I have been trying to construct a smart energy meter that can observe readings of 220v household. For now i am working on voltmeter. I have been following the circuit I attached. Transformer step down 220V to 6V. Zener diode is of 5V.
The output from the circuit( 5v max) is fed to arduino Mega 2560 A0 pin.
* I am powering arduino using a USB cable *
Arduino takes this voltage as input from pin A0 in form of analog values between 0 to 1023. 0 being 0 volt and 1023 being 5v.So any random analog value corresponds to X=(5/1023)*Y where Y is obtained analog value. X is then multiplied by a value obtained by hit and try method (165 in my case) to reach the exact reading of voltage in line observed via multimeter.
Now the problem is that, everything works fine when i calibrate it, but after some time when i switch circuit on the value is inaccurate by margin, and i have to calibrate it again and again every time I turn circuit on after some time.If i switch circuit on soon after switching it off, it gives almost accurate value. I guess this issue is due to the capacitor, but i don't know anything about it or how to solve it I have constructed the same circuit more than 5 times, soldering it 3 times and 2 times on bread board and i am sure there is no problem with my implementation, verified it many times.
this is my code:
float V; // Voltage samples
float V0;
void setup() {
Serial.begin(9600);
}
void loop() {
for(int i=0; i<=20000; i++){
V = V + analogRead(A0);
}
V = V / 20000;
V = round(V);
float V0 = V * (5.0 / 1023.0);
I0 = I0 * 165; // has to be callibrated again and again each time circuit is switched on after a while
Serial.print("Voltage = ");
Serial.print(V0);
Serial.println(" -------------- ");
delay(1500);
}
this is the link i am following http://engineerexperiences.com/3-phase-smart-energy-meter-using-arduino.html
Any help would be appreciated, Thanks!