Detailed energy monitor system design
This part details the system design of the measurement part of a mains AC: non-invasive energy monitor built upon an Arduino. The system can be divided into 3 main parts:
-
Current sensors + current sensor electronics
-
Voltage sensor + voltage sensor electronics
-
Arduino (the microcontroller platform)
The sensors produce signals proportional to voltage and current. The analog electronics convert these signals in to a form ready for the Arduino which in turn calculates useful values in the digital world.
Sensing current
Image 1 – Clip-on CT sensor.
UK: Whole house energy use is measured with 1 CT sensor.
US: Whole house energy use is measured with 2 CT sensors.
Current is measured using a sensor called a current transformer (CT). A CT sensor works by induction. The current in the mains wire produces a magnetic field in the ferrite core of the CT. A secondary coil is wrapped around the ferrite core. When a resistor is connected across the terminals of the coil a current flows that is proportional to the current in the mains wire.
The sensor just clips around the wire to be measured which means that it can be easily used to measure the electrical energy used by a whole building.
The CT sensor produces a current that is proportional to the current flowing in the mains wire by:
Isensor = CTturnsRatio * Imains
The number of secondary turns on a typical home energy monitor CT is around 1500 and so the current in the secondary is 1500 less than the current in the mains wire. The current in the secondary is also electrically isolated from the primary current. This makes household CT's a safe way of measuring mains current.
Current sensor electronics
The current sensor electronics is divided into two main parts:
-
Current sensor and burden resistor
-
Biasing voltage divider
Here's the circuit diagram:

Schematic 1 – current measurement circuit
The CT sensor produces a current that is proportional to the instantaneous current flowing in the mains wire by:
Isens = CTturnsRatio x Iinst
The resistor in parallel with the CT sensor is called a burden resistor and converts the current Isens into a voltage:
VsensI = Burden Resistance x Isens
The two Rvd resistors from a voltage divider that outputs a voltage at half the Arduino supply voltage of 5V. This voltage biases the AC voltage produced by the CT sensor and burden resistor by 2.5V, needed because the Arduino analog input channel requires a positive voltage.
Voltage at analog input = Bias Voltage + VsensI
The capacitor C1 stabilizes the DC bias as this can often be a source of considerable noise.
Suitable sizes for resistors Rvd are 10 to 100k. Higher resistance lowers energy consumption but also increases noise.
A suitable value for C1 is 10uF.
Choosing the size of the burden resistor
-
Choose the power range you wish to measure.
-
Divide by the mains voltage to give mains current.
-
Convert the mains current from an RMS value to a Peak value by multiplying by sqrt(2).
-
Divide this peak value by the CTturnsRatio to give the current in the secondary coil.
-
The Burden resistor that gives the specified range is equal to 2.5V divided by the current in the secondary coil.
For quick reference:
A 100Ohm burden resistor with an efergy CT gives a current measurement range of 0 to 26.5Amps.
A 56Ohm burden resistor with an efergy CT give a current measurement range of 0 to 47.4Amps.
Efergy CT turns ratio: 1:1500
CT's also have an intrinsic phase shift of 0.1 to 0.3 degrees
A useful web page for calculating burden resistor size, CT turns and max Irms
Thanks to Tyler Adkisson for building and sharing this: http://tyler.anairo.com/?id=5.3.0
Sensing Voltage
Image 2 – AC to AC power adaptor
Voltage can be measured using an AC to AC step down power adapter. Using the power adapter method rather than making a direct measurement on the high voltage side maximizes safety as no high voltage work is needed.
Sensor Electronics
The current sensor electronics is divided into two main parts:
-
Step down voltage divider
-
Biasing voltage divider
Here's the circuit diagram:

