Wednesday, December 17, 2014

Measuring Electricity with an Arduino

A few of us have been working on a project to try and figure out what is the most cost effective temperature at which to set our thermostats if we plan to be away for an extended period. I'll write about the details of that at a future date, but clearly an important factor in that determination is how much electricity our air conditioners use. That is a question that I have focused on recently.

 FPL (Florida Power & Light) provides hourly data, as shown here.

For my purposes, however, this has a couple of drawbacks. First, I would have to pull it from the website every day. Second, the highest resolution is on an hourly basis and I am looking for much more detail than that.

I nosed around the internet and I found a website called Desert Home. This is a fascinating collection of home automation projects with detailed how-tos. Dave from Desert Home referenced OpenEnergyMonitor. They sell a bunch of products for doing this kind of monitoring, but they also have a large number of educational posts that give the theory behind measuring electricity. Since I'm retired and have more time than money I decided to build the tools myself.

I ordered up some CTs (current transformers). They clip around the electrical feed lines coming into the house and produce a small current that is proportional to the large current that is flowing through the feed wires. You can see them near the bottom of the picture below. For those of you not familiar with household electricity, in the US we commonly use 120Volt 2-phase 60 Hertz current. That is, the voltage on each of the feed lines alternates between a root-mean-square voltage of +120V and -120V relative to the neutral wire (the thick white wire in the picture) 60 times per second. That's why there are two transformers in the picture, one for each feed line. Incidentally, the 60 cycle wave-forms on the two feed lines are 180 degrees out of phase (thus it's called 2-phase) with each other, so when one is at +120V the other is at -120V. Thus the potential between the two feed lines, rather than between the feed line and the neutral, alternates between +240V and -240V 60 times per second. That's how you get 240V for your electric dryer or pool pump or whatever. But I digress.

You might think that's almost the end of the story, but you would be mistaken. The way power companies charge for electricity is on the basis of "real power." Real power is the instantaneous voltage multiplied by the instantaneous current, giving the instantaneous (real) power (in watts). The reason that's important, the folks at OpenEnergyMonitor taught me is that electrical devices draw different amounts of current at different voltages. The plots of voltage and current draw might look something like this. So what you have to do is measure the voltage and current a bunch of times a second, multiply them, and then total them up. 

Okay, so here is what my setup looks like with all the covers off.

I have two 200amp panels, each with two feeds so I have four measurements that I take. I ran a piece of conduit from each panel to the blue box. I then connected them to a circuit I built, again based on guidance from OpenEnergyMonitor that conditions the current coming from the transformers so that it can be measured using an Arduino microcontroller. You can see it hanging from the wires in the bottom of the above picture. You will remember that the two components needed to measure the power used are current and voltage. That's why there are two "wall wart" transformers plugged in in the picture. One powers the Arduino and one just delivers the alternating current waveform to the conditioning circuit.

Here is a closer picture of the circuit stacked on top of the Arduino.  And here is everything all buttoned-up.

The Arduino takes around 45,000 readings a minute from each of the four current sensors. That may seem like a lot but you must remember that the voltage is alternating 60 times per second so 45,000 readings per minutes is 750 readings per second and if there are 60 cycles per second that is only 12.5 readings per cycle. The Arduino takes the readings and averages them for one minute then stores that number. Then every five minutes it uploads the data to a small computer up in my office. That computer stores the information in a SQL database that I can access via web browser from any computer on my network.

I was a little concerned that I was only getting about 12.5 readings per cycle but the electrical usage that I measure is within less than 2% of what Florida Power and Light reports so it's pretty close, and I think I can get it even closer if I tinker with my calculations a little.

Here is a graph of the electrical usage on a minute by minute basis. The four colors are the four electrical feeds. I know what circuits are connected to what feeds so I can use the information to track down what equipment is using the electricity. I've just gotten this working but there are some features that jumped out at me. Specifically, the blue, yellow, and red lines all have trains of more or less evenly spaced peaks. The blue ones repeat about once every forty-five minutes, the yellow once every two hours, and the red once an hour.

I showed them to Peg and asked her what she thought they were. She said, "What about the refrigerator?" I said it couldn't be that because they each have periods of even units of time, forty-five minutes, one hour, two hours. They must be things that are running on timers. I unplugged my cable box and TV. I unplugged the printer. I turned off the breaker on the security system...nothing. As it turns out they are three different refrigerators. The red one is the one in the kitchen, the yellow one in the outdoor kitchen, and the blue one a small beverage 'fridge that we have in the guest room. Who'd have thought? Well, Peg I guess.

That's it for now. As I said earlier, we're working on a project to measure air conditioner usage and I'll give you an update on that in a later post.


  1. Well, if you just left the refrigerator doors open you wouldn't need air conditioners in the first place.

    1. I was thinking I could go further upstream and just use the electricity to run a motor that would turn a generator thus eliminating the need for the electricity in the first place, and thereby short circuit the whole process. (pun intended)