Real-time Web Based Power Charting

Do-It-Yourself Smart Grid Monitor

Brief project description

This post details a real-time web based household power usage chart. The end result is a live chart in a web page that updates every 10 seconds with the instantaneous power usage for my entire house. The electrical current is measured on the main lines entering my home with AC clamps. The signal is then conditioned with a simple circuit and monitored by an ioBridge module. The ioBridge module takes care of feeding the data to the internet without the need for me to host a power hungry home web server. By using ioBridge widgets with a few JavaScript API calls on my web page, I am able to chart the data with Google Charts as it is measured and make kilowatt-hour calculations in real-time.

(This chart will begin plotting in 10 seconds)

Not so brief project description

Ever since I started paying for my own utility bill, I’ve been interested in my household power usage. Years before the Kill-A-Watt was introduced, I was measuring the power consumption of individual appliances in an attempt to figure out exactly where my money was going. Of course, back then I used a very low-tech way of doing it. I turned off and unplugged everything in the house, then went outside and timed how long it took my power meter’s “wheel” to make one revolution. Then I turned on appliances, one at a time, and re-timed a power meter wheel revolution. With a little simple math, I was able to convert the time differences into watts and get a pretty good idea of power usage of every appliance.

These days, EVERYONE is interested in lowering their household electrical consumption. One way to help do that is by tracking and understanding power usage real-time (not a month later when you get the electric bill). The following will describe the details involved in making a real-time web based household power usage chart.

There are a few ways to measure electrical power. The way I chose might not be the most accurate but it achieves two of the main criteria for this project. It had to be cheap and I didn’t want to screw with my home electrical wiring to make it work. I did not want make an electrical connection with main power wires. The idea of interfacing directly to 220v makes me nervous. I could have used a Kill-A-Watt but it is only good for one outlet. Plus there is no way to get at the actual data, just look at it. I’ve also seen commercial power meters for this kind of thing. Since those meters can cost over $1000, I didn’t want to go that route either.

For this project, I used an AC clamp. With an AC clamp, it is possible to measure the current traveling through a wire without physically touching it. Basically it is a simple transformer where the wire of interest acts as the primary coil and the AC clamp is the secondary coil. Most AC clamps are integrated into a multi-meter. I used a stand-alone type for my project. It outputs 10mV per ampere and is intended to be connected to a multi-meter. All you do is multiply the voltage reading by 100 to get the current in the wire. These can be found for $20 or less on Ebay. Mine were made by Steren, model MUL-285. The great thing about using an AC clamp is that I was able to do all of my prototyping without ever turning the power off.

The only issue with an AC clamp is that the mV output is also AC. This isn’t a problem for a multi-meter since it can be set for measuring AC voltages. However, the ioBridge module is expecting a DC voltage on its analog input pin. Therefore a little signal conditioning is required to convert the AC RMS value into a DC equivalent. The circuit I used was my own design and used components I had on hand, so I’m almost certain that it’s less than ideal. After I was done soldering it up, I found a simpler circuit here. You may want to try it instead.


The main component in the circuit is an Analog Devices AD8220 instrumentation op-amp. This part only comes in surface mount style packaging. I needed to use a tiny SMT-to-DIP adapter board for my circuit. Don’t feel like you need to use the exact same part. Any rail-to-rail instrumentation op-amp will work just fine. For example, the AD627 (Analog Devices) will work too and it comes in a breadboard friendly DIP package. In my circuit, I used a 16k resistor to achieve a gain of 4. Feel free to use a different resistor to get to a particular gain you need. However, any change in gain must be compensated for in the JavaScript of the webpage.

The other part of the circuit is a “leaky” peak detector made with a diode, resistor and capacitor. Its purpose is to translate the AC wave peaks into a DC voltage level. The 47k resistor causes the leakiness. Since the voltage level updates 60 times per second, adding that resistor increases the system’s response time.

