How to build a basic energy monitor - Mains AC: non-invasive 3.0

Voltage and current measurement

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. The Arduino can then be connected to a computer, data logger, lcd screen, Ethernet link, etc to make use of the data.

Changes since last version

Electronics

  • 2x 10uF bias stabilizing capacitors added: more info
  • Changed Voltage measurement circuit
  • Power for arduino comes from a seperate transformer to AC voltage measurement transformer. 

Software

  • Arduino sketch rewrite, sketch now follows Atmel's 465 appnote method, adding:
    • Phase calibration
    • Digital high pass filter to remove offset.

Step One – Gather Components

You will need:

1x Arduino oomlout £23.67 , nuelectronics £16.99

Voltage sensing electronics:

1x AC-AC Power Adapter farnell £2.67

1x 100kOhm resistor

3x 10kOhm resistors

1x 10uF capacitor

Current sensing electronics (you will need 2 of these for whole house monitoring in the US)

1x CT sensor efergy £7.50 , seeedstudio $11.50

1x 56Ohm – 100Ohm burden resistor (for more info on choosing a burden resistor look on the detailed system design page)

2x 10kOhm resistors

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 voltage and current in the mains) 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 look on the detailed system design page.

Assemble the components as in the diagram:

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.

Download the sketch here: basicmonitor.tar.gz

The sketch with a calibration method thanks to Eric Sandeen that allows you to set the component values of the measurement circuit to obtain a rough calibration that can be tweaked further for accuracy with the calibration method at the bottom of this page. For further details see the discussion in detailed system design.

Download the sketch with calibration method: basicSketchWCal.tar.gz

and then upload it onto the Arduino. Then go to the Arduino serial monitor and you should see values being printed to the scre, looking something like this:

From left to right: Real Power, Apparent Power, Power Factor, Vrms, Irms.

Step Four - Calibration

If you compare the output from the serial monitor with the output from a reference energy monitor (like a kill-a-watt plug in meter) they probably wont be the same. To get accurate measurements the energy monitor needs to be calibrated, as follows:

Step one – calibrating power factor

Power factor needs to be calibrated due to phase displacements from the CT sensor, Power adapter and multiplexed ADC readings. To calibrate choose a load that is reactive like a fridge or a grinder and a load that's resistive like a heater. Compare the value for power factor on your energy monitor and your reference meter. Look in the Arduino sketch for the line:

double PHASECAL = 1.0;

Try different values until the power factor's agree for when you have the reactive load connected and when you have the resistive load connected. I found 2.3 worked well.

Step two – calibrating voltage and current

For best results choose a load that's within but close to the maximum range of your energy monitor and your reference meter minus a couple of hundred watts, most domestic plug in meters go up to about 3120W so around 2000-2800W would be fine (as long as this is also within the range of the energy monitor)

If your using non-halogen heaters beware that the power that they consume decreases for sometimes up to 10mins as they heat up. To take an accurate calibration point wait until the power consumption is stable.

Note down the Voltage and Current value off your reference meter and from the Arduino serial monitor and then calculate the calibration coefficients:

Look in the Arduino sketch for the lines:

double VCAL = 1.0; double ICAL = 1.0;

Multiply the old VCAL by the new VCAL and replace the old value with the result.

Upload the sketch and now hopefully your values should be a lot closer to what they should be.

kWh and Frequency

Add kWh and Frequency calculation with this sketch:

basicMonitorPlusKwhFreq.tar.gz

For more information see pages on:

Accuracy

Detailed system design

AC Power Theory 1

AC Power Theory 2

Household wiring

Extend it

Experimental new sketch that may be more accurate - more details soon

mainsACtest.tar.gz

Hi there I'm in the US so we

Hi there

I'm in the US so we have 240v across of two wires. i have a main, a solar pv and a subpanel to monitor - couple of questions

how do you wire two CT's into the Arduino? Would each one go to an analog input port?
if I have mutliple CT's (6 in my case, 3 sets worth), i would be able to see data from each one, and depending on how I wired it up, I could then compute the necessary values?

thanks!

Hey Chris Sounds like you

Hey Chris

Sounds like you have an interesting setup to work with!

To monitor mains in the US you need 2 CT's one for each live leg, and one voltage measurement between GND and one of the live legs using a step down AC-AC transformer as above.

How does your PV system connect up? Could you monitor on the DC side? 

And yes you would need to connect each CT to a seperate analog channel. 

Im on holiday at the moment. so sorry for not much info. Let me know a bit more about your pv setup and when I get back I will see if I can help you bit further.

Trystan

Hi Trystan - thanks! PV is

Hi Trystan -

thanks!

PV is using microinveters, so my measurement would have be off the 240v ac feed.

Sounds like it's doable - I'll need to go and get the parts now.

 How is your build going

 How is your build going Chris?

