Home energy (mains power) monitor

Hi folks,

I’ve just written up a mains power monitor project I’ve been developing for a little while. There’s a step-by-step building guide at http://www.instructables.com/id/Internet-connected-home-energy-monitor/, and the code’s in GitHub at https://github.com/IanHarvey/spark-monitor

I’m quite pleased with the performance you can get out of the STM32 micro - it’s sampling at 12 bits/50KHz (using DMA and triggered from an pin interrupt) and so there’s plenty of data for noise reduction through averaging: it’ll read down to a few watts and all the way up to 10kW.

Have fun,


About 10 years ago I made a power meter using an atmel atmega 8 and it was incredibly accurate with only an 8 bit adc and running at 8 MHz.

Should be pretty amazing with Spark!

This is very cool. Great job. I did almost exactly the same project, and just completed it recently. Even my code is similar, with the integration to calculate power. I didn’t do DMA though, just raw sampling. Maybe I’ll try to implement it that way.

I did find that the noise seems to contribute to over estimating wattage a bit, when I compared it to my home’s power company installed kWh meter. The effect is < 4%, so I just scaled it. I could probably do some fancy FFT or something to filter it out, instead I just scaled it to bring it in line.

One thing I thought was a good idea, though. I modified the cable from the current sensor to put the burden resistor right in the cable. The idea is I never want that cable around the mains of my house and open circuit on the other side. I’m afraid it will build up a high-ish voltage and fry something when I plug it in.

This is awesome! I have an Energy Detective, but it transmits the data over the mains power to a gateway, and it’s very sensitive and slow. It’s always been on my to-do list to do this with a Core (or now Photon). I can probably use the CTs already clamped on the lines with some adjustments.

Thanks for sharing!

The bit in the code which multiplies a sample by a sine or cosine value, and sums up the results, is in fact a Discrete Fourier Transform; as I’m interested in just one frequency (50Hz) there’s nothing to be gained from using an FFT.

I’m not sure there’s a need to put the burden resistor in the cable. The clamp acts as an AC current source, but this is shunted by the resistance of the coil (a few hundred ohms), so the open-circuit voltage is limited. This is why the sensitivity doesn’t usefully increase with a burden resistor more than about 1k.

Thanks for reading,

1 Like

Thanks Ian. I’ll look more closely at your code. Maybe I’ll learn some math(s).

If this were not a safety issue, I would not post a reply, as this is an old thread.
However, there is potential for electric shock and damage to an unburdened CT.

The CT is indeed a current source. But it isn’t shunted by the coil resistance.
If open-circuited with current flowing in the primary, the transformer secondary will attempt to continue driving current into what is effectively an infinite impedance. This will produce a high and potentially dangerous voltage across the open secondary.

Some CT’s have built-in protection. That can be either protective zener diodes, or, if the CT is the voltage-output type, it will have a built in burden resistor and so cannot easily be open-circuited.

A CT is the dual of a VT (voltage transformer)
Short circuiting the secondary winding of a VT produces an overload condition.
Open circuiting a CT secondary produces an overload condition.

What you’re describing is the effect produced by core saturation. It happens when the coupled magnetic flux is so intense that all magnetic domains on a ferromagnetic material are already aligned and thus do not respond to any further increase in the flux. i.e. an increase in the magnetic flux produced by the primary winding results in little or no increase in output from the secondary winding. Hence, the voltage across the burden inceases very little, or not at all.