The Bwired electricity monitor

Forum about Questions, discussions and announcements regarding the Bwired website owned by Pieter Knuvers

The Bwired electricity monitor

Postby Bwired » Wed Nov 29, 2006 11:39 pm

For years I was thinking about the possibility to measure the electricity consumption automatically. I was lucky to have a electricity meter with a very interesting features, this meter had a very bright red LED in the middle which flashes 480 times when 1 kW (1000 Watt) is consumed. This got me thinking about building an interface to pick up the flashes with a sensor and feeding this into my 1-wire network.
Image
Thanks to JON00 I found out that it was possible to use a Infra-red barrier mini-kits from Velleman. (Type MK120) This kit consisted of a transmitter and receiver PCB complete with components and for under 15 euros. With some minor modification, this is the perfect interface for this project.

The receiver side of this kit consists of a photo diode which is designed to pick up infra-red from the transmitter. Looking at the circuit diagram, the transmitter LED's were actually being fed from a a stable oscillator. The modulated IR Light was then being received by the photo diode on the receiver PCB and fed into various op amp stages to integrate and compare the voltages obtained. This voltage (when the photo diode received IR light) was compared to a reference voltage and would switch the final opto to an OFF state. This would then switch to an ON state when no IR illumination was received. For its intended application, the buzzer & LED would activate when somebody crossed the beam.

The output needed to be reversed, this can be done by modifying the receiver PCB and swapping the + and - inputs of the last comparator. This involved 4 cuts on the PCB and a few bits of wire to transpose the connections. It would be nice to leave the LED as an indicator, just use a BC547 transistor and a 1K resistor as the switch interface. Don't install the buzzer its of no use anymore!

The 1-wire interface is the easy part. One of the common uses for 1-Wire is for temperature and weather related devices. Several weather instruments require counters to input the data this includes rain gauges & lightning detectors. A company called AAG http://www.aagelectronica.com/aag in Mexico manufacture 1-Wire counter boards (TAI8585) at minimal cost. These consist of a battery backed DS2423 1-Wire counter, so no counts are lost. The TAI8585 can be triggered by a reed relay or other shorting method.

These two boards, the receiver part of the Velleman MK120 kit and the AAG 1-Wire TAI8585 Pulse counter are the main interface. Of course you need a standard 1-Wire receiver to connect it all trough RS232 to your computer. I use the Log08 1-Wire interface from MIDON http://www.midondesign.com for all my 1-Wire devices.

Technical construction
One of the most important parts of this project was how to mount the photo diode in front of the pulsed LED without obstructing the meter too much and raised eyebrows from the meter reader. A 8mm wide length of sheet metal was bent in to a Z formation with a 5.5mm hole drilled at the end and another 4mm for mounting. To keep interference out use a screened cable to connect the photo diode to the MK120.
Image
Photo Diode mounted in front of LED meter

The Velleman receiver kit is constructed apart from the photo diode and the buzzer. R11 was replaced from a 470K to 15K to reduce the sensitivity of the circuit. As mentioned before, you need to swap pins 9 and 10 on the LM324 IC. As the pads on the PCB could get dislodged, cutting of the board was done after construction with a sharp knife. A meter set to low resistance was then used to confirm that the tracks had been completely cut. Wire links as shown were then added to complete the modification.

Image
Red lines indicate where the PCB tracks need to be cut

Image
Wire links required to complete the modification

Connection of the photo diode and 9V battery to the circuit confirmed correct operation with the on-board LED flashing at the same time as the meter LED.

Just mount the AAG 1-wire counter on top of the Velleman PCB using the mounting holes designed for the battery holder. Use two 25mm M3 pan head screws to mount the 1-Wire AAG board. A 1K resistor is soldered to R12 and pushed through the large hole nearby so that it appeared at the top of board. The collector and emitter of the BC547 are then soldered directly to the 1-wire board (across the reed relay) and the other end of the 1K resistor soldered to the base of the transistor. Finally a ground/common wire is connected from the Velleman PCB to the 1-Wire PCB.

Image
Solder connection of the 1K resistor and ground connection

