Energy mesauring device, project to be expanded to home automation...

I designed this as part of a larger future home automation system.

Basically I got tired of using power measurement devices that clamp into one of the cables of the electricity meter.

These devices are never accurate because they only measure current... Therefore:

Changes to the incoming AC voltage are not taken into account to calculate the real power

An AC supply is composed of several current components (Real, apparent, reactive). Unless all devices in the house are resistive, and therefore have a unity power factor, the measured current and hence consumption will differ from what is in fact being used.

Slow bandwidth: A heater fed with a half wave rectifier, a dimmer circuit or even a switch mode power supply, which pulls power is short bursts near the peak of the AC supply require a bandwidth in the order of a few KHz to correctly detect the phase angle duration and calculate the average power consumed with accuracy. This isn't achieved in most cases, simply because such devices are battery powered, sampling current in intervals and sending it in an even slower wireless transmission once every few seconds.

Put it simply, the results are wrong. Most modern plug in energy meters account for this, but its impossible to use one of these to measure a whole house consumption.

To overcome this I designed a circuit that measures the light pulses from a digital meter and calculates the instant consumption exactly as it is being billed by the supplier. It also logs the last 6H consumption on a display, with one minute resolution, and saves such data to an SD Card.

A RTC is used to add time stamps to the readings and differentiate different billing periods. For example, an economy 7 or 10 tariff.

In a near future I will add a functionality to control remote slaves at given time by reading data on the SD card. This is currently done using plug in timers on those appliances that require it. Its expensive and troublesome to change values individually. The new system will allow adding devices with base on a unique ID by simply changing variables on the SD card.

The basic prototype is shown below. Its running for the last 3 months, with last reset date 32 days ago.

Also the sensor on the meter:

The code:
The code was squashed to fit on an UNO. It's mostly AVR GCC, rather than "arduino code"

To run, extract the zip to a folder and open the Power_meter.ino file. The other files will load in separate tabs inside the compiler.

Libraries needed:
All required libraries are included in the files and should not be changed. I believe the only thing missing is adafruit GFX library. The code includes the source files for my modified ILI9341 Fast library and skinned files for the SD card operation, Real time clock, time library, etc.

SD Card Files:
The data is saved to an Excel file.

The config file has the values of parameters to be used by the device, that can be changed by the user without the need to reprogram the processor.

The config file looks like this:

//---------------------------------------------------------------------------------------------------------

	SMART METER INTERFACE
	Carlos Silva - V1.0, October 2015

	The Smart Meter Interface reads the optical output of the energy meter to calculate 
	Instantaneous energy consumption and total power consumed

	A Log is saved to an SD card showing power consumed within 1H intervals.

	Parameters:
	Pulse Output: Enter the number of Pulses per KW indicated on the meter
	Off-Peak Rates: 
		These are used to setup different electricity costs in Economy 7 or 10 Tarriffs.
		Typically an Economy 7 has a single Night Rate period, while economy 7 has a few spaced over the day.

		Offpeak(x) rate start: Enter time in the format HHMM
		Offpeak(x) rate end: Enter the number of hours in HHMM format

			Example: For off-peak time rate = 0AM to 7AM
				Offpeak rate start = 0000
				Offpeak rate end = 0700

			Example: For night time rate = 11:30PM to 6h30AM
				Offpeak rate start = 2330
				Offpeak rate end = 0630

		To Disable unused off-peak rates enter equal START and END Fields

			Example: Disable Offpeak Rate 2:
				Offpeak rate start = 0000
				Offpeak rate end = 0000

	Card Security Code: Used to detect a valid settings file. Set to 651.

	Max watt dislay: This is used to capp the maximun value the graph plot is able to display
	before clipping occurs, in order to have a better visual accuracy of the consumption as most
	loads draw power continuously, but at a low rate, with high consumption loads only used ocasionally.

	Whenerver power usage exceeds this value the graph is be capped and the plot printed in red.
	There are 180 Active pixels. If this value is set to 2000W, each pixel represents 11W, if set to 10000W,
	each pixel represents 55W.

//------------------------------------------------------------------------------------------------------

		[PULSE_PER_KW=1000]
		[OFFPEAK_RATE_START=0135]
		[OFFPEAK_RATE_END=0834]
		[OFFPEAK1_RATE_START=0000]
		[OFFPEAK1_RATE_END=0000]
		[OFFPEAK2_RATE_START=0000]
		[OFFPEAK2_RATE_END=0000]
		[OFFPEAK3_RATE_START=0000]
		[OFFPEAK3_RATE_END=0000]
		[CARD_SECURITY_CODE=651]
		[MAX_WATT_DISPLAY=3000]

Also attached a few months data logging. Would be nice to have a program to automatically read and display as a graph. Anyone up to the challenge?

One thing Ill change is data to be saved every half an hour rather than every minute. Displayed data will still be shown in 1 minute steps.

Instant consumption is updated at every new meter pulse.

Feedback Welcome :slight_smile:

Power_meter.zip (22.9 KB)

Zipped log file (20 October to 14January) attached

DATALOG.zip (689 KB)

Question: What are you going to do with the data now that you have it? And what use is real power information going to give you? Are you going to use it to dispute your power bill? And being able to measure the power consumption of a dimmed bulb - does that mean that you are not going to use a dimmer any more, or are you going to justify it for walking around in a dimly light house. Most people can figure out if they keep the lights off their power bill won't be as high as if the turn all the lights on and left it on.

I don't see the need for the minutiae.

If you have internet connection you could upload your results to a site like pvoutput.org (geared towards solar but can input power consumption too) or thingspeak.com . If you prefer to host your own site may Emoncms.org or nimbits.com?

If not you can make nice graphs using excel or R on your PC.

The nice thing about detailed graphs is that it allows you to see how much power is used during times you didn't think you used much, often due to appliances you think are off but still using significant power. It amuses me how many people obsess about switching off lights but keep their old refrigerator running in the garage "just in case".

Oh yes! That and equipment that draws up to 5W in standby - The same as a low energy LED light bulb on 24H!

In the new firmware version Ill add a smaller window showing consumption plotted in 24H intervals as well.

Currently the LCD shows the last 6 hours, the rest is simply stored on the SD CARD.