Schematic 2 – voltage measurement circuit
The step down voltage divider scales the AC voltage coming from the voltage adapter down from 9V to around 1V peak-peak.
The resistors R3 and R4 form a voltage divider that outputs a voltage at half the Arduino supply voltage of 5V. This voltage biases the AC voltage produced by the CT sensor and burden resistor by 2.5V, needed because the Arduino analog input channel requires a positive voltage.
Voltage at analog input = Bias Voltage + VsensV
The capacitor C1 stabalizes the DC bias as this can often be a source of considerable noise.
R1 and R2 need to be chosen to give a peak to peak voltage of around 1V.
Suitable sizes for resistors R3 and R4 are 10 to 100k. Higher resistance lowers energy consumption but also increases noise.
A suitable value for C1 is 10uF.
The Arduino
The arduino is the heart of the system and also the bridge in-between the analog world of electronics and the digital world of software. The arduino makes it possible to graph energy consumption on a computer, upload information to the internet and display information on lcd's with ease.
For the basic energy monitor setup the Arduino takes the input from the sensors and sensor electronics, calculates values for real power, apparent power, power factor, rms voltage and rms current and outputs these values to the USB port were we can access them on the computer.
The interface between the analog and the digital world, the ADC
The Arduino turns the analog input signals into digital information with an on-board Analog to Digital converter.
The Arduino ADC has a resolution of 10bits this along with the sample rate determines the detail of the digital representation of the input analog signal. The Arduino analog input has a default input range of 0 to 5V (this can be changed). 10 bits means we can divide that range in to 2^10 or 1024 divisions. The ADC therefore has a 5V / 1024 = 4.8mV sensitivity (It can detect changes in the input voltage of 4.8mV).
An analog input is read by the command: sample = analogRead(pinNumber).
sample is an integer. If the voltage at the pin is 0 sample = 0. If the voltage is 5V, sample = 1024. If the voltage is equal to 2.5V, sample = 512 and so forth.
Arduino Sketch Structure
The Arduino sketch is structured as follows:
variable deceleration and setup
void loop()
{
for n=0 to numberOfSamples
{
read in voltage and current sample
remove voltage and current sample offset with digital high pass filter
correct current phase displacement with linear interpolation caused by: ADC multiplexing,
inherent CT and power adapter phase displacements.
accumulate squares of voltage and current for rms calculation
accumulate product of voltage and current for real power calculation
}
calculate values for real power, apparent power, power factor, rms voltage, rms current from accumulators
apply voltage and current calibration coefficients.
print values to USB serial
reset accumulators.
}
For a more detailed treatment of calculating values for real power, apparent power, power factor, rms voltage, rms current, have a look at AC Power Theory 1 and 2.
Hi Trystan - A couple dumb
Hi Trystan - A couple dumb questions from me about the arduino sketch...
1) What's the magic 0.996 value in the digital highpass filter? Could use a comment. :)
2) I'm thinking there should be a "nominal" VCAL just as a sanity check; assume I have XXX VAC at the wall, YY VAC coming out of the adapter, and YY/11 VAC in the middle of the voltage divider ... there should be some known/nominal VCAL given the wall voltage, the AC stepdown voltage, and the voltage divider properties, right?
We want to turn the arduino analog read value into the instantaneous Vac at the wall... So we have to scale it back up by all the factors involved.
(below assumes we've filtered out the DC offset already)
a) multiply by arduino scaling 5/1024 to convert the value read to the voltage read at the arduino.
b) multiply by voltage divider scaling (R1+R2)/R1 to get to the value at the AC adapter output
c) multiply by AC adapter scaling - (measured Vwall/Vadapter ratio) to get to the current wall value.
So, to go from (value read) to (wall voltage) I think we need to multiply by:
(Vwall/Vadapter)*((R1+R2)/R1)*(5/1024). For my case of 120VAC wall, 12VAC adapter, and 1/11 (10:1) reduction voltage divider, this would give me about 0.537 as a VCAL starting point, does that sound right?
If that all sounds right, maybe it'd be nice to have variables for the above values in the sketch, and scale by that initially, then let VCAL do the final tweaking; IOW VCAL would usually be closer to 1.0
(However, above only works if PHASECAL is 1.0 ... OTOH Vrms should be whatever it is, regardless of the phase calibration, right? So not quite sure how/why PHASECAL affects the measured Vrms, I guess it's because we're sampling over time and have to "scale" the voltage in the loop to accomidate the net effect of the phase shift...?)
Thanks,
-Eric
Sorry for the late reply on
Sorry for the late reply on this
1) The magic 0.996 was the value I think ATMEL used in their power meter example, it worked so I kept it the same.
2) Yes there should be, do you think though that many people will be using different step down transformers and voltage dividers and so a calibration will need to be done anyhow, specially given different voltages around the world? I could leave my setups calibration in there though as a guide, although it should be stressed that using it would not give accurate results even if components are the same, due to tolerances.
Trystan
As for the 0.996 value So
As for the 0.996 value
So this is a digital highpass filter and 0.996 is α ... I actually had this stuff in grad school but don't remember it at all now ;)
However, we -know- what the DC offset is; it's 2.5V (or as close to that as the voltage divider is accurate) so I just subtracted 511 from the value, it's a lot less computationally intensive...
The initial calibration may
The initial calibration may not be that important
... if you need to measure it and adjust it anyway, but it might be nice for people who have no reference meter to get at least a decent starting point for the values.
Plus it's a sanity check on the rest of the calculations; in my setup I only had to tweak VCAL (0.9820) and ICAL (1.0249) a little bit away from 1.0.
I did something like this:
*shrug* it's up to you :)
Nice idea and thanks for the
Nice idea and thanks for the code, I reckon it would be a good idea to do what you have done there, I have added it to the sketch and posted both versions up on the build page, I havent been able to test it though yet as all my arduinos are tied up doing other things, but it compiles ok.
Replying to myself ;) I think
Replying to myself ;)
I think that the accumulated squared voltages should not be using the phase calibrated voltage, but the instantaneous real power should. The PHASECAL essentially shifts the waveform by changing the measured value along the current slope by PHASECAL units; i.e. 0 uses the -last- measured voltage, 1 uses current voltage, 2 uses an approximated "next" value. This is fine for the instantaneous power (instP = calibratedV * sampleI), but it has the effect of changing Vrms, which it should not do; Vrms is what it is regardless of I/V phase shifts...
I think perhaps:
//Root-mean-square method voltage
//1) square voltage values
sqV = (double)sampleV * sampleV;
//2) sum
sumV += sqV;
...
//Instantaneous Power
instP = calibratedV * sampleI;
is better; this way PHASECAL has no effect on the Vrms but it does modulate the instantaneous power...
p.s. calling it "shiftedV" might be more obvious to the reader...
Thanks!
-Eric
Hey Eric, your quite right
Hey Eric, your quite right good observation. I will change it.
Greetings! I stumbled upon
Greetings! I stumbled upon this project after my dad wanted to measure and graph our home power usage. So I started looking into it, and found that the CTs are expensive for how many I need, so I'm going to build them myself.
Anyway, to the point, I wrote these calculators to calculate the burden resistor value, the max current value, and the ratio for the CT. It uses two of the values to calculate the third one. Have a look here: http://tyler.anairo.com/?id=5.3.0 It may help some others plan the CT values.
Congrates on making your own
Congrates on making your own CTs. Since you already have all the material to make your own CTs you might be interested in making a Rogowski coil. This is something that I want to eventually explore. So I thought that you might find this article interesting, http://students.uta.edu/cx/cxl7817/publication/2003RogowskiCoil.pdf
cheers,
Dawn.
Hello Tyler Great page!
Hello Tyler
Great page! thanks for building and sharing it! Im sure that will be useful for others, thanks.
Best of luck with the build, I would be really interested to know how your CT's work out.
Trystan
Thanks! One testing CT I made
Thanks! One testing CT I made seems to work. I made it out of a Coax cable ferrite noise suppressor, with 100 turns of 30 gauge magnet wire, and a 10 ohm burden resistor.
I need to build 32 CTs, 1 for each breaker line. It's going to read them through a series of multiplexers, and put the data in a MySql database. Then it's going to generate power usage graphs for each breaker.
I'll let you know how it turns out. :)
Nice work! that sounds
Nice work! that sounds awesome! let me know how it goes.
Will do. :) Here is a pic of
Will do. :)
Here is a pic of 30 of the rings: http://tyler.anairo.com/image/FerriteRings.png
I am in the process of making
I am in the process of making this Energy Monitor but I am still a little confused on how the step down ac-ac adapter measures the voltage correctly. From what I can remember about house circuitry, big appliances such as the washer and dryer are on one circuit and the lights and outlets are on another circuit. So it seems to me that the voltage circuit measures voltage usage of just lights and appliances that are plugged into the outlet like computers but it would not measure voltages that are being drawn by the washer/dryer.
Is this wrong?
Thanks,
Dawn.
Hey Dawn It sounds like your
Hey Dawn
It sounds like your based in the US? With the two live leg system? am I right? If yes, the voltage amplitudes are likely to vary a little as the different legs are loaded differently, however the voltage phase on both legs will be the same and so by using the one adapter you still get most of the information needed. Its really a matter of how accuracy you want to be, the variation in voltage on both legs may be less than errors introduced by only having a 10bit ADC for example, unfortunately I cant check this here as the system in the UK only has one leg; the voltage is the same for all appliances, if you would like to make an investigation that would be really useful.
One of the other things about the US system is that it is possible to connect across both live legs in order to get 220V, the power is calculated accurately by the fact that two CT's are needed one on each live leg, so for an appliance connected across the live leg say using 1kW the current measured by both CT's is 1000/220 = 4.54A the voltage is measured with one adapter from a live leg to ground as 110V, the aparent power is calculated as Voltage*current at CT A + Voltage*current at CT B = 110*4.54 + 110*4.54 = 1kW (real power calculated as the sum of the real power of each leg)
Hope that helps
Trystan
Trystan, Thanks so much and
Trystan,
Thanks so much and yes I am in the US.
That is a great explanation. I have been looking on web but could not find what I was looking for. I am going to go on vacation but when I get back I will check the variation in voltage and let you know what I get.
Dawn.
Hi Trystan, Greetings from
Hi Trystan,
Greetings from Brasil!
First, congratulations for your unique project!
I am having some trouble, apparently the sample coming from the CT sensor
is not changing it has the same output value all the time, that is 870, sometimes 871 and 869
Even with a 720W toster the sample value keeps in that range.
I am using a 560 Ohms resistor as the burden resistor.
Any Ideas?
Thank you very much!
All Right!!!! Problem Solved!
All Right!!!!
Problem Solved!
Hey Cesar Lascera, thanks
Hey Cesar Lascera, thanks for the greetings! good to hear you've solved it!
So, you are now only using
So, you are now only using the AC-AC adapter for voltage measurement, and not powering the arduino? Was this just to simplify the design, or were you unable to resolve other problems such as noise from the circuit? I like the idea of having a single AC adapter that measures voltage, and also powers the arduino - any thoughts?
Thanks,
-Eric
Hey Eric, Yes it was to
Hey Eric, Yes it was to simplify the design and get rid of the noise problem. I'd certainly like to investigate powering the arduino off the same transformer further, and I think a center tapped transformer design is probably the way to go, I hope to look into it when I have some time. Ive detailed the change further here on the further development questions page: http://openenergymonitor.org/emon/node/64
How is your energy monitoring efforts going? I see your connected to pachube, looks great!
Hi Trystan Still just doing
Hi Trystan
Still just doing the whole-house monitor from the meter pulse; good enough for now. Eventually will play with per-circuit monitoring. Getting solar panels in a month or so, and a new meter, so may have to rework some of this...
-Eric