Hi Trystan - sorry, haven't

Hi Trystan -

sorry, haven't had the opportunity to get all the parts yet.... working on sourcing everything. Hopefully I'll get things in before the end of the month (or maybe october) and find some time to do all this!

Will post back on progress.

Chris, I'm in exactly the

Chris, I'm in exactly the same boat, I also have a pv system w/ microinverters in the US.

I had a whole-house monitor running from a meter pulse but my net meter w/ the solar panels killed that setup, so now I'm back to looking at Trystan's stuff. Feel free to ping me, sounds like we're working on the same thing at the same time. :)

Hi Eric - sounds like it! If

Hi Eric -

sounds like it! If you get around to it first let me know what you ended up doing! =)

Hey Chris I need to order

Hey Chris

I need to order some CTs still to really get going. Right now I have just a couple small ones, I may order some from the Brultech site (I'm not sure how much I trust the seeedstudio ones...) However I wonder if we can put CTs for both phases in series and measure total current that way on one analog channel... I'll have to think about how the phase relationships on the legs might matter and/or work out ...

What a great job you have

What a great job you have done!

It has inspired me to build one for myself. I have a house with grid connected solar and 2 phases. I built a 2 phase and solar input based on your design. The great thing is that with the power factor leading on the solar phase all the export values are Negative and your normal import values are positive. I am currently working on a perl script which downloads the information from the Arduino via USB to my Centos 5.3 server into a Mysql database. I also added WattHours accumulated. The Output looks like:
Freq, Frequency
Phase1,realpower,apparent power,power factor,Volts,current,Kwatthours,Watthours
Phase2,realpower,apparent power,power factor,Volts,current,Kwatthours,Watthours
Solar,realpower,apparent power,power factor,Volts,current,Kwatthours,Watthours
ExportSolar, Export/Import,WattHours exported since reset

My solar system is on Phase 2, The Export/Import value is determined by adding Solar realpower with Phase 2 real power, a negative value means that I am exporting. I have 3 Current transformers and 2 power packs. I also added a individual calibration for each sensor. I also added a input command to reset all the accumulated values. This is handy because you can reset the counters at midnight and all the values you see are just for today! All you need to do is send "r" to the Arduino. When I am completely finished I will make all my code available to everyone.

Thanks for the inspiration!
Michael Smith

Hey Micheal Nice work! Yea it

Hey Micheal

Nice work! Yea it would be really great to see your code once you have done, if youd like to use the blog here your more than welcome I can add you, just let me know

Thanks

Trystan

Hello, Very nice project. I

Hello,

Very nice project. I was inspired to make my own power meter :)
I have one request. Can you explain abaut "Step one – calibrating power factor". I don't understand how to do this. What is "reference meter"? Is it some over precise power meter?
I have this one http://www.lemona.lv/LIUSE/NI/PM300-1.pdf but it dosn't show power factor.

"the power factor's agree for when you have the reactive load connected and when you have the resistive load connected" - where p.f. valuest have to be equal, on my power meter and reference power meter?

Thank you.

Hey Tomas Good to hear you've

Hey Tomas

Good to hear you've build one!

The reference meter I'm using is a pretty cheap but accurate enough meter similar to the one your using: http://www.maplin.co.uk/Module.aspx?ModuleNo=348228

What's the value for power factor that you get with a purely resistive load? You should get 0.99-1.00 If you do then its probably calibrated well enough.

"where p.f. valuest have to be equal, on my power meter and reference power meter?" - yes

Trystan

 

 

Hi Trystan Thank you for the

Hi Trystan

Thank you for the answer.
Everything is working now. Power meter is showing pf=0.99 with heater connected to it.
Now it monitors 3 phases. In Lithuania we have Three-phase electrical instalation.

 Nice work Tomas!

 Nice work Tomas!

I ordered my equipment from

I ordered my equipment from seeedstudio a month and half ago and I have still not received my package. I have had to email them many times before I got a response. I spent a lot of money ordering stuff because I have friends, who want to build one as well. I do not think that they are very good to deal with and suggest using another company.

Not happy customer.

 Could I copy you in on the

 Could I copy you in on the email, can you send me your email address? my email is on the people page. 

Thanks for letting me know,

Thanks for letting me know, that's really bad service! I did try to email them once for information and had no reply too. But then I know of a couple of people who have recieved their orders in as Im aware a timely fashion. I will send them an email, to see if we can get through to them with a few more emails. 

Trystan

Have you noticed the voltage

Have you noticed the voltage meter wandering over time?

