Welcome to Solarduino , A blog about DIY Solar PV and Arduino projects

DIY Bi-directional AC Energy Meter for Solar PV System

Energy Meter is a very useful device that displays important information of electrical parameters. Most Economic Commercial AC Energy Meters are single direction meter which could not record or may be error if the current flow in reverse. They are normally using normal Current Transformer to measure the current value.

Today’s project will be building a Bi-directional AC Energy Meter which could measure electrical parameters such as  RMS Voltage (Vac), RMS Current (Iac), Apparent Power (VA), Real Power (W), Power Factor (pF), Frequency (Hz), Net Energy, Import & Export Energy.

This two directional energy meter is very useful for electric circuit that has Solar On-Grid PV System installed. To cut everything short, we need 2 sensors, the AC voltage sensor and AC Current Sensor.  The Current Sensor we will be using Hall-Effect Current Transformer which can be directly connected to the Arduino Board while AC Voltage Module will be using a standard ZMPT101B voltage module.

Warning ! You may now dealing with high voltage and high power source ! We assumed that you have the basic electrical knowledge and know what you are dealing with. You may need guidance from experienced guys if you are new to electrical work. Safety and Precaution must be always have in mind. We shall not be responsible for anything happening to you.

Peacefair PZEM-021 Energy meter is an compact AC energy meter that measures Voltage, Current, Power and Energy. Peacefair has a lot of model to measure different current requirement from 20A up to 100A. You can get it at our affiliate link here !!!   

Arduino has the ability to measure AC voltage and AC current (via module) by analog input pins. For Arduino UNO, there are 6 analog input pins (A0-A5) where you need separate pin for each measurement. If you stacked up a LCD Display Shield, Analog Pin A0 is automatically occupied by the button function. If you are going a step further by adding Datalogger Shield (but we are not adding the Datalogger Shield due to low memory space), Analog Pin A4 and A5 are also occupied for I2C communication for the Real Time Cloak module in the Datalogger Shield. Technically it left Analog Pin A1 to A3 for AC Current and AC Voltage pin. In this project, I will set A1 to measure AC Voltage and A2 to measure from current module. Do not reverse the voltage polarity which may damage the pins.

Arduino UNO (compatible board)

If you still not yet own an Arduino Micro-controller Board, support us by getting it cheap at our affiliate link here !!!

Measure Voltage using ZMPT101B Voltage Module

This module is equipped with ZMPT101B high-precision voltage transformer and op amp circuit. It can measures AC voltage within 250V. The corresponding output signal can be adjusted using the trimmer potentiometer. It measures the instantaneous voltage value in a waveform of analog values from 0 to 1023. The frequency of the wave is following the Voltage measured. 

Since the amplitude is adjustable, the voltage analog signal need to be calibrated. In order to calibrate, you need another RMS voltmeter for reference. It can be either multimeter or regular voltmeter that can measure AC Voltage (RMS). The maximum voltage that the module can measured (250Vac) is referring to the Root Mean Square (RMS) value. Technically it can measure the waveform up to the peak at 353.55 Vac peak. 

You can calibrate this module in 2 ways: 1) Determine the peak voltage at serial plotter or serial monitor, convert it to RMS value and compare with other RMS voltage reader such as energy meter or multimeter. 2) upload the code to arduino board, adjust the trimpot by comparing the display RMS value in Serial monitor or LCD Display with other RMS voltage reader such as energy meter or multimeter. The second method is faster and preferable.

The AC Voltage Module analog measurement is similar to Current Module. The voltage value will fluctuate up and down within 0 to 5V (0 to 1023 value). When no voltage detected, it will send analog signal at half the supply voltage (example 2.5V) which is about value 512. Different module will have different deviation error. Some might be reading exactly 512 when no measurement voltage detected but some may be slightly more or slightly less than value 512. We have to calibrate the offset value during the first start or during no voltage detected. 

Single Phase AC Voltage Module

This module is equipped with ZMPT101B high-precision voltage transformer and op amp circuit. It can measures AC voltage within 250V. The corresponding output signal can be adjusted using the trimmer potentiometer. You can grab this module at our affiliate link here !!!

UNI-T Multimeter is a good quality with decent price. We have been using UNI-T multimeter for years has not been any issue. We were using UT33C model. It can measure RMS Voltage. You can get yours at our affiliate link here !!!

Calibration for ZMPT101B voltage module

