Hi All,
(although I don't think this tutorial will be as much used as the HeadStart tutorials I've made, I think this tutorial is worth the hassle and I hope people enjoy reading and constructing this.)
Introduction:
In a world where energy prices are rising, computer manufacturers are taking the 'green' path and many governments have plans to reduce energy-consumption, co2 emissions and polution, people (including me) are becoming aware of the fact (mostly cost-driven) that if they reduce their energy-consumption they slow down the polution-rate and might save some extra bucks they can spend on other things.
Now, enough of the 'preaching', the story above has put me to develop a energy-meter for my own house, so that I could see what my consumption and know what the costs are. Now this all isn't new, there are commercially available items for this, but now you can do it with your asus. I also know, you could go out and by a commercial power meter, but they are mostly the ones you have to put between the devices you want to measure. The method described here will allow you to measure all consumption of your house it's components. Besides that, if you're like me: Where's the fun in buying ready-made stuff if you can do it yourself. I have created this meter about half year ago, It has been running since. Right now, the database houses 180.000+ records and is about 15mb in size. So about 35mb of data per year gives an exact and detailed overview of every minute's energy consumption.
Prerequisites:
- Asus WL500xx series router (with 2 usb ports available, one for interfacing with the velleman board, second for storage)
- Have a running installation of MySQL database on the asus
- Have a working installation of cron (task scheduler)
- Have a working installation of a webserver with php enabled (I use lighttpd)
- Velleman K8055 USB interface board (http://www.velleman.be/ot/en/product/view/?id=351346)
- 2 LDR's (Light dependant resistors)
- 2 1k resistors
- 5v ac/dc adapter (power-brick, taken from a mobile phone or something else)
- electricity-meter in your house with LED indication ('digital' ones, which let a LED give a pulse for energy consumption. There also might be a LED
- (soldering iron, solder, flux, time, patience, yadda..yadda..yadda)
Theory:
You need an an electricity meter which somehow indicates that energy is being consumed, and, if you have a double tarif from your energy-supplier, an
indication about what the current tarif is. My particular energy-meter in the house is equiped with 3 leds. 2 LED's are for an indication of the tarif, the third one is a 'pulse' indication which indicates enery is being consumed. Now, most electricity meters state clearly what the 'unit' for the pulse is. Like mine, it states that it indicates '800 pulses per KW'. With this knowledge I know, that everytime the pulse-led blinks 1.25 watts of energy is actually consumed. If I put this along a timeline, and I count the 'pulses in a minute' I know that watts/minute consumed. If you multiply this by 60 (minutes in a full hour) you get the energy consumed measured in KW/H (as this is the most common indication about energy-consumption). Now, you could go and sit in front of your energy meter all day and count the 'blinking leds' and know your consumption. Chances are that you're not going to waste your time on this, so lets put togheter some components which can actually measure (or detect) the consuption and log this into a database and use this data.
In the story above I mentioned 'counting of the pulses' and 'putting things along a timeline'. This is where the Velleman K8055 board and Asus router gets into the picture. The K8055 board is equiped with digital and analogue inputs and outputs. Besides that on 2 of the digital inputs it has a 16 bit counter that we can use. Sweet. This is exactly what we need. If we can make a circuit wich can detect the pulses and send these to the K8055 board, we're in business. If we then let the Asus router read out the values from the K8055 every minute we have detailed information about 'how much pulses were counted in the last minute' and 'which tarif is active right now' we gather information which provides the data for rendering reports about the energy consumption, costs etc.etc.
How it works:
- 5v of the ac/dc adapter goes to the circuit above which consists of the 2 LDR's and 2 resistors. It depends on the resistance of the LDR's if current is passed trough the Velleman K8055 board.
The output of the circuit described above is connected to the K8055 its digital inputs. - Sensor E-meter is connected to input 1 of the velleman board (which has a counter)
- Sensor E-meter tarif is connected to input 3 of the velleman board (which is the first which doesn't have a counter)
The K8055 board only 'detects' if in input is 'hi' or 'lo'. Besides that, on the inputs on which a counter is active the Velleman itself counts the number of times the input has changed its state (it counts the pulses of the led).
While the K8055 board is also connected to the Asus wl500xx router its values can be read with a library installed on the Asus. Running a script every minute which uses the library and reads out the asus values and store these into a mysql database gives us information about the consumption. What you do with this data is all up to you. I've included 3 graphics which uses the data from the database to create a graph of the energy consumption.
How to do it yourself:
Hardware:
- get a K8055 usb-interface board and make sure it works by using the test buttons on the board. (there is a test application on the supplied cd
- build the circuit which is provided in this thread.
- Connect the output of the pulse LDR to the input no:1 on the K8055 board and place the LDR in front of the pulse LED on your meter
- Connect the output of the tarif LDR to the input no:3 on the K8055 board and place this LDR in front of the LOW tarif LED on your meter
- Connect the ground of the sensor (0) to the ground of the velleman board
(if you want, you can test again on your pc. to see that the couter is counting and the tarif is detected) Now that you're are familiar with the circuit and how it works, lets setup the asus router.
Asus Router:
first, let's create the database on the mysql server, open a session to the asus and execute the following command:
(where obviously MYSQLPASSWORD is your mysql password)
Code:
mysql -uroot -pMYSQLPASSWORD
An 'mysql' prompt will return.. please enter the following command to create the database:
Code:
CREATE DATABASE VellemanK8055;
Now switch the console to use the newly created database:
Execute the following command to create the table: tblEnergyMeter
Code:
CREATE TABLE `tblEnergyMeter` (
`dbrowid` int(11) NOT NULL auto_increment,
`datetime` timestamp NULL default NULL,
`MeterValue_1` decimal(8,4) default NULL,
`MeterValue_2` decimal(8,4) default NULL,
`CurrentMeter` char(1) default NULL,
`WattsPerMinute` decimal(4,2) default NULL,
`KiloWattsPerHour` decimal(5,4) default NULL,
`CostperHour` decimal(4,3) default NULL,
`MeasurementTimeInSeconds` int(8) NOT NULL default '0',
PRIMARY KEY (`dbrowid`),
KEY `IX_TimeStamp` (`datetime`),
KEY `IX_MV1` (`MeterValue_1`),
KEY `IX_MV2` (`MeterValue_2`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Execute the following command to create the table: tblEnergyMeterDailyTotals
Code:
CREATE TABLE `tblEnergyMeterDailyTotals` (
`dbrowid` int(11) NOT NULL auto_increment,
`date` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
`Total_MeterValue_1` decimal(8,4) NOT NULL default '0.0000',
`Total_MeterValue_2` decimal(8,4) NOT NULL default '0.0000',
`Cost_Total_MeterValue_1` decimal(4,3) NOT NULL default '0.000',
`Cost_Total_MeterValue_2` decimal(4,3) NOT NULL default '0.000',
PRIMARY KEY (`dbrowid`),
KEY `IX_DATE` (`date`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Execute the following command to create the table: tblEnergyMeterSettings
Code:
CREATE TABLE `tblEnergyMeterSettings` (
`settingID` int(11) NOT NULL auto_increment,
`settingName` varchar(64) NOT NULL default '',
`settingValue` varchar(32) NOT NULL default '',
PRIMARY KEY (`settingID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Execute the following command to create the table: tblEnergyTarifs
Code:
CREATE TABLE `tblEnergyTarifs` (
`TarifEMeter_1` decimal(5,4) NOT NULL default '0.0000',
`TarifEMeter_2` decimal(5,4) NOT NULL default '0.0000',
`TarifGas` decimal(5,4) NOT NULL default '0.0000',
`ValidUntil` date default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Execute the following command to create the table: tblHardwareCounter
Code:
CREATE TABLE `tblHardwareCounter` (
`counter1_Velleman` int(11) default NULL,
`counter2_Velleman` int(11) default NULL,
`EM_Tarif_1` decimal(9,5) default NULL,
`EM_Tarif_2` decimal(9,5) default NULL,
`GasCounter` decimal(9,5) NOT NULL default '0.00000',
`UpdateTimestamp` timestamp NULL default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Read on in the next post to continue