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

The voltage sensor is a AC-AC transformer than plug into any available power socket in the house.

Good luck, Glyn.

Re: How to build an arduino energy monitor

Hi I am new to the arduino arena, I have downloaded the files & compiled them & load them to the board but it doesn't seem to be working. I am using a freetronics "Eleven" board, the problem seems to be with the line

emon.calc(20,200);              //Energy Monitor calc function

I get 1 line of output but nothing else.

If I comment out the line I can get the serial output of 0.00 for each of the values.

I have tried the other sketch mainsACtest which works fine.

Any help would be appreciated & info on why it doesn't work so I can understand the problem & the solution.

Thanks

Matt

Re: How to build an arduino energy monitor

Hi Matt, I have created a forum topic for this here. Hopefuly it will allow us to have a better discussion about your problem.

Re: How to build an arduino energy monitor

hey guys,
if i chose r3 and r4 to be 10 k.....then which sizes are best for r1 and r2 in the voltage sensor part...
many thanks

Re: How to build an arduino energy monitor

r2 should be 100K ohm and r1 10Kohm. Sorry this was not more clear. I will update the documentation. In the meantime it might be easiest to follow the pictotorial image under step 2 here: http://openenergymonitor.org/emon/node/58

Re: How to build an arduino energy monitor

Hi Trystan!

I'm building an energy monitor following your steps in "How to build a basic energy monitor - AC Mains: 3.0 non-invasive.". By "mistake" I've bought the sensor "SCT-013-000 " at seeedstudio. Do you know what "burden resistor" I can use to transform the output current of this sensor in useful AC voltage? [irms]

Do u know how many turns this CT have?

Thanks for your attention, all the best!

Gabriel

Re: How to build an arduino energy monitor

I ordered a CT from seeedstudio and when I calculated the turns I got a ratio of 1200 if that helps.

Re: How to build an arduino energy monitor

Thanks Dawn, that is useful to know

Re: How to build an arduino energy monitor

Hello Gabriel, Im not sure exactly what would be best as its not entirely clear in the datasheet for the CT what the turns ratio is. I have started a page here for the CT with some info on what may be a good burden resistor depending on the turns ratio. Have a look and let us know if you can establish whether it is 30 turns or 3030?

Re: How to build an arduino energy monitor

Hi Trystan

Thanks for your reply! I've placed a 100 Ohms resistor with CT configured with 1200 and works great! Do you have an ideia  to calculate kwh? Im using the Dave's example [http://draythomp.blogspot.com/p/test-html-code.html] as below:

=======================================================================

//Calculate amount of time since last realpower measurment.
ltmillis = tmillis;
tmillis = millis();
timems = tmillis - ltmillis;

kwhTotal = kwhTotal + ((realPower/1000.0) * 1.0/3600.0 * (timems/1000.0));

=======================================================================

But this method seems to carry an error, by not calculating the area of trapezoids but the area of the rectangle (blue+yellow). Any ideias to solve this problem?

Image:

http://i55.tinypic.com/cp8a1.png