I've got my voltage monitor dialed in (~36 seems to be my magic number, FYI) such that the metered voltage pretty well reflects what the Kill-A-Watt reports. The there's as much as .5v difference as the metering starts, but after maybe ten minutes the two start to wander off from each other. Right now the OpenEnergyMonitor is showing me 124.74v while the Kill-A-Watt is reporting 120.7v. If I change the multiplier in the sketch to compensate then things are good for ten minutes or so, then things start to wander again. Hitting the Reset button doesn't clear up the problem. Likewise, unplugging and reconnecting the wall-wart does not bring the voltages into sync. And pulling the USB connection from the Arduino, then reconnecting it, also has no positive effect.

Any thoughts on how to bring the metered values more consistently into sync?

Hey dzm Interesting problem,

Hey dzm

Interesting problem, do you think it could it be related to the temperature of the wall wart? When you unplug the wall-wart have you tried leaving it too cool down before plugging it back in? I dont remember having the same problem but will try to do some tests next week see if I can shed some light on it.

 

 

I don't think it's related to

I don't think it's related to wall-wart temp, but I don't know that it isn't either. It could just be a cheap (and old) wall-wart producing a range of voltage rather than a consistent step-down.

I've left it all connected for days to see if things eventually level out. What I observe is the reported value in the serial monitor slowly wanderings from +/- 4.5v from what the Kill-A-Watt is reporting. At times I'll see 124.5v when the K-A-W is reporting 120v (this was the case when I began typing this text), at this moment I'm seeing 119.3v vs 119.3v (from K-A-W), and I've seen it as low as 114v vs 118v K-A-W. Over time it just slowly wanders from one extreme to the other.

I may eventually purchase the new wall-wart you link to below just to see if this is a result of an old wart being finicky.

Hey dzm Doing some test here

Hey dzm

Doing some test here myself at the moment, My voltage does vary around a bit, but more around the volt range, and it does seem to vary at a rate a bit higher than the reference meter. When I switch on loads like a heater however it does change at the same rate as the reference meter.

I wasnt sure to being with whether this difference in variation was due to differences in smoothing between the energy monitor and reference meter but a thought came to me that the reason for the variation may be in the sketch, the current sketch takes a long window of samples but doesn't check if it has sampled an integer number of wavelengths. I have uploaded a new experimental sketch that does this check and I think the output may be more stable, if you could test it and let me know whether it gets rid of the voltage variation problem that would be great! 

http://openenergymonitor.org/emon/sites/default/files/mainsACtest.tar.gz

Thanks!

Great page, I was thinking of

Great page, I was thinking of starting something similar, glad to see you beat me too it.

I look forward to trying it out, as I am doing my research project on a similar concept.

two questions / thoughts - could someone modify the code to include a web feed? http://www.pachube.com is a good place to send data, then you can read or display it

Second query - a web interface/display would be good - i am thinking of piwik, an open source version of Google Analytics.

also a wordpress or drupal etc plugin would be cool, to brag about it!

Hey Jeremy Your research

Hey Jeremy

Your research project sounds interesting, let me know how it develops.

I've made a start on the web interface side of things here:

http://openenergymonitor.org/emon/node/48

 

and I had a go at pachube a while back, at the time they didnt have detailed graphing so I worked on the mysql flot method in the link, but now they have better graphing I think it would be worth getting that back up and running. 
 
I would like to develop the mysql flot web interface further, have more info like daily kwh and look at adding a 'gaming' element that could make reducing/managing energy easier and more fun!

Do you happen to know of a

Do you happen to know of a 120V version of power adapter?

As you mention elsewhere, the mains in the US are 120v, not 240v. Unfortunately my random Googling isn't finding me a 120v version of the power adapter you link to above. Do you (or anyone else) happen to know of a 120v version of this beastie?

 Hey Dzm, this one should do

 Hey Dzm, this one should do the job from newark: http://www.newark.com/triad-magnetics/wau12-200/psu-ext-plug-in-12v-2-4w/dp/96M0298

All the best

 

Aha! I found an old one in a

Aha! I found an old one in a drawer. It seems the USRobotics modems of the mid-1990s used 9v AC in, so their transformers can be re-purposed. It would be nice to know where to source these new though.

Didnt see your second post

Didnt see your second post here, the USRobotics one sounds just right

Hi, Very interesting project

Hi,

Very interesting project and as i needed to only get the CT sensor (I already had all the components needed to give it a try) I could not wait to get started. I hope to expand it with the ethernet shild to send the results to a webservice to log the results into a SQL database for historical analysis and charting, when complete i will be happy to let you have the source code, etc. However I have a newbee question.

I have stopped as when I connect the CT sensor over the incomming mains to the house (I am in the UK by the way so only have 1 sensor) it generates a buzzing sound. Is this normal? I have disconnected it as I am not sure.

 Hello Dave, someone else

 Hello Dave, someone else mentioned this too, but we didnt get to the bottom of it. It's not something I have experienced so Im not sure what's happening. Which sensor do you have? do you know the number of turns? and max current rating? What happens when you add a 50-100Ohm burden resistor across the CT terminals?

