# ac voltage measurement using Arduino: ac voltage detector

Ac voltage measurement using Arduino: In this article, we will see how to measure ac voltage using arduino and how to design ac voltage detector circuit using arduino uno r3 and how to design alternating voltage measurement sensor using a very simple technique and at the end, we will see how to write ac voltage / potential measurement code in arduino programming. So it will be a simple arduino based ac voltmeter which can measure 220 volt very easily and without any need of external sensor. I will start writing articles from this week on how to measure ac current , ac power, power factor using Arduino and I have already written a articles on all these topics using pic microcontroller. But on the request of users,I will be also writing these articles using Arduino. Check following articles which are based on pic microcontroller projects So now lets see how to measure ac voltage using Arduino and how to design ac voltage sensor using Arduino and I recommend you to check arduino tutorials and Arduino projects first, if you are a beginner in Arduino programming.

### Components required for ac voltage measurement with Arduino

Followings are the main components required for the design of ac voltage detector with Arduino:

• Arduino Uno R3: It is a main component of this project. It measures analog voltage with the help of built in analog channels and converter the analog measured voltage into digital value and then we convert this measure digital value back into voltage my multiplying it with resolution factor of Arduino ADC.
• 16 x 2 LCD: Liquid crystal display is used to display measured voltage value. If you don’t know how to interface LCD with Arduino, I suggest you check this tutorial on lcd interfacing with Arduino.
• difference amplifier: In this alternating voltage measurement method, difference amplifier is used to step down voltage from 220 volt ac to less than 3.3 volt ac. I will explain it in more detail in next section of this article.

### How to design ac voltage measurement sensor?

To measure ac voltage with the help of Arduino, first of all you need to design alternating current voltage measurement sensor. First example if you want to measure voltage of magnitude 220 volt AC. you need to step down this voltage first. Because Arduino has built in ADC channels and maximum voltage that Arduino analog channel can measure is 5 volt. So we can not measure voltage greater than 5 volt with the help of Arduino directly. you should also know how to measure analog voltage with the help of Arduino or how to use analog channel of Arduino. if you don’t know, check this article on how to measure analog voltage with Arduino.

It will give you an idea on how to use analog channel of Arduino. Because it is a first step towards designing ac voltage sensor with Arduino and ac voltage detector meter with Arduino. As I have explained earlier, in this project I have used difference amplifier to step down voltage from 220 volt AC to less than 3.3 volt AC. Because built in ADC of Arduino can not measure voltage more than 5 volt. So we need to find a way to step down voltage. There are many other methods to step down voltage like potential transformer or step down transformer which is a expensive method for low cost applications. Voltage divider method, it is a least expensive method for this purpose. But it has disadvantage of less voltage range and more power consumption. So we can not use it critical power applications.

So I have come up with another method using operational amplifier. I have use operational amplifier for a step down purpose. Operational amplifier is used a difference amplifier. By adjusting the gain of operational amplifier, we step down the voltage to less than 3.3 volt. I have explained all the theory and working of difference amplifier for to step down ac voltage in separate article on ac voltage measurement using pic microcontroller. I recommend you to check it, if you want to get more understanding about this method.  Circuit diagram of difference amplifier is given below: Input to difference amplifier is 220 volt ac and output of difference amplifier is less than 3.3 volt. I have also added 5 volt dc to ac to convert negative cycle into positive cycle. Because Arduino can not measure negative voltage directly. Again refer to the article on ac voltage measurement using pic microcontroller for more understanding and why I added 5 volt dc level to the circuit. Output of this circuit is fed to analog channel of Arduino which measures this voltage and after performing some calculations displays measured voltage value on LCD.

### Circuit diagram of AC voltage measurement using Arduino