The potentiometer is used for offset calibration. I used a 15-turn pot for the best accuracy. To calibrate, power the circuit, make sure the AC clamp is not on any wire and measure the circuit’s voltage output. Adjust the potentiometer until 1.000v is reached.

Caution:
Don’t touch ANYTHING inside the breaker box! The beauty of using an AC clamp is that it’s designed for this sort of thing. Just clip it on a line you’re interesting in measuring and put the cover back on immediately. Touching the wrong thing in there will kill you. I don’t assume any responsibility if someone injures themselves trying to recreate this.

To access my particular breaker box, I just removed the front panel by unscrewing the four screws in the corners.

I used two converter circuits in my setup. In most US homes, the electricity comes in as 220v on 3 main lines. Some appliances, like ovens and clothes dryers, are connected to these 220v lines directly. However, by using just one of the lines, the power is reduced to 110v for all the wall outlets. Usually, a home’s electrical wiring is divided into two sections. One line (known as a leg) powers one section of the home and the other line powers the other side. To get the total power usage in my house, I put an AC clamp on both legs and added the measurements together.

If you are interested in monitoring a single breaker or maybe a single appliance, this method will still work. Just put the clamp on the wire coming out of the breaker. I measured single appliances by splitting an extension cord and clipping the clamp around the wire. (It is necessary for the clamp to be places around a single wire only. Clamping all the wires of an AC electrical cord simultaneously won’t give you a reading.)

To fine tune the scaling factor for converting measured DC voltage to AC current I used a Kill-A-Watt and a portable space heater. I first measured the current draw with the Kill-A-Watt. I then did the same thing my setup, using the clamp on a modified extension cord. Assuming the Kill-A-Watt was accurate, I saw that my readings were about 7% off and adjusted accordingly.

Getting the data to the web was probably the easiest part of this entire project. I just connected the outputs of my converter circuits to the I/O ports of an ioBridge module. The module was connected to my home network using a LinkSys wireless gaming bridge. That saved me from running another Ethernet cable to the electrical panel.

I then went to ioBridge.com and made two analog input monitor widgets, one for each leg of power to be monitored. I embedded these two widgets in my webpage to track the readings. My ioBridge module also monitors the inside and outside temperate.

To convert the voltage reading to current, use the following formula:

I = (VoltageReading – 1) x 100 / Gain


To convert this to Watts, the math gets a little fuzzy. A number called the “Power Factor” is needed. The power factor is different for different appliances. Some appliances use voltage and current in phase with each other. This is the case with a heater for example. An electric heater would have a high power factor, maybe 90%. Other things, like computers, use power differently and their voltage/current demands are not in phase. In these situations, the power factor is lower, maybe 35% to 50%. Your entire home is a combination of all these devices with differing power factors. In order to calculate power usage in watts from voltage and current, you’ll need to make a guess at the power factor. Most people use 60% as a good estimate for a home’s average power factor. I used 75% in my calculations. To get power use the following:

Assuming V = 110v (US homes)

P = V x I x Power Factor


As for the plotting and the use of Google Charts… I’m actually a JavaScript newbie myself. I’d rather not try to explain my patchwork of code. The source code is available for my power charting page and the embedded comments should help explain a little of how it works. Code involving the ioBridge widgets was taken from the Temperature Chart example available on their website. More information about the Google Chart API can be found here. I attempted to write the code in a way so that others could reuse it by just changing a few variables. But if you use a different circuit, you’ll need to make changes to compensate for different offset, gain and scaling.

There are a few features of the chart that I’d like to point out. First, it automatically updates every 10 seconds. It will continue to add more points for an hour. After an hour, data older than an hour will be scrolled off the chart to make room for new data. This limitation is because of the way Google Charts works. A Google Chart is created through the use of a URL. Since a URL is limited to 2048 characters, there is a limit on the amount of data that can be plotted at once. The other thing I want to mention about the chart is that it will automatically scale the Y-axis.

In this effort to track and minimize power usage, you may be wondering about the electricity consumed by the ioBridge module the LinkSys wireless bridge. Together they use a mere 5 watts! That is considerably less that running a home web server to publish this data.