Trystan, Thanks for the quick

Trystan, Thanks for the quick response. I have one of the efergy CTs (http://www.efergy.com/Products/efergy-shop-Accessories/EFERGY/DC-Extra-S...) and to be honest I was in such a rush to start the project I did not check what the max current rating was. However as soon as I place a 100 Ohm resistor across the terminals the buzzing has stopped. Will try and get the project moving again later today and will let you know how things progress. Is here the right area to post comments & questions? I have now registered on the forum site - would that be better?

Hey Dave, good to hear that

Hey Dave, good to hear that the 100ohm resistor stopped the noise, must be something to do with the current transformer saturating as it had no load. You can post comments here or on the forum, whichever you prefer, although it may be easier to keep track of discussions on the forum...

Hi Trystan, First, great

Hi Trystan,

First, great site!

I have a couple questions for you. I've tried to ask them in the forum, but it doesnt send the confirmation email so I can't post there.

I am considering building your energy monitor, after giving up on a Current Transformer+DS2438 (1 wire voltmeter) because there is no way for a 1-wire system to measure the phase shift.

I'd like to know what are the arduino analog input sensors capable of? They are 6 sensors, all capable of measuring current 0 to 5V, either AC or DC. Correct? How fast/often does it measure AC current?

Also, my ultimate reason in going DIY way instead of just getting a TED 5000 is to be able to monitor the mains AND each breakers separately. Having "only" 6 analog sensors is a limitation for me, given that I could only monitor the phase shift (1 input), the mains (2 inputs because I'm in the US) and either 3 110V breakers or 1 110V breaker and 1 220V breaker. Is this correct? Is there any easy way to add more analog sensors to the Arduino without buying another one?

Another option for me would be to use the arduino only for reading the AC current (phase shift) and using cheap (4$ each ) DS2438's to read each of the dozen or so clamps I would need. Then again, 6x 4$ is about the cost of an arduino with 6 sensors, so I might as well go all-arduino.

What do you think?
Thanks for putting this site up!

Cheers,
Simon

I've been googling around, but I can't seem to find the answer to this.

Hey Simon, I will just repeat

Hey Simon, I will just repeat my reply to your email here, incase its useful for anyone else. If anyone else is having forum sign in problems email me and I will try and see why its not working, seems to work for some and not others... I cant quite work out why.

The arduino has 6 analog voltage inputs, that can measure voltage in the range of 0 to 5V. I recommend looking up analog digital converters, ADC's, arduino ADC for more in depth info. The circuit and sensor connected to the arduino determines whether the arduino analog input measures AC mains current or AC mains voltage. 
 
The arduino usually samples instantaneous voltage and current at a rate of around 2800 times a second, However a reading for rms current requires many samples. A typical rms current, rms voltage, real power... set of measurement may take around half a second. The longer the time (number of samples) the more accurate, the shorter the less accurate. Have a look at detailed system design and AC power measurement theory here http://openenergymonitor.org/emon/node/56 
 
To measure rms mains AC current on many circuit breakers you could use a multiplexer to increase the amount of inputs as much as you want. Found this guide here that might be useful: http://www.arduino.cc/playground/Learning/4051 With this method you would have to measure the power at one breaker, then sequentially the next and the next and so on.
 
I'd recommend building the above first, monitoring only one outlet. Once you have that working, try adding more current sensors and current sensing circuits to the other arduino inputs, you will need to modify the code to read sequentially each current sensor which shouldn't be too hard. Once your happy with that, have a go at using a multiplexer as in the example to gain even more inputs! :D
 
Another thought Micheal who commented here: http://openenergymonitor.org/emon/node/56#comment-1281
has used a Arduino MEGA which has 12 analog inputs, he has documented his work here: http://www.komputer.de/wordpress/?p=8

 

Thanks Trystan! I will

Thanks Trystan!

I will keep reading about the arduino, this is very interesting.

I assume that getting the Arduino MEGA to start with would be cheaper and easier than getting a normal arduino+ the multiplexer, especially when taking shipping into account.

I'll google around, but what would be a good tutorial for arduino? Will just any PCB fit as a "home made shield" on top of the arduino?

BTW, Here's a link to Michael's page, translated to english by google:
http://translate.google.com/translate?js=y&prev=_t&hl=fr&ie=UTF-8&layout...

Would this Arduino MEGA board

Hey Simon,  Thanks for the

Hey Simon, 

Thanks for the translation link.

The Arduino MEGA board looks like the one you need, but I cant quite tell if it comes with the bootloader installed, If you look halfway down the page you see the pic with the: not included USBtinyISP bootloader. Maybe its worth dropping them an email to check whether they have already loaded the arduino bootloader to the board. Otherwise it might be a safer bet is to go with the official Arduino Mega.

The Arduino Mega is meant to be compatible with most shields so you should be ok.

Trystan