## 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

do i need to use a raw adapter without regulator? or does it need to be regulated?

thanks

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

Hi. alchemist3173.

I did a lot of googling and there is not a great deal of choice regarding the AC/AC adaptor. Not sure if you are in the UK or not but I bought the Maplin variety, which works well, yet is fairly expensive, but Hobsons choice really. Google "n57at" and or see  this page for details.

AW

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

SKU 1279503 is an equivalent for the one specified in the original parts list. It has a slighly higer current output, but it doesnt matter.

(as of posting this, I note that it is out of stock though).

http://uk.farnell.com/jsp/search/productdetail.jsp?CMP=i-ddd7-00001003&s...

The PSUs are manufactured by Stontronics, so you may be able to find a reseller in your country.

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

i think u cant use AC /DC bcoz u need AC signal as output to measue the voltage and get power factor if u used  AC/DC u ll not get the voltage i think

:P

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

hello,

can i use a 9v ac/dc adapter for this kind of project?..

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

i think u cant use AC /DC bcoz u need AC signal as output to measue the voltage and get power factor if u used  AC/DC u ll not get the voltage i think

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

I have just built this circuit for my solar immersion controller and all seems to work ok except that after a few minutes running the arduino stops transmitting to the serial monitor.

Is it something to do with this line of code

for (int n=0; n<numberOfSamples; n++)

I am not to hot on the code side so bear with me. I want the code to run all the while so it monitors my solar pv all day.

any help would be great

thanks.

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

strange that it works for some time and then stops working.

try adding some serial.prints to debug at which point exactly does it stop, if inside the "for" and with what value of "n"

so you could at before the FOR

Serial.println(numberOfSamples);

and also the same line inside the FOR.

Serial.println(n);Serial.println("\t");Serial.println(numberOfSamples);

that way you can see if for some reason the value of "n" is not increasing and therefore the program gets stuck inside the FOR

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

I think it happened because I closed down the serial monitor. If I leave the serial monitor running it works continuous. Am I right in thinking that it will still stop after 3000 samples.

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

I seem to be having the same problem, I'm starting to think my burden resistor is too big. It works fine when there's no large draw, but stops when the wattage goes way up. I'm using two 30A split core current sensors. ( http://www.sparkfun.com/products/11005 ) got a pcb fabbed for a pro mini, and a set of xbees.