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

No one can help me with this?

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

Hi,

Running into the same problem, I came across this note that describes the problem (and solution!) rather well:

www.ti.com/lit/an/slaa122/slaa122.pdf

From the example, you can see that the formula defining FilteredV does the actual work, and that the PHASECAL is a correction to it to  account for additional phase lags of the CT transformer.

Bart

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

shiftedV = lastFilteredV + PHASECAL * (filteredV - lastFilteredV)

Studying the code, I realized that shiftedV is used to calculate the real power.

In "AC Power Theory 2" page is said that the real power is calculated with the instantaneous power.

There is something I did not understand? Or the documentation is really at disagree with the code?

What this line really do?

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

Hi, hope you dont consider this an offtopic, and if so, please move it or let me know.

I have bought this CT sensors on ebay.

I was using a smaller version of 5Amps for some time with no problem.

however the 20Amps version produce a buzzing noise when current goes through the primary wire. even if its "just" 1000W which is something the 5Amps CT worked just fine and did not produce a noise.

readings are correct but i dont now if its safe to leave this unattended due to the noise. it does not get hot though.

I also have an efergy CT and also a blue version of similar one. and none produces noise.

oh btw, I have 3 of this units and all produce the same noise.

thank you a lot !!

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

It's probably just loose secondary coils reacting to the electromagnetic field induced from the primary, causing vibration and hence a buzzing noise. Does is get louder if the current increases?

It's an unusual choice of CT, as the split-core 'clamp' rogowski coils are usually a lot easier to fit and maintain.

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

I will try tomorrow to increase the current and see what happens.

So by unusual you also mean bad? I got them because of their price on ebay and cause i did not mind having to fit the wire inside.

what do you mean about maintain?

I really dont think its a loose secondary coil as all three of them do it. by loose you mean inside the CT??? of my conection of the secondary to the circuitry?

thank you so much and please if you have time, help me out a bit more. thanks again.

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

So by unusual you also mean bad?

No not bad, in fact they are supposed to be more accurate than the split core CT's, but as you have said, more difficult to fit as they require disconnecting/reconnecting supply leads which some people are not comfortable in doing.

what do you mean about maintain?

CT's without a burdon resistor attached can develop very voltages in the secondary coils - enough to give you a wake-up call! so it's always handy being able to simply unclip it when working on your circuit/wiring ect.

I really dont think its a loose secondary coil as all three of them do it

That depends upon the build quality/design of all three. For example, if the sec coil is just a loose fit inside the plastic case, then it's hardly suprising that they buzz.

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

what do you mean about maintain?

CT's without a burdon resistor attached can develop very voltages in the secondary coils - enough to give you a wake-up call! so it's always handy being able to simply unclip it when working on your circuit/wiring ect.

This CTs generate a current of up to 20mA if I am not mistaken, please see this:

www.ebay.com/itm/Horizontal-Mount-20A-Input-Current-Inverter-Transformer-/220923995722

So I guess the maintain issue is not applicable? I am using a burden resistor to read from them. I dont really understand the wake-up call you mention.

I will try to record a video with sound tomorrow, however this things look very robust, and actually i have tried 5 of them, and all make the same sound.

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

I'm in the U.S. and I have a 120vac to 4vac transformer, can I use this or does the output need to be 9vac?

Thanks

~Corry

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

Different voltage AC adapter can be used but resistor values should be calculated accordingly: see detailed design page: http://openenergymonitor.org/emon/node/59