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:

    Safely Measuring Single And Three-Phase Power

    There are many reasons why one would want to measure voltage and current in a project, some applications requiring one to measure mains and even three-phase voltage to analyze the characteristics of a device under test, or in a production environment. This led [Michael Klopfer] at the University of California, Irvine along with a group of students to develop a fully isolated board to analyze both single and three-phase mains systems.

    Each of these boards consists out of two sections: one is the high-voltage side, with the single phase board using the Analog Devices ADE7953 and the three-phase board the ADE9708.

  2. Tomi Engdahl says:

    How to build an Arduino energy monitor – measuring mains voltage and current

    This guide details how to build a simple electricity energy monitor on that can be used to measure how much electrical energy you use in your home. It measures voltage with an AC to AC power adapter and current with a clip on CT sensor, making the setup quite safe as no high voltage work is needed.

  3. Tomi Engdahl says:

    Logging 2 Electricity Smart Meters Using Arduino Nano Every © GPL3+

    Data logging from two electricity meters (type “eHZ”) simultaneously and store data (time and value of reading) to an SD card.

  4. Tomi Engdahl says:

    This energy monitor plug is actually really smart inside.

    There is a very fancy chip inside that rivals the accuracy of the Hopi, but with the slight annoyance of only displaying one or two variables at a time.

  5. Tomi Engdahl says:

    Home Power Monitoring
    With PZEM-016, monitoring of 3 phases in main electrical arrival of my house

  6. Tomi Engdahl says:

    This Digi-Key Electronics article introduces the idea of using a current sense transformer and a Nano 33 IoT to obtain the data required to simply and cost-effectively implement a predictive maintenance tinyML application:

  7. Tomi Engdahl says:

    The digital home electrical meters typically measure nowadays the current and voltage going on the live wire. The current can be measured with a very low value shunt resistor in series with the line or using magnetic sensor (currrent transformer, rogowski coil or hall sensor). Voltage is typically measured with a resistive or capacitive voltage divider or using voltage transformer.

  8. Tomi Engdahl says:

    Can my $15 DIY AC/DC Current Clamp keep up with a commercial one? || DIY or Buy

    In this episode of DIY or Buy we will be having a closer look at my broken AC/DC current clamp which can be also called a current probe. The job of such a current clamp is simple, visualizing the current waveform on an oscilloscope. So in this video I will explain how such a current clamp functions and how we can make a DIY alternative in order to find out whether it makes sense to DIY such a tool or whether we should stick to the commercial solution instead. Let’s get started!

  9. Tomi Engdahl says:

    Custom Isolated Variac Is Truly One Of A Kind

    It’s no surprise that many hardware hackers avoid working with AC, and frankly, we can’t blame them. The potential consequences of making a mistake when working with mains voltages are far greater than anything that can happen when you’re fiddling with a 3.3 V circuit. But if you do ever find yourself leaning towards the sparky side, you’d be wise to outfit your bench with the appropriate equipment.

    Take for example this absolutely gorgeous variable isolation transformer built by [Lajt]. It might look like a high-end piece of professional test equipment, but as the extensive write-up and build photographs can attest, this is a completely custom job. The downside is that this particular machine will probably never be duplicated, especially given the fact its isolation transformer was built on commission by a local company, but at least we can look at it and dream.

  10. Tomi Engdahl says:

    Using Homebrew Coils To Measure Mains Current, And Taking The Circuit Breaker Challenge

    Like many hackers, [Matthias Wandel] has a penchant for measuring the world around him, and quantifying the goings-on in his home is a bit of a hobby. And so when it came time to sense the current flowing in the wires of his house, he did what any of us would do: he built his own current sensing system.

    Inductive current measuring using Raspberry Pi

  11. Tomi Engdahl says:

    Homemade DC/AC Oscilloscope Current Clamp | Hall Sensor + Ferrite Core

    The clamp works perfect but is not the most professional tool ever, it is more as an example in order to understand the theory. You could always improve it using better OP AMP and a better circuit. It could observe both DC and AC currents with a range up to 9A. I hole you like it.

    I was looking for a current probe like this not long ago but gave up due to the high prices. This one is quite possibly the ugliest looking probe I’ve ever seen, but that’s OK because it obviously works! Why should I buy a probe costing hundreds of dollars when I can now easily build my own for dirt cheap? I learned something today. Great job, and I look forward to seeing more from you!

    What a wonderful, creative, low cost hack! This is exactly the basis I needed for a non-invasive high current monitor for a battery back up sump pump. Thanks so much for sharing!

    How a AC/DC Clamp-Meter works

    How can a clamp-meter measure AC- and DC-current without interrupting the circuit?

  12. Tomi Engdahl says:

    DIY current sensor (hall effect)

    DIY cheap and simple scalable current sensor. I forgot to mention it’s isolated from the circuit where is measuring current. Works on ac and dc. Can be made for under 2 $ but the normal market price are about 25$, you can find them on google typing “current half effect sensor”

  13. Tomi Engdahl says:

    DIY ESP32 AC Power Meter (with Home Assistant/Automation Integration)

    In this project I will show you how to build an ESP32 AC power meter that can be used with your home assistant setup. That means I will firstly explain how to actually measure and calculate real and apparent power along with the power factor and then I will show you how to use the ESP32 in combination with some complementary components in order to create the power meter. Let’s get started!

  14. Tomi Engdahl says:

    Hack Your Home Part 3: Power Monitor

    In addition to controlling appliances, we can also measure how much power they are using. In this episode, you will use a CT sensor to measure the current being drawn by an appliance and post that data to the Internet. Note that a little bit of math is necessary to figure out the average current.

  15. Tomi Engdahl says:

    DIY Arduino power/energy meter

    Months back we have build a current meter. Now, the last emter tutorial, we calculate power and print it on an OLED display. This project will measure current, voltage, power and energy. I’ve used a shunt resistor for the curent measure. More info below.

  16. Tomi Engdahl says:

    #347 Measuring Mains Voltage, Current, and Power for Home Automation

    In video #321, we looked at DC current sensors. Today we will look at how to measure AC mains currents, which is much more difficult. And more dangerous because it can kill you if you do not pay attention. And, because measuring AC power is useful in home automation, we will also look at how to measure voltage and calculate power. To measure correctly, we have to learn about phase shifts and power factor. And I will tell you the essential rule to live long around high voltages.

  17. Tomi Engdahl says:

    Accurately Track Your Mains Frequency

    Depending upon where in the world you live, AC mains frequency is either 50Hz or 60Hz, and that frequency is maintained accurately enough over time that it can be used as a time reference for a clock. Oddly it’s rarely exactly that figure though, instead it varies slightly with load on the network and the operators will adjust it to keep a constant frequency over a longer period. These small variations in frequency can easily be measured, and [jp3141] has created a circuit that does exactly that.

  18. Tomi Engdahl says:

    Smart Energy Monitoring System Using ESP32

  19. Tomi Engdahl says:

    IoT Based Energy Consumption Cost Calculator Using ESP8266

    Circuit & Code:

  20. Tomi Engdahl says:

    What’s In A Wattmeter?

    The idea behind watts seems deceptively simple. By definition, a watt is the amount of work done when one ampere of current flows between a potential of one volt. If you think about it, a watt is basically how much work is done by a 1V source across a 1Ω resistor. That’s easy to say, but how do you measure it in the real world? [DiodeGoneWild] has the answer in a recent video where he tears a few wattmeters open.

    There are plenty of practical concerns. With AC, for example, the phase of the components matters. The first 11 minutes of the video are somewhat of a theory review, but then the cat intervenes and we get to see some actual hardware.

    Wattmeters – what’s inside, how do they work

  21. Tomi Engdahl says:

    EdenOff is a Nano 33 BLE Sense-based device that can be placed inside of a wall outlet to predict power outages using a tinyML model.

    This Arduino device can anticipate power outages with tinyML

    Bandini then deployed this model to a DIY setup by first connecting a Nano 33 BLE Sense with its onboard temperature sensor to an external ZMPT101B voltage sensor. Users can view the device in operation with its seven-segment display and hear the buzzer if a failure is detected. Lastly, the entire package is portable thanks to its LiPo battery and micro-USB charging circuitry.

  22. Tomi Engdahl says:

    Arduino Based Overvoltage And Undervoltage Protection System
    Full Details & Project:

  23. Tomi Engdahl says:

    I have completed this project assembly and am glad about the turn out of the whole working process.

    This is an electrical load management system, which monitors the maximum load an output source can provide.
    The preset load ratings can be easily key into the microcontroller internal Eeprom memory using the 4×4 keypad module.

    Once the load ratings of each line gets reached, the system will automatically cuts out the particular line until the load ratings are reset.

    I couldn’t have completed this project to this working level, if not for the inputs that I got from Martins Obi who guilded me how to rectify the challenges I had while programming this project.

    I have shared the design information for this project on the video description for the project demonstration, as you can find both the schematic diagram, Arduino code and further materials that I made available, inclusive with the corrected code from Martins, here

    #project #design #programming #embeddedsystems #Electronicsdesign #iotdevices #arduinoproject

  24. Tomi Engdahl says:

    High Precision Digital AC Energy Meter Circuit [Voltage, Current, Power, KWh]

    Disclaimer: Some parts of this circuit carry 220V Mains voltage. Be careful with your experiments. If you are a beginner, ask some experienced users to guide you.
    Dealing with the 220V-AC mains voltage and measuring the AC loads’ true power, voltage, and current parameters are always considered a big challenge for electronic designers, both in circuit design and calculations. The situation gets more complex when we deal with the inductive loads because inductive loads alter the sine-wave shape of the AC signal (resistive loads don’t).
    In this article/video, I introduced a circuit that can measure the AC voltage, RMS current, active power, apparent power, power factor, and energy consumption (KWh) of the loads. I used an Arduino-Nano board as a processor to make this more educational-friendly and attractive even for beginners. The device independently measures the aforementioned parameters and displays the results on a 4*20 LCD. The measurement error rate is around 0.5% or even lower.

  25. Tomi Engdahl says:

    Over and Under Voltage Protection using Arduino
    Full video and project file can be found in this link:

  26. Tomi Engdahl says:

    A DIY high-precision digital AC meter capable of handling inductive loads.

    This high-precision AC meter handles inductive loads

    This DIY AC meter can take the power factor into account, which lets it calculate an accurate reading of the real power of a circuit. An Arduino Nano board monitors a HLW8032 energy metering IC that measures line voltage and current. The HLW8032 calculates active power, apparent power, and the power factor and sends that data to the Arduino via UART. The Arduino then displays that data on a 4×20 character LCD screen. All of the components mount onto a custom PCB that contains input terminals for the AC source and output terminals for the load.


Leave a Comment

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