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

DIY AC Energy Meter with Arduino

Energy Meter is a very useful device that displays important electrical parameters. There are 6 important electrical parameters in a Alternating Current (AC) Energy Meter, which are AC RMS Voltage, AC RMS Current, RMS Power, Instantaneous Power, Power Factor and accumulate Energy consumption. This device is used in all household loads measurement or AC energy generation. It also can be used in AC Side of Solar PV System. To cut everything short, in order to obtain all the 6 parameters above, we need 2 sensors, the AC voltage sensor and AC Current Sensor.  

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, 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, you can get 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 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 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. You will have to manually key in 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. For people out there that do not have the LCD Display Shield, you can manually offset by entering the offset value in the code and re-upload again. There are 2 offset values (voltageOffset1 & voltageOffset2) need to calibrate. Do the same for AC current module for 2 offset values (currentOffset1 & currentOffset2) and finally is the powerOffset.

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.

Once calibration done, 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 or Serial Monitor 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 having this choice to overcome the distortion problem.

Measure Current using ACS712 or Split Core Module 

The current sensor that is widely used for Arduino is the ACS712 Current Sensor Module. 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 produced will be in reduced. 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. 

The standard ACS712 Current Sensor Module rated at 5A, 20A and 30A which are suitable to most applications. You may get them by our affiliate link here !!! The 5A module has the resolution of 185mV/ampere, 20A module has 100mV/ampere while 30A module has the resolution of 66mV/ampere.

Assume using 5V supply as standard (which we do not recommend using 3.3V supply), the 5A module will provide voltage at 2.5V +/- 0.925V, 20A module will provide voltage at 2.5V +/- 2.0V while 30A module will provide voltage at 2.5V +/- 2.0V. These modules require direct contact which I think is a major drawback. It has to be connected in series to the measured value. The wiring of the existing system need to be altered in order to fit the module into the existing system. I highly recommend you to use the following option due to safety issue.

Fortunately, there is also a hall-effect sensor type with split core transformer type (as picture on left). It is the Hall-Effect Split-Core Sensor HSTS016L module. The model ranges from 10A up to 200A. With split core current sensor type, not alteration on the existing 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.

How the signal being processed

Root-Mean Square (RMS) voltage or RMS current value is the square rooted averaged value that is derived from summation of squared of each raw values. while RMS power is the multiplication of RMS voltage and RMS current. 

Instantaneous power is the averaged value derived from summation of instantaneous current times voltage values. 

Power factor is the division of instantaneous Power over RMS power value. It will be between 0 to 1. The energy consumption is referring to instantaneous Power over an extension of time.

Both sensors are quite sensitive. We need 2-time calibration for each module sensorBoth calibration need to be done during no current & voltage measured. The first calibration is making sure when no voltage or current measured, it shows exactly at 0 point. It is an analog value calibration. Some modules might not showing exactly at analog value 512 (I have shifted it to 0 point using Arduino code for easy understanding) when no value is detected. We need to add an offset value for this to adjust it back to origin when no value detected.

The second calibration is to further eliminate false signal value during RMS calculation. Even after the first calibration is made, there are still some minor ghost or electrical noise even when no voltage and current are measured. We have to add another offset to make it to zero value at the final stage for display. This second calibration must be done only after the first calibration take into effect. Both calibrations can be done manually (the harder way) or automatically by pressing the SELECT Button in the LCD Display Shield and wait for about 5 seconds. Of cause you need to have the shield in order to work. You may purchase at our affiliate link here !!!

I recommend you to add a 16X2 LCD Display Shield which 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 !!!. 

The good news is you do not need to manually calibrate the offset settings if you got the LCD Display Shield with you. 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.  

Datalogger Shield

If you plan to record the data in a proper way, you may consider this Datalogger Shield. It allows your arduino to record your data in SD Card. Datalogger shield is often installed together with LCD Display shield. Please find it at our affiliate link here !!! For more about this Datalogger Shield, kindly visit our post 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. If more modules or shields are stacked, if voltage dropped is obvious, you may consider using independent 5V power supply and not from the arduino board.

Wiring using HSTS016L Split-Core Sensor module


In order to connect wiring between Arduino board and module, you need the dupont line cables male to female. You can get it at our affiliate link here !!!

You need the connector that can secure cables and isolate from accidental touch. Get the fast connector at our affiliate link here !!!

You need a fuse to protect your safety and cables!! You can get it here !!

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 !!!

Software Codes

The final step would be adding source code onto Arduino board. I assume you have installed the Arduino Software. If you 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). 

There is 2 source codes file attached which are source code with and without LCD display shield function. If you don’t have LCD Display shield with you, kindly choose the code that is without LCD Display Shield but you have to manually calibrate and key in the 2 offset values for both sensors. However, I still highly recommend that you get a LCD Display Shield.

With LCD Display Shield, once the code is uploaded to the Arduino board, the current value will be shown on the LCD Display. We have added the auto calibrate function, once the SELECT button is pressed, the value returns to exact zero point. You may have to wait about 5 to 8 seconds long until all values are re-calibrated. If first press is not satisfied, you may repeat by pressing it again.

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. 

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 !!

Result – In Serial Monitor

Result – In LCD Display

For Arduino Code Files, Remember to Right Click > Save Link As … You may alter the internal code as you wish. Happy coding !! 

AC Energy Meter.ino
AC Energy Meter with LCD Display.ino