Code: [ Ссылка ]
Working Principal:
Need of voltage divider circuit?
As we are using 220/12 v transformer, we get 12 v on l.v side. Since this voltage is not suitable as input for Arduino we need a voltage divider circuit which can give suitable voltage value as input to Arduino that is 5v.
Purpose of zener diode?
Arduino can get damage if voltage greater than 5v is fed to it. Hence a 5v zener diode is connected to ensure safety of Arduino which breakdowns in case this voltage exceeded 5v.
To assign variable n to this formula n=(m*.304177), first some sort of calculations is performed by using the data obtained in simulation section:
As seen in simulation photograph, 5v or 1023 analog value is obtained at pin A0 when input a.c voltage is 311volts. Hence:
1023 analog value corresponds to 311 volt mains supply
So any random analog value corresponds to (311/1023)*m where m is obtained analog value.
Hence we arrive at this formula:
n=(311/1023)*m volts or n=(m*.304177)
Now this voltage value is printed on the serial monitor by using serial commands.
![](https://s2.save4k.ru/pic/zGSjCr5j1us/maxresdefault.jpg)