I live in Greece where 220Volts/50 Hz is in every house's socket.
I need to measure the Watts being consumed by a device (a single lamp), which I hook up in the socket.
The problem is that I can only measure the instantaneous current i(t). I don't know the resistance of the lamp neither the instantaneous voltage. The current is being measured from an arduino, using ACS712-5A, which makes my first question :
Is this safe, for me, my arduino and all my peripherals to measure the curent with ACS712-5A ?
Secondly, this is the "analysis", I did to determine a way to measure the Power. I need you to tell me, if it's valid ?
$$ P_R(t) = V(t)i(t)\\ => P_R(t) = \sqrt(2)V_{rms}cos(ωt)*\sqrt(2)I_{rms}cos(ωt+φ) $$ ,but φ=0 since I just have a lamp (an ohmic load). So, $$ P_R(t) = 2V_{rms}I_{rms}cos^2(ωt)\\ => P_R(t) = V_{rms}I_{rms}(1 + cos(2ωt))\\ $$ but instantaneous power is not so usefull, so I go for the average power : $$ P_M = \int_0^T V_{rms}I_{rms}(1 + cos(2ωt))dt\\ => P_M = V_{rms}I_{rms} (t\Big|_0^T + \frac{sin(2ωt)}{2}\Big|_0^T)dt\\ $$ the second term is 0, so $$ P_M = V_{rms}I_{rms}T \\ => P_M = \frac{V_{rms}I_{rms}}{f} \\ => P_M = \frac{220I_{rms}}{50} $$
So, all I need is calculate $$I_{rms} : I_{rms} = \frac{I_{max}}{\sqrt2}$$ which means that I must determine the maximum current. In order to do this, I need to have a sample rate faster than 50Ηz (ideally faster than 2*50Hz based on Nyquist theorem). On this question : https://arduino.stackexchange.com/questions/699/how-do-i-know-the-sampling-frequency is being said that :
For a 16 MHz Arduino the ADC clock is set to 16 MHz/128 = 125 KHz. Each conversion in AVR takes 13 ADC clocks so 125 KHz /13 = 9615 Hz.
So, I guess my arduino is capable of that measure. The pseudocode I guess will be something like this :
max = 0;
t = millis();
while (1)
{
instantCurrent = readAnalog();
if (instantCurrent > max)
max = instantCurrent;
if (millis() - t > 1/50) //period is over.
{ // prepare for the next maximum in the next period
Irms = max/sqrt(2);
AveragePower = 220 * Irms/50; // --> THAT'S WHAT I WANT
t = millis();
max = 0;
}
}
So, what's your opinion ?
Edit : Missed, the division by T in calculating the average power : $$ P_M = \frac{1}{T}\int_0^T V_{rms}I_{rms}(1 + cos(2ωt))dt\\ $$ which makes a more reasonable result, independent of frequency, as Anderson mentions : $$ P_M = V_{rms}I_{rms} $$ The general problems thought, remains the same :)