After using this setup for a few days, I’m amazed at how much power our hot water heater uses (as you can see in the picture below).

Special thanks to Steve for suggesting this as a potential application of ioBridge hardware/software.

And yes… I do know “The Energy Detective” exists. I don’t believe the T.E.D. will publish data directly to your web page without a server running in your home. Besides… it wouldn’t be a very good DIY project if I didn’t actually do it myself.

PS: If you add a comment that includes a link, I probably won’t publish it. Most times, the links are thinly-veiled attempts to plug other products or services.

This entry was posted in Uncategorized. Bookmark the permalink.

32 Responses to Real-time Web Based Power Charting

  1. Tim says:

    Awesome article! I bet if you went into production making kits this woudl be very popular! -Tim

  2. Cole Petersburg says:

    Impressive work! Technical note: U.S. house wiring comes in as two wires of 120V each. Because they are 180* apart, you can get 240V for your stove by connecting one to the other. Commercial buildings have three “legs” 120* apart, and the difference between any two is 208V. I suspect that there’s no ground wire going all the way back to the power company.

  3. Carl Nelson says:

    Hi, I’m a retired analog integrated circuit design engineer, and have a few comments about the analog portion of the circuit you used. You are peak detecting the current waveform, which will create fairly large errors when rectifying loads are measured, as with computers, TV’s, etc. That is in addition to simple power factor errors created by reactive loads like motors, etc. You could make fairly simple circuit changes which would avoid the peak detecting problem. The next step after that is to use a multiplier (made by Analog Devices) instead of an instrumentation amplifier, which would generate a true power factor corrected DC output. That would require connection to line voltage, but there is a safe way to do that, using a plug-in AC output wall adapter. Let me know if you want any further details.

  4. Val says:

    “I’m curious, how does the power company calculate this? After all, they don’t know what’s in your house.

    The power meters the utility company installs inside/outside your house, either the old mechanical rotating disk type or the newer solid state, measure active power. They do not need to know what’s in your house but they can measure/adjust for the power factor by sensing voltage and amperage and the phase shift between them (assuming the sinusoidal wave form).

    They do not use “the same cheap CTs” as some other poster mentioned.

    But all this being said, the project is truly nice and affordable. I like especially the web access part.

    Thanks.

  5. Anonymous says:

    Jason,

    Cool project. My electrical panel is surface mounted meaning the line comes into it form outside and is thus surface mounted as well. Can I simply place the clamp on the line coming from the meter?

  6. Jason says:

    I’m no electrician… but assuming you can access the wires individually, it should work. However, if all the wires are encased in a single cable, placing the AC clamp around that bundle won’t get you a reading. This is because the phases of the wires are opposite and will always add to zero.

  7. jjhall says:

    Any idea where to get those individual sensors listed above? I checked Mouser and Digikey with no luck.

  8. Anonymous says:

    Go Gators!

  9. Jim says:

    I have a question. For 120V things, I can see how you measure the currents in the individual phases and add them up. But for 240, aren’t you measuring the same current twice, since it comes in one phase and out the other?

    Wait a minute…you are measuring the current twice, so your current reading will be twice too big, but since the voltage is twice (240), the wattage still comes out. Cool!

  10. Anonymous says:

    Fabulous project!!!!!

  11. Anonymous says:

    Anyone knows what are the connector type for the current transformer clamp ?

  12. Todd says:

    Well today I put together the LM324 simpler circuit you referenced as mentioned in my prior post. I connected up everything and I’m getting a reading:

    http://route.dnsalias.org:83/AP/PowerMonitor.htm

    I’m still working on the formula and graphing.

    One thing I did that I’m not sure about. I tied both clamps together in series. When testing, this appears to work instead of using two inputs and adding them together. Do you see any drawback to this method?

    Todd

  13. Jason says:

    I thought about using the clamps in series myself but decided against it. Since the clamps are measuring an AC signal on two conductors that are out of phase, I didn’t think it would work all that well. But I never did actually try it.

  14. dbg says:

    You could measure voltage safely and accurately using two step-down transformers (e.g. low voltage AC-output wall-warts), plugged into different receptacles. Search for two receptacles that are on circuits connected to the two opposite phases that bring the power into your breaker box.

    If you have a small microprocessor with several reasonably speedy A/D converters, you can multiply the voltage by the current as measured many times during each power cycle. The sum of those products is the energy used, and is correct for whatever power factor is currently in effect–in fact, you can calculate the true power factor using those measurements.

    You might be satisfied by using just one voltage measurement, but heavy loads on one phase can cause voltage drop in the neutral supply wire and thus shift the midpoint, so that the other phase’s voltage gets higher. So it’s more accurate to measure voltage and current on both phases.

    Power factor is caused by the current waveform either leading (capacitive load) or lagging (inductive load) or in sync with (resistive load) the voltage waveform. Modern electronic power supplies or controls can cause the waveforms to be extremely distorted, so ignoring the details of current versus voltage throughout the cycle can give very misleading results.

    The power company’s meter physically measures the components of current relative to voltage, so it compensates for power factors quite accurately. If you had a pure inductive or capacitive load, there could be large currents flowing, but for half the cycle the Volts * Amps would be adding and for the other half they would be subtracting, so the net power would be zero (ideally). The power company hates such loads, however, because the large currents (that you don’t pay for) do cause resistive losses in the distribution system (that you don’t pay for!), so they insist that large users correct their power factor (usually by using banks of capacitors).

    This is a really neat project–congratulations!

  15. Scott says:

    Hi Jason, this is an example of American resourcfulness and rich curiosity. You are to be commended.

    One question I have is if you have seen the Black & Decker Power Monitor system. It's $99 and does everything except the web feed. Considering your materials cost, have you considered hacking into the B&D device to web enable the data? The B&D device is a re-branded BlueLine Powercost Monitor.

    Since I'm not so good with the electronics as you are, I would much rather take the Black & Decker device and just hack into it (potentially with the iobridge) to feed the data to my web widget.

  16. Jason says:

    Scott,
    That’s a very interesting idea. I’ll look into that!

  17. Anonymous says:

    Dude you should sue google, they totally stole your invention.

  18. Yoyodyn says:

    Jason,
    Did happen across this page?

    http://www.kondra.com/circuit/circuit3.html

    This one is way expensive because of the board he is using. But it seems like the IOBridge might work with this kind of setup as well.

  19. Trystan Lea says:

    Thanks for doing this project! Good effort, im working on a power monitor myself at the moment, Its been very useful having your project up here. Thanks!

  20. Anonymous says:

    is there anyone willing to help me do a quite similar project that measures the total power consumption, say for about a month, instead of having it done on an instantaneous manner.. thank you..

  21. darwin says:

    sir, would you be kind enough to help me build a similar project that actually polls the data instead of pushing it? this would help in improving the project better for its long term usage instead of an instantaneous one.. thanks..

  22. blalor says:

    Great work, Jason. I’ve been meaning to implement this for my own (rented) home ever since reading this article a few months ago. Last night I finally got one clamp working. I think there’s something wrong with my fridge, ’cause I can’t believe how often it runs! (And how the noise just fades into the background).

    I’m a complete novice when it comes to electronics, so please bear with me. I’ve got a pair clamps similar to yours. I picked up an LM324 op-amp from Radio Shack (I know, I know) and, using 3k3 and 12k resistors, got a gain of 4.67, which should be enough to get 75A to register as 3.5v on my Arduino’s ADC. The LM324 will only amplify the signal to Vcc – 1.5v, and I’m running at 5v. So far so good. Is the op-amp’s gain a straight multiplier? Eg, is 10mV going to get amplified to 46.7mV with a gain of 4.67?

    I’m having difficulty understanding the capacitor in your circuit. It seems to me that it’s “backwards”, with the positive lead tied to ground, and the negative to the 47k resistor and ADC input. Can you explain how that works? I understand that the resistor is “leaking” the cap, but I don’t understand how it charges (except perhaps from the grounded side of the clamp, but that’s very small voltage…).

    What sort of resolution are you able to get? I bought a new DMM at Home Depot yesterday with an AC current-sensing clamp, so that I’d know if I was even close. Using a clothing iron and the incandescent lamp at my workbench, I’m able to measure about 0.5A with just the lamp, 12.1A with the iron, and (as expected) 12.6A with both turned on. My circuit, however, is not as responsive, however; it registers about 11A (scaling the ADC value up) which is sort of acceptable, but it doesn’t “see” the 0.5A change from the lamp, either with or without the iron on. Is that a limitation in the sensitivity of my cheap clamp, or have I buggered something up (likely)?

    Thanks for the great write-up!
    Brian

  23. Anonymous says:

    It’s a waist of time to measure voltage. Just assume a5% error. If you want to know the power factor of your home just turn everything on and use a multimeter. Find your current and voltage multiplied together is your S (or apparent power) then find your power using the meter this should be possible ha or wait an hour and check your house meter . Divide your S by p for your PF.

    Ryan

  24. Jason says:

    Brian,

    That was an error in the schematic. The capacitor was supposed to be facing the other way. Thanks for pointing that out.

    It’s hard to know exactly what is going on with your circuit. I tried to use the LM324 and didn’t have much luck either. I’m able to see 0.5A changes on my system. I’m actually in the middle of redesigning the whole thing to incorporate power factor. You may want to take a look at Analog Devices, AD737. It does what my circuit attempts to do, but is much much better at it.

  25. blalor says:

    Thanks for the reply, Jason. The first thing I’m going to do tomorrow is turn my caps around! :-)

    I found an adjustment pot inside my clamps and cranked them both up to their most sensitive/amplified setting. One clamp is *way* off and I had to increase the gain on that channel of the LM324 to 5.9 to get it to match the other clamp, whose gain is set to about 4.6. They at least read pretty much the same right now. The next time I place an order with Digikey, I’ll be sure to stock up on some better op-amps.

    Are you going to use the AD737 with your next iteration? I’m curious to see how that turns out. It looks like the perfect solution.

    I’m also on the look-out for some smaller clamp-on CTs. The off-the-shelf units I bought via eBay are nearly identical to yours, but don’t fit into my crowded electric panel…

  26. The Greenth says:

    Jason, The comments and feedback you have been getting indicate just how useful this kit is to lots of folk, well done. Are you collecting your internal/external data and analysing it to see if you can create a management dashboard yet?

    As well as pubishing the live data set up alarms and maybe simple email/sms messages to indicate where energy management savings can be made.

    This could then lead to controlling lights, HVAC and other devices automatically.

    Once great job!

    Mark

  27. t_lewis says:

    Jason,

    I constructed this project for one leg only so far. I used the AD627 and left the gain at 5. I am still messing around with the calibration, but was able to modify the html to accommodate only the single leg.

    Could you please explain why you biased the circuit to run from 1.0V to 5.0V, rather than from 0.0V to 5.0V? Is there some linearity issue with the op-amps or the IOBridge near 0V? Or some other reason?

    Very fun project, thanks very much for posting it!!

    Tom Lewis

  28. Jason says:

    Tom,

    It has been a few months so the details are a little fuzzy. But the 1 volt offset was related to the circuit not functioning correctly when the output was near zero. Sorry I can't remember the exact details.

  29. t_lewis says:

    Jason,

    I completed my monitor based on your solution. Thanks again. Site is http://www.thomaswlewis.com/?p=548.

  30. Ben says:

    This is a cool project, I'm trying to build one, but having the damnedest time ordering the clamps. The Steren site does not seem to have a working checkout. Any advice on how to order from them or someone else?

  31. Anonymous says:

    nice job
    i am going to try this out wireless

  32. Pingback: Web Based Water Metering with ioBridge | Jason Winters' Pico-Projects