Once the code is uploaded to the Arduino, if you got LCD display shield attached, you will see the current, voltage, active power and apparent power value. Make sure to turn OFF the AC voltage source that you are measuring. Press the SELECT button of the LCD Display Shield and wait for 5 seconds. It should go to 0 volt. Same for the AC current showing 0A

Trimpot Potentiometer AC Voltage Adjustment 

This setting is to adjust the magnitude of AC voltage wave. Unlike AC current, we calculate and get the expected current but for AC voltage, we need a reference voltage for adjustment. You need to calibrate this physically only once and can leave it forever.

Once you have pressed the SELECT button for zero calibration, you should see the value 0 volt when no voltage is detected. Now, turn on the Voltage source and turn on the reference voltage reader (the multimeter or the energy meter). Compare both of the voltage value. Turn the trimmer potentiometer (trimpot) using a small screwdriver to reduce or increase the voltage value detected by the module. You need to turn the trimpot until the voltage shown in the LCD display Shield is the same as the voltage reference value in the volt or energy meter. And Congratulations, it’s Done !!!!

If you really read through the codes, we actually has reduced the potential wave amplitude by half (in formula is times 2). 

RMSVoltageMean = (sqrt(voltageMean))*2;

This is why when monitoring voltage is applied, the value measured is high and you need to reduce it. Full wave amplitude (x 1) get distorted when near to 250V which made us have an idea to reduce the wave by half in physical calibration and then magnify 2 times by calculation to overcome the distortion problem.

16X2 LCD Display Shield can be directly fit on to the top of the Arduino board without the need of extra wiring for the LCD Display. Without the LCD Display, you can only monitor the measured current value on PC via Serial Monitor. You can get the LCD Display board at our affiliate link here !!!. 

Measure Current using Hall Effect Split Core Transformer

In this project, we will be using the Hall Effect Split Core Transformer to measure AC current. It utilizing hall-effect phenomenon which voltage is produced from the movement of current within the region of magnetic field. The voltage produced by hall effect is directly proportional to the applied current making it suitable to estimate the applied current from the voltage sensed.

The sensor can measure current in 2 direction. Reverse current will not damage the sensor but the voltage difference will be in negative. As we know, Arduino analog input only read positive integer values. In order to measure 2 direction, the zero point should be at half the total voltage range (0 to 5V) which is 2.5V. This is true if the supply voltage to the sensor is 5V. 

Hall-Effect Split-Core Sensor HSTS016L module can measure two direction of DC curret ranges from 10A up to 200A (based on the model number). With split core current sensor type, no modification on the existing wiring system required. You can get it via our affiliate link here !!! The output voltage of this sensor is 2.5V +/- 0.625V with decent accuracy. 

Similar to Voltage Sensor, Current Sensor also requires initial offset setting. When no current operate, the sensor might have some deviation value and not exactly at 2.5V which most probably due to sensor or the supply voltage from Arduino Board. Secondly, current sensor is also a sensitive sensor. The output reading of the sensor seems to have electrical noises and its value fluctuates  all the time even when there is no current detected. It is more obvious if the measurement is in a smaller time frame. In order to greatly reduce this phenomenon, multiple samples must be taken for averaging must be done. 

The good news is you can automatically calibrate the offset settings using the LCD Display Shield. Below we have attached the code that utilizes the button function that could automatically calibrate by itself when you pressed the SELECT Button. You may download from the end of this page below.  

Our code is also designed to display a value which is derived from averaging 1000 samples in every second. Each sample is recorded every 1 milli second (0.001 second). The single averaged value is then to be displayed at Serial Monitor and LCD Display. With this, the fluctuation of value is way lesser compare to taking 1 sample reading every second. Make sure the sensor cables are tight because minor movement of wires might affects on the wire terminal connections thus affecting the accuracy reading.

How the signal being processed

Root-Mean Square (RMS) voltage or RMS current value are the square rooted averaged values that is derived from summation of squared of each raw values. In other words, the raw data have to undergo squared, averaged and then being square rooted. The Apparent Power (VA) is the multiplication of RMS voltage and RMS current. 

Instantaneous or Real Power (W) on the other hand is the averaged value derived from summation of instantaneous current times voltage values. Power Factor (pf) is another electrical parameter that indicates the Real Power and Apparent Power ratio. It will be between 0 to 1. The Energy Consumption is the energy being consumed or generate based on Instantaneous or Real Power over an extension or time 

Apparent Power (VA) VS Real Power (W)

