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 :)

  • \$\begingroup\$ For a sinusoid into a resistive load the average power is not a function of the frequency. Something went wrong with your math. Also, we need to see the schematic and physical layout of the current sensor and arduino. \$\endgroup\$ Jun 25, 2018 at 17:58
  • \$\begingroup\$ Calculating the RMS current from the I<sub>max</sub> current will work for an incandescent lamp on full-wave, un-dimmed, AC supply. Add in a dimmer or a non-resistive lamp such as a compact flourescent or an LED bulb and this won't work. The current waveforms of both of those are non-sinusoidal. \$\endgroup\$
    – Transistor
    Jun 25, 2018 at 20:46

2 Answers 2


From the datasheet you can see that there is sufficient isolation to support your needs.

However, whether it's safe for your depends on either the implementation of the board your bought, or the PCB you laid out. When including mains voltages and MCU/logic level circuitry on the same PCB you have to be very careful to ensure you have the correct spacing of tracks.

I consider PCBs such as these (Ebay specials) to be quite dangerous as they have no solid mounting points or have very small safety spacing on tracks so are difficult and potentially dangerous to use.

enter image description here

A much safer sensor interface is to use a current transformer, again readily available and easy to connect to an Arduino A/D.

enter image description here

Here the mains is kept in it's rated cable and well isolate from your MCU/logic levels.

Since you are measuring a resistive load all you need to do is find the peak current flowing. From this you can find the RMS current and even assuming the mains voltage you'll get reasonably accurate results. For an Arduino based solution sensing only the current flow I'd suggest you find the zeros crossings (of the current waveform) and simply calculate the top of the sine wave current flow and trigger the A/D. Or you could take say 1kHz readings, and search for the highest current reading.

Remember that if your load is reactive in any way you need to measure voltage/phase/current together to get accurate power readings. You could then follow the bouncing ball at OpenEnergyMonitor.


My mini design review:

The chip you have selected is not recommended for new design and is replaced with an improved version. https://www.allegromicro.com/en/Products/Current-Sensor-ICs/Zero-To-Fifty-Amp-Integrated-Conductor-Sensor-ICs/ACS723.aspx

The degree of safety using this chip depends on proper PCB design which you may follow from their demonstration board. The improvement in this chip reduces the effective series resistance (ESR) which below 1 mOhm of the previous IC. While the insulation level comes with 2.4kV std and improved option at 4.2kV for lightning isolation. Your power meter has a lightning arc shunt voltage that will breakdown at 6kV.

You may occasionally get spontaneous bad readings during load switching of motors which you can toss or average in software or hardware. The preferred way for hardware averaging is to use an Op Amp(OA) precision {half or full} wave rectifier on AC output. The output is DC biased at Vcc/2 to be your reference for the OA. While peak is $$V_{RMS}=V_p/\sqrt 2 $$ $$V_{RMS}=V_{AVG}\dfrac{\pi}{2\sqrt 2}~=V_{AVG}*1.11$$

enter image description here The beauty of this, is you can use a Dual OpAmp to make a full wave Recifier then choose gain to include AVG to RMS with an average weight time filter for many seconds to save on CPU data processing.

Choose your accuracy 1st then then design 2nd e.g. parts e.g. 0.1% or 0.5% for R values that affect gain and offset.. Remember low input signals will have greater % error.

Of course if you don’t measure V(t)*I(t)=P(t) between samples , you lose accuracy due to often specified 10% tolerance for residential voltage.

Conversion of this product would be done in firmware using the same Average precision rectified an low pass filtered method for each.

But it all depends on your specs for resolution , accuracy and range for energy consumption specs.

BTW, What are yours?

  • \$\begingroup\$ Shouldn't \$V_p\$ be somewhere in the equation that starts \$V_{RMS}=\$ ? \$\endgroup\$ Jun 25, 2018 at 20:46
  • \$\begingroup\$ oops no that was supposed to say Vavg \$\endgroup\$ Jun 25, 2018 at 20:49
  • \$\begingroup\$ No, I mean your formula that starts \$V_{RMS}=\$ just yields a constant value. There's something missing from that formula. \$\endgroup\$ Jun 25, 2018 at 20:53
  • \$\begingroup\$ Yes I understood before \$\endgroup\$ Jun 25, 2018 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.