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.

Thursday, December 4, 2014

Housewarming present

I've mentioned in the past that my brother John and his wife Doreen are building a vacation home here in Venice. It was supposed to be done in July, then August, then September. Well, I guess new houses asymptotically approach completion, half way, half way half way but never quite there.  Each time I go by there are a tradesperson or two over there tinkering with something. However, they were down a few weeks ago, and they got a certificate of occupancy and actually stayed in the house. I thought that was official enough to give them their housewarming present.

It's what is sometimes called an ambient device. The idea is that is kind of conveys information to you almost subliminally. For instance, I've seen these small globes that sit on the table in your living room and glow green when the stock market is going up or red when the stock market is going down.

Well, down here in Florida we focus a lot on the weather. Considering how little weather we actually have here relative to the rest of the country it's a peculiar fixation, but it is what it is. Here is a picture of the device. It has two display modes, one is temperature and one is barometric pressure.

Here it is displaying a temperature of 83 degrees Fahrenheit. The top two lights represent the tens place and the rest represent the ones place.

In Barometric Pressure mode the top light shows the current pressure, the next one down the pressure three hours ago, the next one three hours before that, etc. etc. Here we can see that the current pressure is  between 30.00 and 30.20 inches of mercury, down slightly from three hours ago.

The device is made from alternating layers of cedar and acrylic. In the center of each acrylic layer is an RGB LED. It's really three LEDs (Red, Green, and Blue) built into one. Each color can be illuminated at 4096 different intensities and thus, theoretically, each LED can display 4096 x 4096 x 4096 = 68,719,476,736 different colors. Of course humans can't discern anywhere near that many colors so I settled on Red, Orange, Yellow, Green, Blue, Indigo, and Violet (Roy G Biv) White and Black (no light at all.)

I went over to Lowes and picked up cedar board meant to be a fence rail and ran it through the planer. Then I cut it into isosceles triangles.

I made some jigs and glued the cedar into squares.

Then I made another jig to drill holes to fasten them together and for the LEDs and wires.

I made a bigger square of cedar for the bottom and hollowed it out for all the electronics. Then fastened them all together.