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

hey guys thanls for uploading this project its really usefull but i have some problems i have connected every thing same but the output results is not satisfactory and not the same as given . an other thing i want to ask the ouput from the adapter and CT conneted to the arduino should be AC or DC i got one AC and an other DC .

so any one can help me please

thanks

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

Hi omer.

You need the AC/DC adaptor to power the Arduino which in turn powers the CT circuit.  You also need an AC/AC adaptor set to 9v to as the reference input. Don't forget to modify the sketch for your voltage, burden resistor etc.

AW

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

Hi, I have a fully working version 3.0 in my house expanded to not only 1 CT but 5 of them (1 efergy and 4 smaller 5A CTs from ebay)

I bought some 20A CT sensors to completely monitor each section of my house and wanted to make all 8 work together.

When testing the 20A CT individually they seam to work correctly however when using them with the rest of the proyect I get two problems´:

- The voltage regulator starts to get hot (probably the new CTs are using up to much current)

- The readings start to fail when I add the third new CT.

At first I thought there was something wrong with the CT sensors but now I think I might be hitting a max current value of the regulator.

so the question.....

Would it be possible to supply the 2,5V to all the CTs from another source or regulator? can I feed it also to the arduino to control voltage fluctuation?

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

What are the resistor values of the voltage dividers you are using? You can use a regulated external power source, but you should either also power the arduino with the same power source (not through it's voltage regulator), or apply a voltage divider to the power source for the CTs to the AREF pin to get equivalent behavior to not using an external power source.

I plan on doing a similar "zone" monitor, but haven't gotten around to it.

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

resistors are 470ohms

I also thought about the external power source, i am using the AC-AC transformer with a rectifier to DC of a capacitor and a diode bridge.

So I could get the output from there, pass it through an externar regulator and feed that to a voltage divider, then put those 2,5V to the CT sensors and the AREF pin.

Do you think this is correct?

I will have to look into the AREF pin as I have not used it before, but I guess there is some code tweaking to use that value as reference for the analog input?

thanks

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

470 ohms seems awfully low in value to me. The CT's in my system run on 10,000Ω (10kΩ). Try changing to that value and see it if helps keep your regulator happy.

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

Yes that is very low, there must be a mixup? we usually use 470kOhms

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

well I dont know why but yes I am using 470ohms.

so could this be the reason? what could be happening by using 470ohms instead of 470kohms?

btw, I am building a new system for a freind and the AC to AC transformer is of 1Amp instead of 0.5Amps which i have in my setup. Well in my setup the regulator does not heat up but in my friends setup it does and a lot !!

Why could this be?

Thank you very much

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

I guess 2x470ohms still does not use that much current, only 26.5 mA for 5 CT's which of course is much less than 1A. Could there be a short someware?

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

Trystan I am building a meter for a friend and want to use only CT sensor with no Voltage reading.

What is the best code to use here? I will be using 3 CTs which are different.

I have seen in the emonTx_SimgleCT_example

https://github.com/openenergymonitor/emonTxFirmware/tree/master/emonTx_S...

int CT_INPUT_PIN =          0;    //I/O analogue 3 = emonTx CT2 channel. Change to analogue 0 for emonTx CT1 chnnel
int NUMBER_OF_SAMPLES =     1480; //The period (one wavelength) of mains 50Hz is 20ms. Each samples was measured to take 0.188ms. This meas that 106.4 samples/wavelength are possible. 1480 samples takes 280.14ms which is 14 wavelengths.
int RMS_VOLTAGE =           240;  //Assumed supply voltage (230V in UK).  Tolerance: +10%-6%
int CT_BURDEN_RESISTOR =    15;   //value in ohms of burden resistor R3 and R6
int CT_TURNS =              1000; //number of turns in CT sensor. 1500 is the vaue of the efergy CT

but here the burden resistor says 15 ohms !!!!!! Is that correct? You were telling me about going up to 470kOhms because my values where too low.