Home power consumption measuring unit

From uCtrl
This page is kept for historical interest. It may document projects or methods that are obsolete and/or no longer relevant. The information here is not kept up-to-date.

This module was given to a friend many years ago.
Home power consumption measuring unit complete and connected

Information

You need a light sensor that registers LED flashes from your house power consumption unit. In Norway we have a unit that emits a LED flash every X kW. This sensor connects to the module. The consumption is measured in kW and calculated by counting the number of pulses and divide by 500 (500 pulses pr. kW). The registration will continue as long as the module receives a signal from the light sensor, the used amount can then be read using serial communication from the computer.

Two values are stored, current and present usage. By sending a command to the module the current value can be moved to the previous, thus making it possible to compare periods. Current usage value is deleted when moved to previous. These values are stored in EEPROM every hour, and is used when the module start up from e.g. a power loss. That means that you could lose one hour of monitoring. You can also enter a desired start usage value.

Before any EEPROM values are stored the module will display -1 kW current and previous usage. There can be reset by moving current to previous two times (command 4). Correct EEPROM values will then be stored one hour after first received signal.

Connectors

Power connector

2,5 mm, 9-12V=, positive center.

9-pin Sensor

  • 6 : 5V + out
  • 7 : 5V - out
  • 8 : 5V + sensor in
  • 9 : 5V - sensor in

9-pin RS-232

  • 2 : Transmit
  • 3 : Receive
  • 5 : GND

Communication

Forbruksmaaler v.1.0                                                           
JensenCorp 0704001                                                             
                                                                               
Press 0 for help                                                               
                                                                               
1 - Current usage                                                              
2 - Previous usage                                                             
3 - Enter starting point                                                       
4 - Move current to previous                                                   
                                                                               
Current usage will be deleted! (0 to cancel)                                   
Enter starting point in kW : 100                                               
100 kW saved                                                                   
100 kW current usage (50000 pulses)                                            
100 kW moved to previous                                                       
100 kW previous usage                                                          
0 kW current usage (0 pulses)

Serial settings

Baud
9600
Data bits
8
Parity
None
Stop bits
1

Images

Schematic drawing

Home-power-consumption-measuring-unit-circuit-2qek9q.png

Parts list

Sensor not included.

Qty. Part
1 AVR ATtiny2313-20PU, DIL-20, 20 MHz, 18 I/Os
5 Capacitor, aluminium electrolytic, 1 µF, 50V
1 Capacitor, aluminium electrolytic, 10 µF, 25V
2 Capacitor, aluminium electrolytic, 47 µF, 25V
2 Capacitor, ceramic, 1 nF, 100V
2 Capacitor, metallized polyester foil, 0.01 µF
1 D-sub cable, pin-to-pin 5m, 9-pin male-female
2 D-Sub soldering cups, 9 pin female
1 D-Sub soldering cups, 9 pin male
1 DIL socket, 16-pin, 7.62mm
1 DIL socket, 20-pin, 7.62mm
1 DIL socket, 6-pin, 7.62mm
1 Diode, rectifier, 1 A, 400V, 1N4004
1 Enclosure, plastic (1591 FL), 112x62x31mm, flange
1 Fuse 5x20 mm, 400 mA, fast-acting
1 Fuse holder, open, PCB, 5x20mm
1 Fuse holder, open, PCB, Protective cover
1 Heatsink, 27.3K/W, 19mm, attachable, TO220
1 LED 3mm, Green, 2.1V, 20mA, 3.5mcd, 38°
1 LED 3mm, Yellow, 2.0V, 20mA, 2.5mcd, 38°
2 LED holder 3mm, Black plastic
1 Optocoupler, single, CNY17F-3, DIL-6
32 cm2 PCB, stripboard, 100x160mm, 160cm2
1 Power jack, panel, 2.5mm, plastic housing
1 Power jack, plug-in, 2.5mm
4 Resistor, carbon film, 0.25W, 330 Ω, 5%
1 Resistor, carbon film, 0.25W, 4.7 kΩ, 5%
1 Resistor, carbon film, 0.25W, 10 kΩ, 5%
1 RS232 interface, MAX232CPE, dual
2 Spacer, round unthreaded, 3mm, Ø6mm, Delrin
6 Straight pin header, female, Dual row, 2.54mm
9 Straight pin header, female, Single row, 2.54mm
2 Straight pin header, male, Dual row, 2.54mm
17 Straight pin header, male, Single row, 2.54mm
1 Voltage regulator +5V, 2 A, L78S05CV

Resources

  • MAX202
  • RS-232

Source code

Template:Basic code

 '--------------------------------------------------------------
' Thomas Jensen
'--------------------------------------------------------------
' file: AVR_FORBRUKSMÅLER_v.1.0
' date: 27/04/2007
'--------------------------------------------------------------
$regfile = "attiny2313.dat"
$crystal = 8000000
$baud = 9600
Config Portb.0 = Input
Config Portb.1 = Output
Config Portb.2 = Output


Dim Serialcharwaiting As Byte , Serialchar As Byte
Dim Is_active As Bit , W As Long , Kw As Long
Dim Lifesignal As Integer , Led_timer As Integer
Dim Set_kw As Long , Kw_prev As Long , Pval As Integer
Dim Eeprom As Eram Long , Eeprom2 As Eram Long , Eeprom_timer As Integer

Print "Forbruksmaaler v.1.0"
Print "JensenCorp 0704001"
Print
Print "Press 0 for help"
Print

Kw = Eeprom
W = Eeprom * 500
Kw_prev = Eeprom2

Top:
Serialcharwaiting = Ischarwaiting()

If Serialcharwaiting = 1 Then
   Serialchar = Inkey()
      Goto Myroutine
   End If

Goto Main

Myroutine:
Select Case Serialchar
Case 49
Print Kw ; " kW current usage (" ; W ; " pulses)"
Case 50
Print Kw_prev ; " kW previous usage"
Case 51
Goto Set_value
Case 52
Goto Reset_value
Case 48
Print "1 - Current usage"
Print "2 - Previous usage"
Print "3 - Enter starting point"
Print "4 - Move current to previous"
End Select



Main:
'count
If Pinb.0 = 0 And Is_active = 0 Then
   Is_active = 1
   Incr W
   Kw = W / 500
   Led_timer = 51
   If Eeprom_timer = 0 Then Eeprom_timer = 1801
   End If
If Pinb.0 = 1 Then Is_active = 0

'led_timer
If Led_timer > 0 Then Decr Led_timer
If Led_timer = 50 Then Portb.2 = 1
If Led_timer = 0 Then Portb.2 = 0

'lifesignal
If Lifesignal > 0 Then Decr Lifesignal
If Lifesignal = 500 Then Portb.1 = 1
If Lifesignal = 0 Then
   Portb.1 = 0
   If Eeprom_timer > 0 Then Decr Eeprom_timer
   If Eeprom_timer = 1 Then
      Eeprom = Kw
      Eeprom2 = Kw_prev
      End If
   Lifesignal = 2001
   End If

Waitms 1
Goto Top
End

Set_value:
Print
Print "Current usage will be deleted! (0 to cancel)"
Input "Enter starting point in kW : " , Set_kw
If Set_kw = 0 Then
   Print "Operation aborted"
   Goto Main
   End If
W = Set_kw * 500
Kw = Set_kw
Print Kw ; " kW saved"
Goto Main
End

Reset_value:
Kw_prev = Kw
Kw = 0
W = 0
Print Kw_prev ; " kW moved to previous"
Goto Main
End