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

How to Measure AC Voltage with Arduino ?

Arduino has the ability to measure voltage using analog input pin. For Arduino UNO, there are 6 analog input pins (A0-A5) where you can use one of the pins to measure AC voltage. Arduino NANO has 8 pins while Arduino MEGA has 16 input pins. The analog input pins will map input voltages between 0 and 5V into integer values between 0 and 1023 with resolution of 4.9mV per unit (5.00V / 1023 units). 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 !!!

Warning ! You are now dealing with 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.

You can measure AC Voltage such as 110Vac, 220Vac and 240Vac by using the market-available Single Phase AC Voltage module. It can detect the instantaneous waveform of the voltage. The signal can be used with AC current sensor to determine further useful information such as power factor,  direction of current flow, real power and apparent power. 

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

Simple Waveform

If you wondered how the analog signal of Arduino detects the voltage, this is the basic output of the module in analog value. You can copy the below code to try your own. You can see the waveform in Serial Plotter. This unprocessed value and waveform can be further processed into other usable information especially when compared to AC waveform. 

</p><p>void setup() {<br />Serial.begin(9600);<br />}</p><p>void loop() {<br />Serial.println(analogRead(A2));<br />delay(300);</p><p>}</p><p>

The output signal of the Single Phase AC Voltage Module is 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. 

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. The AC Voltage Module requires at least 5V power supply and the signal output voltage is within 5V thus if you have a Arduino Nano or NodeMCU that have 3.3V analog pins, you need to add a voltage divider resistors in between to reduce or step down the output analog values.

 

The sensor module is a sensitive sensor. The output reading of the sensor might produce electrical noises or fake values even when there is no voltage detected. In order to greatly reduce this phenomenon, multiple samples must be taken for averaging and initial offset must be done. Our code is designed to display a value which is derived from averaging 1000 samples in a second. Each sample is recorded every 1 milli seconds (0.001 second). Each single sample value is being squared initially and once the 1000 sample values are accumulated, the average value from the 1000 samples is then being square-rooted in order to come out the Root Mean Square (RMS) voltage value which is to be displayed at Serial Monitor and LCD Display. With this averaging, the fluctuation of value is way lesser.

The second problem could be the false signal and accuracy problem. Each sensor has its own deviation error. When there is no voltage sensed, the sensor might not be 100% at middle point of voltage value. Some might be remaining at few milli voltages above / below the middle point even though after averaging. This might be due to voltage supplied not in exact 5V or due to the sensor itself. Thus 12V power adapter to power the Arduino UNO is highly recommended.

Besides, the sensor requires initial offset setting. You may need to manually offset the value by checking the false value when no voltage measurement during Arduino startup and then key in offset value in the code file. Secondly, make sure the sensor cables are tight because minor movement of wires might affects on the wire terminal connections thus affecting the accuracy reading.

Once the wave swing is calibrated to oscillate at exact middle point, after the calculation of squared, averaging and square root, there is still some minor false value existed even no voltage measurement. So our code included the second offset setting to eliminate this noise value. 

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 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. After calibration, AC values lesser than 1% of the voltage rated (250Vac) which is 2.5Vac will be automatically turn to 0V to eliminate ghost values. 

Now, the first thing need to do is get a reference voltage reader such as a Multimeter or an Energy / Volt Meter. Make sure the reference voltage reader is showing (RMS) Root Mean Square Voltage value. The accuracy of the module is subject to the reference meter based on your physical calibration. Once everything ready, you may wire up all the hardware together.

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

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

Hardware Connection – Single Phase AC Voltage 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 !!

Software Codes

The next 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 are 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. 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 in Serial Monitor using Arduino Software and on the same time 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 after about 5 seconds later. If first press is not satisfied, you may repeat by pressing it again. During calibration, make sure the measurement circuit is turned OFF (no voltage value sensed).

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

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.

Calibration Process

Once the code is uploaded to the Arduino, if you got LCD display shield attached, you will see the voltage 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. 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.

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 Arduino. You need to turn the trimpot until the voltage shown in the LCD display Shield same as the voltage reference value. And Congratulations, it’s Done !!!!

If you really read through the codes, we actually has reduced the potential wave amplitude by a factor of 0.66. 

RMSVoltageMean = (sqrt(voltageMean))*1.5;

What I realized is that by default, the waveform will start to distort before reaching 250Vac. It will affect the accuracy of other values if we calibrate based on distorted wave. So to solve this issue, I have reduced the amplitude by a factor of 0.66 in the coding, so that the waveform will not stretched till the maximum extend. You will realize when monitoring voltage is switched on, the voltage value is high and you need to reduce it. 

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 Voltage Module.ino
AC Voltage Module with LCD Display.ino