User Tools

Site Tools


blink_electricity_monitor

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
blink_electricity_monitor [2021/04/05 22:17]
admin
blink_electricity_monitor [2021/04/05 22:32]
admin
Line 2: Line 2:
 **Summary:​** Using an [[https://​www.arduino.cc/​|Ardunio]] to count the number of blinks from the electricity meter in the flat and eventually convert that into live and historical electricity usage graphs. **Summary:​** Using an [[https://​www.arduino.cc/​|Ardunio]] to count the number of blinks from the electricity meter in the flat and eventually convert that into live and historical electricity usage graphs.
  
 +==== The hardware ====
 It's a really simple circuit, basically connect the light dependent resitor (LDR) to the 5V pin on the Ardunio, then connect back to GND with a 100k resistor between the LDR and GND.  Connect the analog data pin (A0) just after the LDR. It's a really simple circuit, basically connect the light dependent resitor (LDR) to the 5V pin on the Ardunio, then connect back to GND with a 100k resistor between the LDR and GND.  Connect the analog data pin (A0) just after the LDR.
  
-{{:​pasted:​20210405-172619.png}}+{{:​pasted:​20210405-172619.png|Generated with https://​www.circuit-diagram.org/​editor/​}}
  
 Then, upload some code to the Ardunio to count the number of blinks. ​ You might need to tweak the delay and the sensorValue depending on your electric meter LED type.  These values worked for me. Then, upload some code to the Ardunio to count the number of blinks. ​ You might need to tweak the delay and the sensorValue depending on your electric meter LED type.  These values worked for me.
  
-<​code>​+<​code ​python>
 int sensorPin = A0; int sensorPin = A0;
 int sensorValue = 0; int sensorValue = 0;
Line 30: Line 31:
 } }
 </​code>​ </​code>​
- 
-On the Linux box it's plugged into, you need to set the baud rate, then just use cat to read directly from the Ardunio (I also use ts to prefix each line with a timestamp): 
-<code bash> 
-stty -F /​dev/​ttyASM0 9600 
-cat /​dev/​ttyASM0 | ts > /​tmp/​electric_meter.log 
-</​code>​ 
- 
-If you have any issues with permissions,​ make sure your user is in the dialout group. 
  
 That gives me the data in the format: That gives me the data in the format:
Line 48: Line 41:
 Apr 05 22:07:47 975 (3792) Apr 05 22:07:47 975 (3792)
 </​code>​ </​code>​
 +
 +To dump this to a file, on the Linux box (or Raspberry Pi) the Arduino is plugged into, you need to use ''​stty''​ set the baud rate, then just use cat to read directly from the Ardunio (I also use ''​ts''​ to prefix each line with a timestamp):
 +<code bash>
 +stty -F /​dev/​ttyASM0 9600
 +cat /​dev/​ttyASM0 | ts > /​tmp/​electric_meter.log
 +</​code>​
 +
 +If you have any issues with permissions,​ make sure your user is in the dialout group.
 +
  
 Each line corresponds with a blink of the meter, so I use some PHP to basically count the number of lines in a minute (this runs in a cron job every minute): Each line corresponds with a blink of the meter, so I use some PHP to basically count the number of lines in a minute (this runs in a cron job every minute):
blink_electricity_monitor.txt ยท Last modified: 2022/01/06 03:08 by admin