Compared to DC electrical characteristic, AC is more complicated as it consists of many terms due to its sinusoidal waveform. Voltage and current value shall be measured in Root Mean Square (RMS) and not in average value or peak value. RMS is derived from square root of the average of squared values while average is derived from average of the half waveform. RMS is a more accurate representing the AC characteristic as it shows the equivalent DC value for the same power. 

Real Power (W) is the actual energy consumption of the electric appliances and it is often confuse with the Apparent Power. Most of the loads consist either resistance or reactance elements. Reactance element such as coil and motor based components will cause the delay flow of current waveform relative to its voltage waveform. Apparent Power (VA) is the power calculation based on no waveform delay between current and voltage (in phase); the delay current waveform will deviate the Real Power from the Apparent Power. Apparent Power is important especially when it comes to sizing a power generator or cable size which assuming loads are operate in full and efficient power.

The delay actually does not have much issue on consumer’s perspective view but it is important for grid operator in power management especially for heavy sectors such as industrial. Grid operator allocate the amount of power capacity (in Apparent Power) based on premise’s request and declaration. However, if the premise are over-request by only using small amount of power, they would be charged a certain amount of penalty every month as the allocate power does not utilized. Grid operator determines the usage quality by Power Factor (pf) which is the ratio between Real Power to Apparent Power or indirectly measures the amount of phase delay. However, it has no penalty for residential sector.

Screw Shield / Expansion Shield

When there are a lot of wiring around especially more than 1 sensor, sharing pins will be difficult as existing pins (ground and 5V) are limited. This shield provides a lot of convenient terminals for each of the input and output pins. The shield can be mounted directly on top of the Arduino Uno board or in between the shields which made it very convenient to use. You can get it at our affiliate link here !!!

Hardware Connection

Once you get your current sensor module, voltage sensor module and Arduino Board ready, you may start to do hardware wiring. Below is the schematic of the whole wiring. You may also need some tools and accessories. Be sure your connection cable is tight and module shall be installed in such a way no movement at all. 

You can stack up screw shield, and LCD Display Shield on top of Arduino UNO. Not recommend to add Datalogger Shield as the measurement values might not be accurate due to low memory. No additional wiring is required as the shields are meant for adding function without need of extra wiring. Do not use 5V power supply to operate Arduino Board as there are more modules and under power supply may cause the measurements are not being accurate. Use the 12V power supply instead.

Wiring using HSTS016L Split-Core Sensor module

Dupont Line Wires

You may need Dupont Line Wires to connect Arduino board and Sensor Module. It is available at our affiliate link here !!! 

Software Codes

The final step would be adding source code onto Arduino board. I assume you have installed the Arduino Software. If you still have not installed the software, the link here can bring you to the official download site. Once you have downloaded the software, you may download the code file (.ino) for this application below (right click save link). Once the code has been uploaded to the arduino board, the output can be shown in LCD Display. I will not display the code here because it is long. You can download the .ino file to see for your own. Almost all code lines are with explanation. 

Coding Concept and Calculation

For Voltage and Current measurement, each data will be collected every 1 millisecond. In other meaning, one complete cycle waveform will consists of 16 to 20 data. Power, energy and power factor values will be calculated based on the voltage and current data. As for frequency, it is a bit complicated as the measurement timing may not compatible with other values. Thus here we reduced the waveform cycle number to about 46 or 47 in order to match with timing of other values so that they can display the same time on the LCD Display Screen.

Ferrule Lugs and Crimper Set

Ferrule lugs are used at terminals for tight and secure connection. Besides, it also prevent stranded cables accidentally touching adjacent power line that may cause short circuit. Grab 1 at our affiliate link here !!!

Terminals Crimping Plier Set

This is a crimping tool with interchangeable jaw for crimping many types of terminals. It is a must have for DIY electronic and electrical for professional installation work. You may choose at out affiliate link here !!!

Before we end, we would like to give gratitude to you for taking the time to read the post. We would need readers like you to support us in order to keep growing. You can support us in the following ways :

Donate & Fund Raising

If you like my work, please send me a donation to encourage me to do more. Thanks


Aliexpress Affiliate

We are the member of Aliexpress affiliate marketing. Do support us by clicking the affiliate product links if you do wish to purchase them.

Like and Share

If you like our post, we need your support to like and share our posts or videos so that it can reach more and more people like you !!

Bi-directional AC Energy Meter.ino