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.

  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.

  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.


Leave a Comment

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