# measuring Vrms/AC Voltage using arduino ATmega 328

I need to measure Vrms using arduino so I can display it on a LCD for my project. I’m not much familiar with arduino yet. Here I have the code for reading AC voltage.

``````#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int in0=0;
int in1=1;
int in2=2;
int out=(12, 11, 5, 4, 3, 2);
void setup() {

lcd.begin(16, 2);

lcd.print("output");
}

void loop() {

float input1=getvoltage(in2);
float output=getvoltage(out);
float out= input1;
lcd.setCursor(0, 1);

lcd.print(out);
delay(1000);
}
float getvoltage(int pin)
{
}
``````

Im planning to insert the equation Vrms = 0.707 *(Vpp/2) to display the Vrms… Am I on the right track?

Am I on the right track?

Actualy no. It's pretty difficult to do what you are trying to do because a single analogRead() command takes just a single 'snap shot' of the value of a AC voltage where as you need to perform a lot of consecutive analogRead() statements to try and identify the highest positive peak and lowest negative peak before your formula can be applied. Also the analogRead command can only read DC voltages in the range of 0 to +5vdc where as a true AC voltage has a negative voltage for half its cycle which can damage a analog input pin.

So you need external hardware circuitry to shift the representative AC voltage such that it's most positive and negative peaks fit within a 0-5dc range and a reading of +2.5 would represent the AC zero crossing value. Then you have to read enough points over a 16.666 milliseconds timeframe (one complete AC cycle at 60Hz) to be sure that you can identify the absolute peak values.

This is not something the AVR chip is good at doing.

Lefty

This is a nice introduction, http://openenergymonitor.org/emon/buildingblocks/ac-power-arduino-maths