Power consumption measuring unit
From uCtrl.net
PCMU, driven by AVR ATTiny2313.
Contents |
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
Parts list
Sensor not included.
| Quantity | Supplier | Part number | Description |
| 1 | Elfa | 73-646-56 | AVR-RISC, ATtiny2313-20PI |
| 1 | Elfa | 50-197-24 | Plastic Enclosure (1591 FL), 112x62x31mm fixed install. |
| 1 | Elfa | 44-055-51 | D-Sub soldering cups, 9 pin male |
| 2 | Elfa | 44-055-02 | D-Sub soldering cups, 9 pin female |
| 1 | Elfa | 48-161-38 | DIL socket, 16-pin, 7,62mm |
| 1 | Elfa | 48-161-53 | DIL socket, 20-pin, 7,62mm |
| 1 | Elfa | 48-161-04 | DIL socket, 6-pin, 7,62mm |
| 1 | Elfa | 70-003-91 | Rectifier diode, 1A 400V, 1N4004 |
| 2 | Elfa | 48-884-18 | Unthreaded round spacer, 3mm, Ø6mm |
| 1 | Komplett | 100316 | D-sub cable, pin-to-pin 5m, 9-pin male-female |
| 1 | Elfa | 75-612-36 | Heatsink, 27.3 K/W, 19mm, attachable, TO220 |
| 1 | Elfa | 67-008-01 | Aluminium electrolytic capacitor, 10uF 25V |
| 5 | Elfa | 67-013-12 | Aluminium electrolytic capacitor, 1uF 50V |
| 2 | Elfa | 67-008-68 | Aluminium electrolytic capacitor, 47uF 25V |
| 2 | Elfa | 65-851-94 | Ceramic Disc Capacitor, 1 nF 100V |
| 2 | Elfa | 65-550-64 | Foil capacitor, 0,01uF |
| 1 | Elfa | 48-396-76 | Laboratory card, 100x160mm (1/5) |
| 1 | Elfa | 75-006-14 | LED 3mm, Green, 2.1V, 20mA, 3.5mcd, 38° |
| 1 | Elfa | 75-006-22 | LED 3mm, Yellow, 2.0V, 20mA, 2.5mcd, 38° |
| 2 | LED1.de | 803053 | LED holder 3mm, Black plastic |
| 1 | Elfa | 73-023-26 | MAX232, CPE RSR232double |
| 1 | Elfa | 60-106-15 | Carbon film resistor 5% 1/4W, 10 K |
| 4 | Elfa | 60-104-33 | Carbon film resistor 5% 1/4W, 330 Ohm |
| 1 | Elfa | 60-105-73 | Carbon film resistor 5% 1/4W, 4,7 K |
| 1 | Elfa | 75-355-94 | Optocoupler DIL-6, CNY17F-3 |
| 9 | Elfa | 43-708-05 | Socket connector 2,54, 1×36, female |
| 6 | Elfa | 43-708-13 | Socket connector 2,54, 2×36, female |
| 17 | Elfa | 43-702-19 | Straight pin header 2,54, 1×36, PCB |
| 2 | Elfa | 43-704-33 | Straight pin header 2,54, 2×36, PCB |
| 1 | Elfa | 33-167-18 | Fuse 5x20 mm, 400 mA, quick-acting |
| 1 | Elfa | 33-150-17 | Open fuse holder, PCB, 5x20mm |
| 1 | Elfa | 33-150-25 | Open fuse holder, PCB, Protective cover |
| 1 | Elfa | 73-095-60 | Voltage regulator +5V, L78S05CV 2.0A |
| 1 | Elfa | 42-051-26 | Power Jack, panel, 2,5mm |
| 1 | Elfa | 42-049-05 | Power Jack, plug-in, 2,5mm |
Images
Schematic drawing
Resources
Source code
The program is written in basic, using Bascom-AVR.
'-------------------------------------------------------------- ' 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