Arduino AC measurements

Sometimes there is need to measure power going to different devices. Measuring DC power consumption is pretty easy, but when you try to do the same for AC circuit, things start to become complicated. How to Measure Electrical Power article will discuss best practices for making electrical power measurements, starting with power measurement basics and proceeding to the types of instruments and associated components typically used to make measurements. DC power measurement is relatively simple as the equation is simply watts = volts x amps. For AC power measurement, the power factor (PF) introduces complexity as watts = volts x amps x PF. This measurement of AC power is referred to as active power, true power or real power. Power is typically measured with a digital power analyzer or a DSO (digital storage oscilloscope) with power-analysis firmware.

What if you want to implement power mesurement yourself? Power consumption in AC circuit is correctly measured by calculating volts x amps = volt-amps (apparent power) over time, using at least one complete cycle. Using digitizing techniques, the instantaneous voltage is multiplied by the instantaneous current then accumulated and integrated over a specific time period to provide a measurement. This method provides a true power measurement and true RMS measurements for any waveform up to the bandwidth of the instrument.

In addition to math, you will need to provide some sensors to measure current and voltage. For AC current measurements potential sensor types are shunt resistor, current transformer, hall current sensor and rogowski coil. Usually current transformer and hall current sensor are the most suitable types to use with Arduino (they both provide isolation from measurent circuit). For AC voltage measurements the most suitable sensor types are voltage transformercapacitive voltage divider and resistive voltage divider. From those alternatives only voltage transformer can provide galvanic isolation from circit being measured.

Can this measurement of AC power made using Arduino? The answer is yes, ans there are several ways it can be done. AC Power Theory – Arduino maths web page provides inntroduction how this can be implemented with Arduino (check also Advanced maths). There is EmonLib library that provides you a set of ready made AC measurement calculation routines that you can use easily.

Arduino sketch – voltage and current from OpenEnergyMonitor project shows how you can do the AC power measurements with Arduino.

#include "EmonLib.h"              // Include Emon Library
EnergyMonitor emon1;              // Create an instance

void setup()
  emon1.voltage(2, 234.26, 1.7);  // Voltage: input pin, calibration, phase_shift
  emon1.current(1, 111.1);        // Current: input pin, calibration.

void loop()
  emon1.calcVI(20,2000);          // Calculate all. No.of crossings, time-out
  emon1.serialprint();            // Print out all variables

To us this simple looking source code, you need to have EmonLib installed (it does all the complex calculations so you don’t need to worry about them). The simplest way is to download EmonLib zip packet and extract it to arduino libraries folder. It will give the needed library and project examples.

Here is example code I used “voltage_and_current” (my modified version):

// EmonLibrary examples, Licence GNU GPL V3

#include “EmonLib.h” // Include Emon Library
EnergyMonitor emon1; // Create an instance

void setup()

emon1.voltage(2, 11.7 /* 234.26 */, 1 /* 1.7 */); // Voltage: input pin, calibration, phase_shift
emon1.current(1, 5.5 /* 111.1 */); // Current: input pin, calibration.

void loop()
emon1.calcVI(20,2000); // Calculate all. No.of half wavelengths (crossings), time-out
emon1.serialprint(); // Print out all variables (realpower, apparent power, Vrms, Irms, power factor)

float realPower = emon1.realPower; //extract Real Power into variable
float apparentPower = emon1.apparentPower; //extract Apparent Power into variable
float powerFActor = emon1.powerFactor; //extract Power Factor into Variable
float supplyVoltage = emon1.Vrms; //extract Vrms into Variable
float Irms = emon1.Irms; //extract Irms into Variable

I got the following output when I measured 20W halogen lamp system:



Here is picture of the Arduino Nano + Nano Sensor Shield based test circuit I used:


In this test circuit I measured 12V halogen lamp system current and voltage. For current mesurement I used ACS712 sensor based current measurement sensor module with +-5A current measurement range. For voltage measurement I used a simple voltage divider module (22k ohm from input pin to +5V, 22 kohms from input pin to ground, 120 kohms from AC voltage source to input pin).

