Arduino Electricity Monitor

Arduino Electricity Monitor

I’ve had my eye on some of the commercially available home energy monitors for a while. They all utilise a current transducer that clips or clamps around the main cable coming into the house. I wasn’t too keen on these, as in order to correctly, and accurately, measure the current flowing, you need to accurately know the voltage too. Without making serious modifications to the supply cabling, this isn’t possible. Making changes to the supply cabling is pretty dangerous and not to mention, very illegal.

However, those of us lucky enough to have a modern, digital electricity meter, may have spotted an LED on the front that flashes whenever a certain amount of electricity has been consumed. In my case, it flashes 1000 times per kWh, which is once per Wh.

I found an excellent Arduino sketch over at that counts these pulses from the meter. There’s a very simple circuit feeding 5v to an LDR which is sitting in one half of a voltage divider. The output of this voltage divider is then wired to pin1 on the Arduino. Of course, pin1 supports interrupts, so we can get the Arduino to do something whenever that interrupt happens.

As it’s a ‘normal’ LDR and not limited to infra-red or anything, I needed to shield it from ambient light. If someone switched the light on, we’d probably get an errant pulse being recorded. The first thing that sprung to mind when I saw the size of the disc surrounding the LED on the meter was the small canisters 35mm photographic film comes in (remember that lovely stuff?!) So i dug one out and cut a hole in the base for the cable. Perfect fit. I need to fashion some kind of more robust bracket, probably involving velcro and strips of aluminium at some point. For now Blu-Tack will just about do.


I’ve modified the code to include parts of the standard ‘web client repeating’ sample sketch. I want to be able to log the data in a mySQL database so that I can graph it and do further analysis on it later. So the Arduino posts the measurements whenever there is a pulse to a PHP script that then inserts everything into a database.

There are a number of issues with this script as it stands. If I change the value in the ‘power’ equation (towards the bottom of the code), it breaks the script. With the numbers as they are, I get figures in the region of 600kWh, which is more like a small factory, rather than a domestic dwelling! For now, I’ve done a division in the PHP script to get this number to something more realistic. I need to get my maths head on, and do some thinking.

The other problem is that the Arduino seems to stop after a few hours. I can’t wok out what’s causing it. It’s powered up and the network lights flash in unison on the Ethernet Shield, network switch and Raspberry Pi (that’s where the PHP script is). But nothing is appearing in the database…

Anyway, feel free to use this code, but please let me know of any improvements or changes you make.


#include <SPI.h>
#include <Ethernet.h>

//Adapted from a sample Arduino sketch and,