Image
Circuit diagram of transistor interface

Image
Detailed view of interface and 1-wire board mounted on Velleman PCB

Image
Another view of finished interface

All that's needed is to mount the finished interface within a plastic box. Just add two sockets, one for the photo transistor and the other for the 1-Wire & 12V supply. Solder the LED and mount it on the outside of the box.

Image
Completed interface mounted in plastic box

Possible technical problems
If you encounter some problems reading the flashes it could be the circuit is to sensitive. The sensitivity of the circuit by adjusted by replacing R11 on the Velleman PCB. For instance to make it less sensitive you can replace R11 with 15K instead of 470K. Also use a screened cable for the photo-transistor and keep the distance as short as possible.

Software
With the Bwired Home Control System, which is my general control system I read all the data from the 1-Wire network. Keep in mind that the 1-Wire TAI8585 only can count to 65535 before it resets to zero. As there are 480 flashes in 1 KWh the pulse counter will reset after counting 136KWh. I read the 1-Wire once every minute and store about 60 readings in one hour. This way I can keep track of the current energy consumption and also usage for the hole day. All the data is saved into a SQL server called MYSQL. With my home Control System I can start all kinds of events based on the energy consumption. For example, if there is no one at home and the energy consumption is higher then 0.500 KWh I get a message on my cell phone.

Benefits
We were consuming about 10.000 kW a year, way to much! For years I was thinking about a plan to measure the electricity automatically. With this little project I was able to reduce the electricity from 10.000 KW to 6635 KW. Because of the accurate and minute by minute reading of electricity consumption I became much more aware of it all. I found out that I was consuming 0.600 kWh at night! With simple things like unplugging adapters of my cellular (GSM) and standby of video an television I was able to reduce the power to around 0.380kWh. I also discovered that there are a lot of power adapters which consume a lot of energy, I use now power switching adapters which have a high performance and so consume much less energy. The energy monitor is automatically plugged in my Home Control System which adds nice little features like for example getting a mail on your cell phone GSM) if the power consumption is higher then 0.500kWh and there is no one at home. I really think automating your home or business and controlling your energy can help to reduce the worlds growing energy problem.
http://www.bwired.nl Online Home, Domotica, Home Automation. Weblog. http://blog.bwired.nl
User avatar
Bwired
Administrator
Administrator
 
Posts: 5315
Joined: March 2006
Location: Netherlands

The Bwired electricity monitor

Postby Spawn32 » Mon Dec 04, 2006 10:44 am

Hi Pieter,
I have managed to get my own Electricity logger ruining and storing everything to a sql DB, works very nice, the setup i very similar to yours, but could you help me out with with one of you nice Chardirector / asp setups ? i am not very good with asp, try-ed you phone asp example but that one seem to have a fault in it, saying expected "end" or something.. would be very nice if you could post the asp for "Chart Electricity used last 24 hours", that would give me a very good start to work from..

Best Regards
Morten (Norway)
Spawn32
Starting Member
Starting Member
 
Posts: 10
Joined: December 2006
Location:

The Bwired electricity monitor

Postby Bwired » Mon Dec 04, 2006 9:39 pm

Ok that a good thing, put the link on this site when it's working.

this is the code, look good at the examples that come with chart director ans then combine them with the code below.
Good luck Pieter

Code: Select all
<%
Set cd = CreateObject("ChartDirector.API")
strSQL = "SELECT datum, sum(wattage)/1000, DAYNAME(datum) FROM energie GROUP BY datum ORDER BY datum DESC LIMIT 30"
Set rs = my_conn.Execute(strSQL)
Set dbTable = cd.DBTable(rs)
   
'Create a XYChart of size 420 pixels x 240 pixels
Set c = cd.XYChart(420, 114)
Call c.setBackground(&H02061d)
Call c.setPlotArea(35, 7, 380, 90,,,,&H666666)

set layer = c.addBarLayer(dbTable.getCol(1))
Call layer.setBorderColor(cd.SameAsMainColor, 1)
Call Layer.addExtraField(dbTable.getCol(0))
Call Layer.addExtraField(dbTable.getCol(2))
call c.yaxis().setRounding(1, 1)