One note in plannng to use this power measurements: If you plan to measure mains power, you need to understand all the safety details related to mains power. When testing the circuit, I highly recommend that you have a low voltage test system that you can sefely test and debug your designs (hardware and software). I have used 12V halogen lamp system for this: a traditional 12V transformer gives out safe 12V AC output usually at several amperes, you can control the load easily by turning 12V lamps on/off as needed. When you have debugged your design at safe voltages, you can start thinking of working with higher dangerlous voltages!


Related project pages:

OpenEnergyMonitor building blocks


Home Energy Monitoring System

Watt Meter build walks you through Power Measurement basics

DIY Digital AC Watt Meter

Digital Data from a Cheap Power Meter



  1. Tomi Engdahl says:

    Self Built Power Meter Uses Dual Sense Transformers

    [Renaud] built a AC power meter from scratch. While commercial power meters like the Kill A Watt are available [Renaud’s] build gives an interesting insight into the methods used.

    currentAt the heart of [Renaud’s] design lie two sense transformers. The first is a typical voltage stepdown transformer. This brings the AC line voltage down to +/- 10V, which is more amenable to digital sampling. The second is a current sense transformer

  2. Tomi Engdahl says:

    Another mains power meter project:

    WiFi Power Monitor

    Building your own hardware to measure AC power isn’t a simple task. There’s a number of things to measure, including voltage, current, power, and power factor. The Atmel 90E24 is a single chip solution designed for this exact purpose. Connect a few components, and all the power data is available to a microcontroller over SPI.

    Aside from the Atmel 90E24 device, a high power and low resistance resistor is needed for shunt sense current measurement.

    [hwstar] built a custom power monitoring board based on this IC. His AC-Emeter will give you all the measurements you’d want, and includes an ESP12 module for data collection and WiFi connectivity.

    Hardware for an ESP8266 or Arduino based AC power meter using the Atmel 90E24 energy management chip

  3. Tomi Engdahl says:

    Energy monitor with Arduino
    Measure energy consumption with Arduino

    Recently I discovered
    It has all necessary information for building home energy monitor – software and hardware.
    I have a few ideas for improvement.

  4. Tomi Engdahl says:

    Using low cost appliance energy meter for AC power measurements:

    Energy Meter Hacking – Reading EOUT Pulses

  5. Tomi Engdahl says:

    Finally, a Power Meter Without Nixies

    First steps lead me to OpenEnergyMonitor. I looked into

    and found that is not something that I’m looking for.

    it’s one phase only (3 phase = 3 Arduinos ~ still cheap for AVR based one but not so cheap for 12-bit resolution ARM based one )
    Arduino’s way of using ADC’s is very slow – only about 50 I,V samples per mains cycle. They do some “weird” filtering to deal with that.

    I wanted:

    to collect all 3 phases currents and voltages simultaneously
    to make AC waveform graphs
    12-bit resolution
    accuracy…as I plan to use only one device on whole home and like to see 1W difference on meter capable measuring some kWatts
    reactive power with sign (indication of capacitive or inductive load)
    to have frequency measurement like on – read the story behind that
    to have whole system in my home network – without need of internet connection and cloud storage
    I love everything open and I wanted this project to be replicable, customizable and very simple

    After some research starting at AC power I’ve found excellent application note: Texas Instruments SLAA577G – Implementation of a Three-Phase Electronic Watt-Hour Meter

  6. Syed says:

    how you get this calibration??

    emon1.voltage(2, 234.26, 1.7); // Voltage: input pin, calibration, phase_shift
    emon1.current(1, 111.1); // Current: input pin, calibration.

  7. Syed says:

    i am confused about calibrating voltage and current sensor??? i want to make pf meter to measure pf of loads such as bulb.

    Kindly help

    • Tomi Engdahl says:

      I did the calibration on one of my protoype using the following method:

      I had 12V halogen 20W lamp that used traditional transformer (gave out 50 Hz AC).
      I connected the Arduino board plus to multimeters (one for current and other for voltage).
      Then I looked at what the Arduino showed and what the multimeter showed. For example if the voltage Arduino showed was for example around twice what it should be, I adjusted the cablibration values according to the difference (in this case multiplier should be either twice or half of the original value depending how it is used, I don’t remember, but easy to test which is right direction).. Do the same for current.
      For phase shift, use the data from the current transformer data sheet.

    • suleman says:

      Are u done it???

  8. Talha says:

    What it is for? why 20 and 2000

    • Tomi Engdahl says:

      The first parameter (20) defines over how long time period the calculation is performed. Here the value 20 means over 20 zere crossings (=10 AC cycles).

      The second parameter (2000) is some kind of timeout to stop analyzing if it takes more than reasonable amount of time.

    • Thien says:

      20 means sample. My code on 1 second: emon1.calcVI(2000,1000); // Calculate all. No.of half wavelengths (crossings), time-out

  9. Akpellas says:

    First of all, I’m not an energy expert, but I would like to explain two concepts that I think are misunderstood.
    The EmonLib library is designed to measure 3-phase electric power , so uses the factor (sqrt root) 3 = 1.732050 (380V), but when you want to measure 1-phase electric power, the factor is (sqrt root) 2 = 1.414213 (230V), in this case must be replace value 1.7 –> 1.41 in the formula
    emon1.voltage (2, 234.26, 1.41); // Voltage: input pin, calibration, phase_shift.
    About Power factor,this value is provided by the company that builds motors, which writes on specifications plate, and shows how many energy transforms in job, always this value is between 0.80 to 0.85, never will be over 1. In 1-phase electric power isn’t need power factor, due Electrical appliances consume low energy.

    • Thien says:

      Thank’s about your comments!
      emon1.voltage(0, 240.074, PhaseV); // Voltage: input pin, calibration, phase_shift
      Where: PhaseV = 1.41; adaptor Power 220/9 therefore calibration = 240.074

  10. nabin bera says:

    I’m using 230/2 volt PT and 5/1 amp 15 VA CT to step down voltage and current respectively.and using two 8.2 ohms 2watt resistor in series across CT to get voltage drop corresponding current.this two parameters are fed to arduino analog pin A0 and A1 .so what will be the calibration values and phase sift emonlb.h related program.

    Here is the program
    #include “EmonLib.h” // Include Emon Library
    EnergyMonitor emon1; // Create an instance

    void setup()

    emon1.voltage(2, 234.26, 1.7); // Voltage: input pin, calibration, phase_shift
    emon1.current(1, 111.1); // Current: input pin, calibration.

    void loop()
    emon1.calcVI(20,2000); // Calculate all. No.of crossings, time-out
    emon1.serialprint(); // Print out all variables

  11. Tomi Engdahl says:

    Put a Reverse Engineered Power Meter in Your Toolkit

    It seems that one can buy cheap power meters online and, well, that’s it. They work just fine, but to use them for anything else (like datalogging or control or…) they need a bit more work. The good news is that [Thomas Scherrer], alias [OZ2CPU], just did that reverse engineering work for us.

    Inside these budget power meters, you’ll find an LCD driver, a power-monitoring chip, and an STM32F030, which is a low-cost ARM Cortex M0 chip that’s fun to play with on its own. [Thomas] traced out the SPI lines that the power-monitoring chip uses to talk to the microcontroller and broke in to snoop on the signals. Once he got an understanding of all the data, tossing an ATmega88 chip on the SPI line lets him exfiltrate it over a convenient asynchronous serial interface.

    Peacefair pzem-021 energy meter hacked SPI to SERIAL out AVR mega 88

    The Peacefair PZEM-021 energy meter is very popular and super cheap at ebay
    the unit is very good and usefull for all sorts of projects and to be used when working with mains powered electronics.

  12. Tomi Engdahl says:

    Root Mean Square


    You can compute RMS voltage using an oscilloscope. However, with a meter, it can be tricky depending on what the meter measures. Most meters that don’t claim to measure RMS, read the average value of the voltage. Some meters measure RMS but only for a sine wave. Older true-RMS meters used thermal or electrodynamic methods to measure the RMS value. However, modern meters are usually adept at measuring RMS, at least for pure AC signals. A very few meters will have an option to measure RMS voltage for signals with a DC component, like an offset.

    According to Fluke, an average-reading meter will read 10% high on a square wave, 40% low on the output of a single-phase diode rectifier, and anywhere from 5% to 30% low on the output of a three-phase diode rectifier. Big difference.

  13. Mohit yadav says:

    How can measure ac power for variable load.
    Suppose 2 load is on for “t” sec then, 1 load aaded or removed form it how can we measure power now.
    Which type of sensors we should use. To measure current and voltage.

  14. Tomi Engdahl says:

    Decabit: Or The Conspiracy Theory That Wasn’t

    [LDX] first noticed the odd sounds coming out of his ceiling fan, regularly, on the hour and half-hour. Then he noticed that the lights were flickering as well. Figuring something was up, he built a logging power-line monitor to see if he could decode the shadowy signals and figure out what cryptic messages were being transmitted over the power lines. Naturally, he suspected the Illuminati were behind it.

    Even if you’re not prone to flights of fancy, you might want to keep track of your power line because it can serve as an accurate long-run timebase for projects, or because it can tell you something about the overall health of the grid.

    Investigating AC
    Get your tinfoil hat ready!

    I used a Teensy 3.1 running at 96MHz connected to a voltage divider circuit from a 10v AC adapter, the waveform is shifted up above 0v to capture the full wave.

    The code averages 2 readings before pushing to serial port, use the ‘Serial Plotter’ function

    to view the wave (it is really fast but screenshot-able).

  15. Tomi Engdahl says:

    How to Trick Your Electrical Meter By Saving Power

    A group of Dutch scientists have been testing out some of today’s “smart” electrical meters to check their accuracy, among other things. Not ones to disappoint, the scientists have found consistently false readings that in some cases are 582% higher than actual energy consumption.

    Their results? Well, “results varied wildly, with some meters reporting errors way above their disclosed range, going from -32% to +582%. Tests with uncommon results were repeated several times

    Millions of Smart Meters May Over-Inflate Readings by up to 600%

    Lab tests carried out by Dutch scientists have shown that some of today’s “smart” electrical meters may give out false readings that in some cases can be 582% higher than actual energy consumption.

    The study involved several tests conducted on nine different brands of “smart” meters, also referred to in the industry as “static energy meters.” Researchers also used one electromechanical meter for reference.

    Using a simple test rig, portrayed above, researchers connected the smart meters to various power-consuming appliances found in regular homes, such as energy saving light bulbs, heaters, LED bulbs, and dimmers.

    Problems blamed on smart meter designs

    Researchers blamed all the issues on the design of some smart meters, and, ironically, electrical devices with energy-saving features.

    The latter devices, researchers say, introduced a large amount of noise in electrical current waveforms, which disrupt the smart meter sensors tasked with recording power consumption.

    “The reason for faulty readings appears to be the current sensor,
    and the associated circuitry,”

    Since the research only covered smart meters commonly installed in Dutch homes, researchers say that around 750,000 smart meters deployed around the Netherlands may be giving out false readings.

    Worldwide, the numbers of possibly faulty smart meters could be in the millions, especially after some governments, especially in the EU, have pushed for smart meters to replace classic electromechanical (rotating disk) meters.

    UPDATE [March 27, 2017]: ESMIG, which describes itself as |the European voice of the providers of smart energy solutions” has published research that disputes the findings of the Dutch researchers. Here are their main conclusions :

    The electromagnetic interference phenomena created in the tests of the University of Twente grossly exceed emissions limits allowable under EU regulation for equipment typically used in households.
    These conditions would not be found in any imaginable normal household scenario.
    There is no reason to question smart metering technology.

  16. Tomi Engdahl says:

    How Many Watts Are You Using?

    [Bogdan] built up a simple whole-apartment power monitor from scratch over the weekend, and he’s been nice enough to walk us through the whole procedure, starting with picking up a split-core CT sensor and ending up with a finished project.

    The brains of his project are an ESP8266 module, which means that he needed to adapt the CT sensor to put out a voltage that lies within the chip’s ADC range of 0 V to 3.3 V.

    The microcontroller reads the ADC frequently, does a little math, and you’re done.

    The rest of the code was borrowed from here or there. EmonLib takes care of the math, ArduinoOTA allows him to reflash the firmware over the air, and Blynk takes care of making a nice Android app for visualization.

    Power meter for the entire apartment

  17. Tomi Engdahl says:

    How to Measure Electrical Power

    If a product uses power, then power consumption and power quality measurements must be made as part of product design and test. These measurements are essential to optimize product design, comply with standards and provide nameplate information to customers.

    This article will discuss best practices for making these measurements, starting with power measurement basics and proceeding to the types of instruments and associated components typically used to make measurements.


Leave a Comment

Your email address will not be published. Required fields are marked *