$5 Power Consumption Meter

I've been seeing a lot of talk lately about power consumption in the discussions so here is a dead easy $5 project for anyone who has a digital power meter installed and wants to see their KwH power consumption. It provides a serial data output which you
can develop further for your own use. As it stands it displays the readings constantly on the Arduino IDE Gui serial monitor.

Digital meters have a flashing LED indicating the consumption wattage per hour. This project uses a $2 Arduino Nano microcomputer (or Arduino Uno $5) and a $2 Photosensitive Module to detect the light pulses. The Arduino measures the frequency of these light
pulses and then converts them into Kwh consumption and displays the result repetitively onto the Arduino IDE Gui terminal. You can of course process the data further to input to your Pi computer etc. Here's the details.

First order the Nano or Uno from eBay not forgetting the USB cable if you require it. Arduino hardware and software is Open Source so all makes of Arduino are legitimate hence the very cheap China versions which is what I used. Also order the Photosensitive
Arduino module (so called), this is the one which has a flat faced photocell poking out front with variable pot and diff amp chip on the board with 3 pins out the back, VCC, Gnd and Dout. Search these - atmega328 Nano or atmega328 Uno and Arduino Photosensitive
Light Sensor Module. Depending on how keen you are you might want to also order some jumper leads etc. You will also need a 220 ohm resistor and 100nf cap to ground (both non-critical) as a spike filter to attach photocell Dout to pin D8 on Arduino to give
rock solid performance.

If you are not familiar with Arduino just go onto Arduino.cc website and download the Arduino IDE and install on your PC, Pi or Linux. With this you will write programs and upload them onto the Nano or Uno. Get familiar with it and try out the examples.
Once you've played around with that for a bit you can start on the project. You need to extend the Arduino library to include the Frequency Measurement utilities so download the Zip from
http://www.pjrc.com/teensy/td_libs_FreqMeasure.html and add them to Arduino IDE via Sketch>Include Library>Add Zip Library and select the one you've just downloaded.

Then connect up everything from Nano/Uno to Light module +5v, Gnd, and Do which goes to pin D8 on Nano/Uno via a 220 ohm resistor and connect a 100nf cap to ground from D8 as well. Temporarily sticky tape or bluetac the photo fingy over the flashing light on
the electric meter and adjust variable pot so the green led on the photo board flashes in sympathy - shut out all other light otherwise you'll get misreading's - take your time over this to get it just right. Most meters are 1000 flashes per Kw hour but some
are 800 (Sprint) or maybe something else so set this in the 'pulserate' constant in the software. Now paste the software below into the Arduino Gui and upload it to the board. Open the Arduino Serial Monitor and Voila! you should start seeing power readings.
You can adjust the const sample rate in the software to suit.

Where to go from here? There are a number of ways of exporting the data, serial transfer, I2C, or add a wifi module ($4) and web server software to the Nano/Uno thus permitting access via the internal web by Pi, phone, tablet or PC. This is the method I shall
be trying over the next week or so I can use the data for auto power management on my solar scheduler.

Note that some meters (mine) start displaying the power surplus as well when the solar excess power is greater than the consumption so some additional nifty software is required to track this and indicate deficit or surplus power consumption.
Another Note - you'll will have to indent the code to pretty up again