Call c.yAxis().setcolors(&H666666,&H666666,&H666666,&H666666)
Call c.xAxis().setcolors(&H666666,&H666666,&H666666,&H666666)
Call c.xAxis().setLabelStyle(, 7.5, &Hc0cccc)
Call c.yAxis().setLabelStyle(, 7.5, &Hc0cccc)

'lijntje rechts yaxis
Call c.yAxis2().setTitle(" ")
Call c.yAxis2().setcolors(&H665665,&H656666,&Hc05500,&H656566)

'Set the x-axis labels using the supplied labels
Call c.xAxis().setLabels(dbTable.getCol(0),"{value|d}")

'Set the x-axis width to 1 pixels
Call c.xAxis().setWidth(1)

'Set the y-axis width to 1 pixels
Call c.yAxis().setWidth(1)

'Create the image and save it in a session variable
chart1URL = c.makeSession(Session, "chart11")

'Create an image map for the chart
imageMap = c.getHTMLImageMap("", "", toolTip)
%>
<img src="chartimage.asp?<%=chart1URL%>" border="0" usemap="#map11">
<map name="map11"><%=imageMap%></map><%set cd = nothing
set c = nothing%>
http://www.bwired.nl Online Home, Domotica, Home Automation. Weblog. http://blog.bwired.nl
User avatar
Bwired
Administrator
Administrator
 
Posts: 5315
Joined: March 2006
Location: Netherlands

The Bwired electricity monitor

Postby Spawn32 » Tue Dec 05, 2006 1:03 am

Thanks for you help :)
but i am having some problems, i get this error on the asp code you gave me, and on most / all of the examples in the chartdirector as well:

Script error: Type mismatchchart1URL = c.makeSession(Session, "chart11")
'Create an image map for the chart
imageMap = c.getHTMLImageMap("", "", toolTip)

this is what the script look likes now :

Code: Select all
<%
Set my_conn = createobject("ADODB.Connection")
my_conn.open = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=energi;UID=root;PWD=xxxx;OPTION=35;"
Set Rs = CreateObject("ADODB.Recordset")

Set cd = CreateObject("ChartDirector.API")
strSQL = "SELECT Date, sum(Count), DAYNAME(Date) FROM energi_monitor GROUP BY Date ORDER BY Date DESC LIMIT 30"
Set rs = my_conn.Execute(strSQL)
Set dbTable = cd.DBTable(rs)

'Create a XYChart of size 420 pixels x 240 pixels
Set c = cd.XYChart(420, 114)
Call c.setBackground(&H02061d)
Call c.setPlotArea(35, 7, 380, 90,,,,&H666666)

set layer = c.addBarLayer(dbTable.getCol(1))
Call layer.setBorderColor(cd.SameAsMainColor, 1)
Call Layer.addExtraField(dbTable.getCol(0))
Call Layer.addExtraField(dbTable.getCol(2))
call c.yaxis().setRounding(1, 1)

Call c.yAxis().setcolors(&H666666,&H666666,&H666666,&H666666)
Call c.xAxis().setcolors(&H666666,&H666666,&H666666,&H666666)
Call c.xAxis().setLabelStyle(, 7.5, &Hc0cccc)
Call c.yAxis().setLabelStyle(, 7.5, &Hc0cccc)

'lijntje rechts yaxis
Call c.yAxis2().setTitle(" ")
Call c.yAxis2().setcolors(&H665665,&H656666,&Hc05500,&H656566)

'Set the x-axis labels using the supplied labels
Call c.xAxis().setLabels(dbTable.getCol(0),"{value|d}")

'Set the x-axis width to 1 pixels
Call c.xAxis().setWidth(1)

'Set the y-axis width to 1 pixels
Call c.yAxis().setWidth(1)

'Create the image and save it in a session variable
chart1URL = c.makeSession(Session, "chart11")