[button-brown url=”http://store.microcontrollerslab.com/product/ac-voltage-measurement-code-simulation-arduino/” target=”_blank” position=”center”]buy code and simulation[/button-brown]

Circuit diagram of ac voltage measurement using Arduino is given below: ### 18 thoughts on “ac voltage measurement using Arduino: ac voltage detector”

1. Is there any disadvantage of such circuit because it is not isolated.

2. can you please send me the code of this ac voltage measurement circuit using arduino. I tried this circuit by in lcd i couldn’t get the voltage as you mentioned in the video. please help me.Giving my email below. Thanks

• let me know the issue you are facing by sharing your code in comments

This is a non-isolated method.
it is better to use an optocoupler or transformer before to opamp to avoid electric shock and ground level difference

• This method just works fine without any issue and I have implemented it many times. you will find this circuit in many modern inverters and power electronics circuits.
Although it is good to have optocoupler and transformer, But it will make system device costly.

4. You are right ????.
The reason behind that not just a 50 RS.
The circuit shown in above figure has better accuracy and precision.
Other circuits use a capacitor to filter ac components which is vulnerable to frequency.
Frequency is very according to load.
Please refer isolated opamps and ac voltage measuring ICs

5. Hello Sir
Yesterday i couldn’t reply you..i will tell what is the problem that i am facing when i am doing the project.. first of all i had referred your previous article ” Ac Voltage measurement using pic microcontroller “. I saw the code that you had given there for the ac voltage measurement using op-amp. i went through that code and i took the idea from there and i put it in my code.
i am using ATmega328P as my MCU for this project. i am not using Arduino for my project because in Arduino also they are using the same controller. But i am using avr studio as my IDE. i will give the code here.. I test this circuit in the proteus simulation. The problem that i am facing is when i run the code it doesn’t show the voltage that i can see in your simulation.i will share the pic also. Kindly check the code and tell me if there is any fault i made.
“””
#include
#include”LCD.h”
#include”DELAY.h”

unsigned int Buff;

volatile float Volt=0;

void main()
{

DDRD=0xff;
PORTD=0x00;

DDRC=0x00;
PORTC=0x00;

LCDInit();
Delay_ms(10);
LCDClear();
Delay_ms(5);
LCDDispStringXY(0,0,”Volt:-“);
Delay_ms(5);

while(1)
{
for(count=0;count<30;count++)
{
Delay_us(30);
}

Volt = Buff;

for(count=1;count<30;count++)
{
if(Volt<Buff[count])
{
Volt = Buff[count];
}
}

Volt *=0.707106781;

LCDDispIntXY(0,7,Volt,6);
Delay_ms(500);
}

}

{
}

{
ch &=0x0f;
} """

• Hi

Unfortunately I do not have tutorial related to atmega,
I will try to write about it in future

6. Hi Dear,
I am looking for a arduino module to check the the availability for Main AC Voltage i.e 220 V 50-60Hz. I have found one module for checking just the availability but i am stuck with the module which can give me the magnitude of the voltage means accurate reading either the voltage is very high or too low.
Regards.
Khurram

7. Hi

What is lowest and maximum range of AC voltage it can measure?

How to connect AC line and neutral here? I think we have to connect line voltage to + terminal side and neutral to – terminal side, is it? Please confirm

Thanks
Manjunath AN

8. Hi

What is lowest and maximum range of AC voltage it can measure?

How to connect AC line and neutral here? I think we have to connect line voltage to + terminal side and neutral to – terminal side, is it? Please confirm

Thanks
Manjunath AN

9. Hi,

1. Can I use LM358 instead of LM258? if Okay, Do I need to change any circuit?
2. Can I supply +5v instead of +12v to OPAMP?
3. What is the minimum and maximum AC voltage range it can measure?
4. How the ac line connection should be? My understanding is line voltage to + terminal neutral should give to – terminal? is it correct?

Thanks
Manju an

10. hi
can i have a code for voltage measurement with Arduino project please …
u can send to me by Email: abuod89@gmail.com
Thanks

11. Hy
Please sir can you help me with the code for automatic transfer switch between solar inverter and grid
I am doing my project base on that and i saw your simulation video but i could’nt find the code
Am using arduino uno
Pls help me with the code