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

Including voltage measurement via AC-AC voltage adapter and current measurement via a CT sensor.

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.

The energy monitor can calculate real power, apparent power, power factor, rms voltage, rms current. All the calculations are done in the digital domain on an Arduino.

### Step One – Gather Components

You will need:

1x Arduino

Voltage sensing electronics:

1x 100kOhm resistor for step down voltage divider.

1x 10kOhm resistor for step down voltage divider.

2x 10kOhm resistors for biasing voltage divider  (or any equall valued resistor pair upto 470kOhm)

1x 10uF capacitor

Current sensing electronics

1x CT sensor SCT-013-000

1x Burden resistor 18 Ohms if supply voltage is 3.3V or 33 Ohms if supply voltage is 5V.

2x 10kOhm resistors (or any equall valued resistor pair upto 470kOhm)

1x 10uF capacitor

Other

1x A breadboard and some single core wire.

Oomlout do a good arduino + breadboard bundle here £29

### Step Two – Assemble the electronics

The electronics consist of the sensors (which produce signals proportional to the mains voltage and current) and the sensor electronics that convert these signals into a form the Arduino is happy with.

For a circuit diagram and detailed discussion of sensors and electronics see:

CT Senors - Introduction

CT Sensors - Interfacing with an Arduino

Measuring AC Voltage with an AC to AC power adapter

Assemble the components as in the diagram above.

### Step Three – Upload the Arduino Sketch

The Arduino sketch is the piece of software that runs on the Arduino. The Arduino converts the raw data from its analog input into a nice useful values and then outputs them to serial.

a) Download EmonLib from github and place in your arduino libraries folder.

b) Upload the voltage and current example:

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

void setup()
{
Serial.begin(9600);

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 wavelengths, time-out
emon1.serialprint();           // Print out all variables
}
```

c) Open the arduino serial window

You should now see a stream of values. These are from left to right: real power, apparent power, rms voltage, rms current and power factor.

### Re: How to build an arduino energy monitor

Hi Trystan, I remember there were some pictures of this setup in your garage and you were using a regulator in order to use the AC-AC transformer to supply power to the Arduino with a big capacitor. I dont seem to find it anymore, is it still online?

Could you give me any info on how to build this? I am assuming that if a big enough capacitor is used, using the AC-AC transf for both things will not affect the voltage reading,right?

Thanks a lot

### Re: How to build an arduino energy monitor

The method used to calculate V_RATIO is returning an integer in the way the example is given (sketch with calibration method). Using an integer in an equation will give an integer as result (AC_WALL_VOLTAGE and AC_ADAPTER_VOLTAGE are considered as integers while they don't have a point).

I suggest to secure the formula:
double V_RATIO = (double) AC_ADAPTER_RATIO * (double) AC_VOLTAGE_DIV_RATIO * 5 / 1024 * (double) VCAL;

### Re: How to build an arduino energy monitor

Hi,

I'm using dual SCT-013-030 in series plugged on an atmega328p running arduino bootloader on 3.3v and 8Mhz. Also I have a 7.5v AC-AC transformer for voltage measurement.

Will I have to alter any portion of the library calculations? I'm having some strange values:
Real Power:|-1019.35687256|
Apparent Power:|1218.37536621|
Power Factor:|-0.836652576923|
Vrms:|133.550430298| -> THIS IS OK
Irms:|9.12296104431| -> THIS IS OK

My calibration values is:
emon.calibration( 0.285315, 0.128401361, 2.3);

Thanks,

Wagner Sartori Junior

### Re: How to build an arduino energy monitor

Hello Wagner, Try flipping your CT around, that should fix it.

### Re: How to build an arduino energy monitor

PS: Its to do with the direction of the magnetic field. Negative real power and correct apparent power values are usually because the voltage and current signal are close to 180 degrees out of phase, if you flip either the CT or the voltage sensing power adaptor leads around that should fix the problem.

### Re: How to build an arduino energy monitor

Fixed, thanks...

Real Power:|1492.89855957|
Apparent Power:|1668.04089355|
Power Factor:|0.895001173019|
Vrms:|133.835250854|
Irms:|12.4633893967|

### Re: How to build an arduino energy monitor

Great!, good work with getting it all built and working!

### Re: How to build an arduino energy monitor

im stuck in the calibration part.. I took the readings from the meter of the arduino, but then I used an AC clamp meter to find the current, from the generator I found its true power and what is the voltage. so now I have to change the numbers of the powerfactor until they come similar to the ones I found by my calculations??

### Re: How to build an arduino energy monitor

Yes that's it, the powerfactor calibration is just a matter of trial and error, I found around 2.3 to work best but try around other values around this value.

### Re: How to build an arduino energy monitor

if i want to read the power of the whole house.. the ct sensor ok ill just put it on the phase... but what i do the the voltage sensor?