'Create an image map for the chart
imageMap = c.getHTMLImageMap("", "", toolTip)
%>
<img src="chartimage.asp?<%=chart1URL%>" border="0" usemap="#map11">
<map name="map11"><%=imageMap%></map><%set cd = nothing
set c = nothing%>

Regards
Morten
Spawn32
Starting Member
Starting Member
 
Posts: 10
Joined: December 2006
Location:

The Bwired electricity monitor

Postby Bwired » Thu Dec 07, 2006 12:25 am

try adding tooltip = "" above the imagemap=c.gethtml...... line
and you need the chartimage.asp form the samples in your directory.
Most of the examples are based on this file. Look at the working of the examples and where the files needs to be placed.
Pieter
User avatar
Bwired
Administrator
Administrator
 
Posts: 5315
Joined: March 2006
Location: Netherlands

The Bwired electricity monitor

Postby Spawn32 » Thu Dec 07, 2006 2:07 am

Hi, diden help :(
your chartimage.asp dosen exist in Chard. 3.1 or 4.1, but found out from the demos that you probaly mean getchart.asp ?

anyway, i am now trying to get the aspdemo : dbdemo3 to work, but get the same error in that one :

Script error:
Type mismatch chart1URL = c.makeSession(Session, "chart1")
' Create an image map for the chart
imageMap = c.getHTMLImageMap("dbdemo3a.asp", "", "title='{xLabel}: US$ {value|0}M'")

could the problem here be that i am trying to run the asp's in the Homseer2 webserver ? the problem line seems to be the one with Session in it ?

Nice of you to help me Pieter
Spawn32
Starting Member
Starting Member
 
Posts: 10
Joined: December 2006
Location:

The Bwired electricity monitor

Postby Bwired » Thu Dec 07, 2006 9:01 am

OK right...
I think I changed that filename....so long ago for me.
This is whats in my chartimage.asp

<%
Response.ContentType = "image/png"
Response.BinaryWrite Session(Request("img"))
%>

The directory "Image" needs to be there I think..... but I don't see the program writing anything in it!
The Other thing I think that you need to run this code in a normal webserver. Do know if it run in the Homeseer webserver? So let's say your homeseer webserver is on port 81 and your IIS webserver is on port 80. Try this option as well.
Hope it will help you now.
Pieter
User avatar
Bwired
Administrator
Administrator
 
Posts: 5315
Joined: March 2006
Location: Netherlands

The Bwired electricity monitor

Postby Spawn32 » Thu Dec 07, 2006 11:57 pm

That fixed it, HS2 can't handle the Session stuff, IIS works, chartdirecor demos works as well, tested your asp with my DB but in only makes a chart going from 0 and up to 150, with no data :(

i save the my data 1 timepr min and divide the count with 250 before saving to "Count" in my DB (250 pulses = 1 Kw on my reader) i also save time and date.
Count the looks like this for one min : 0,026 (example).
So the modified asp file i pasted here should work then, shoulden it ?

Regards
Morten
Spawn32
Starting Member
Starting Member
 
Posts: 10
Joined: December 2006
Location:

The Bwired electricity monitor

Postby Bwired » Fri Dec 08, 2006 12:17 am

That's good!
I also log my energy once a minute, but I'm not adding a record every minute in the database. I create one record for every hour but update it every minute. So the above query gives a record for every day and puts it in the chart. You can simple adjust it to give chart for every hour.
Experiment with it and I think it will work

Pieter Knuvers
www.bwired.nl Online House in the netherlands. Domotica, Home Automation.
User avatar
Bwired
Administrator
Administrator
 
Posts: 5315
Joined: March 2006
Location: Netherlands

The Bwired electricity monitor

Postby Spawn32 » Fri Dec 08, 2006 12:24 am

Ok, thanks
after i wrote my last reply, that chart updated to a new scale from 0 to 3 and showing a width bar going from 0 to 2, so that must be the current day (yes i know, using to mutch Kw's here :) but i thout with that sql setup that i would show more than just the current day ?

strSQL = "SELECT Date, sum(Count), DAYNAME(Date) FROM energi_monitor GROUP BY Date ORDER BY Date DESC LIMIT 30"


probaly need to learn som more sql here :)

Morten
Spawn32
Starting Member
Starting Member
 
Posts: 10
Joined: December 2006
Location:

The Bwired electricity monitor

Postby Spawn32 » Tue Dec 12, 2006 10:29 am

Still having problem here Pieter, hope you have som time to help me out :)

i get this chart after 5 days of loging:

Image

as you see it only shows 3 bars for 5 days, very odd, in the DB there is correct data for all days :/

i use this to get the data :
strSQL = "SELECT Date, sum(Count), DAYNAME(Date) FROM energi_monitor GROUP BY Date ORDER BY Date DESC LIMIT 30"

Date is stored as : 07.12.2006 in th DB, is that a problem ?

Regards
Morten
Spawn32
Starting Member
Starting Member
 
Posts: 10
Joined: December 2006
Location:

The Bwired electricity monitor

Postby Bwired » Tue Dec 12, 2006 11:25 am

Did you try the select with a Mysql client like mysql manager and check the result. You should get 5 records summarized, check all the fields you use in the asp file. also check the type of the fields.
User avatar
Bwired
Administrator
Administrator
 
Posts: 5315
Joined: March 2006
Location: Netherlands

The Bwired electricity monitor

Postby Spawn32 » Tue Dec 12, 2006 12:43 pm

Ok, will try with sql manager when i get back from work.

my fields are set up like this Time = time, Date = date, Count = char and is typical like : 0,026

this should be correct ?

Regards
Morten
Spawn32
Starting Member
Starting Member
 
Posts: 10
Joined: December 2006
Location:

The Bwired electricity monitor

Postby Willem4ever » Tue Dec 12, 2006 1:27 pm

Still having problem here Pieter, hope you have som time to help me out :)

i get this chart after 5 days of loging:
as you see it only shows 3 bars for 5 days, very odd, in the DB there is correct data for all days :/

i use this to get the data :
strSQL = "SELECT Date, sum(Count), DAYNAME(Date) FROM energi_monitor GROUP BY Date ORDER BY Date DESC LIMIT 30"

Date is stored as : 07.12.2006 in th DB, is that a problem ?


I assume you are using mySQL, but it should be the same for all SQL databases.

DATE
'YYYY-MM-DD'
The permitted range is from '1000-01-01' to '9999-12-31'. Can be assigned as a string or numeric.
TIME
'HH:MM:SS'
Range from '-838:59:59' to '838:59:59'. Can be assigned as a string or numeric.
DATETIME
'YYYY-MM-DD HH:MM:SS'
Range from '1000-01-01 00:00:00' to '9999-12-31 23:59:59'. Can be assigned as a string or numeric.
YEAR
'YYYY'

The default is for the YEAR to be 4-digits - YEAR(4), but a 2-digit year is also permitted - YEAR(2), although there should be no reason to want to use it. In 4-digit format, YEAR's can range from 1901 to 2155. In 2-digit format, YEAR's can range from 70 (1970) to 69 (2069). Can be assigned as a string or numeric.

TIMESTAMP
'YYYY-MM-DD HH:SS:MM'
Range from '1970-01-01 00:00:00' to partway through the year 2037.

You can use NOW() to get and store the current time in your databases;
e.g. INSERT INTO energy VALUES(NOW(), ....);


Willem.
User avatar
Willem4ever
Global Moderator
Global Moderator
 
Posts: 804
Joined: October 2006
Location: Uithoorn / Netherlands

The Bwired electricity monitor

Postby Spawn32 » Tue Dec 12, 2006 1:35 pm

Thansk for you help Willem,
i read in the mysql doc about that, and even tryed with Now(), but when i check my sql db afterwards, it still shows the data in the order as : dd mm yyyy, maybe this is just win xp fooling me ? i will delete the whole db and start from scratch, and only use Now() for storing the date,


Regards

Morten
Spawn32
Starting Member
Starting Member
 
Posts: 10
Joined: December 2006
Location:

Next

Return to Bwired Forum

Who is online

Users browsing this forum: No registered users and 1 guest