2018 Energy Meter

Summary:

I had an old fashioned power meter with the spinning disk but wanted to get my power usage into Cacti.
I fashioned this cheap sensor and it worked ike a charm.
You can find this information with images, video and 3D files on my Thingiverse.

Components used:

Arduino Nano V3
BTE16-18 IR Reflection sensor
10µF capacitor
3D printed sensor case (Thingiverse)

Connections:

Sensor->Arduino
VCC -> 5V
GND -> GND
OUT -> Pin D2

RST of the arduino is bridged to GND with a 10µF capacitor to prevent the Arduino from resetting when a serial conection is established (this works on a Nano V3 but different methods apply to other Arduinos). You MUST pull this capacitor if you want to upload code to the Arduino.

The IR will reflect off the plastic housing of the meter and it will be impossible to callibrate if you do not isolate the IR emitter. I just made a small tube out of some electrical tape that fits just around the emitter an sits flush against the plastic window; this fixed all callibration issues.

The sensor should be set up to look at the shiny side of the spinning disk. When the black stripe comes by it wil trigger the sensor (='tick'). The arduino will keep track of the ticks and the count can be read throught the USB serial interface of the Arduino. After connecting, issue command 'c' (count) to read the current count or 'd' (delta ... seemed logical at the time) to read the current count and reset the counter.

Shell code to check current tick count only:

#!/bin/sh
echo 'c' > /dev/ttyUSB0
ticks=$(head -n 1 /dev/ttyUSB0)
echo "ticks:$ticks"

Shell code to read current tick count and reset the counter:

#!/bin/sh
echo 'd' > /dev/ttyUSB0
ticks=$(head -n 1 /dev/ttyUSB0)
echo "ticks:$ticks"

Arduino code for Arduino Nano V3:

int buttonPin = 2;
volatile int buttonCounter = 0;
int buttonState = 0;
int inByte = 0;

void countButtonPresses();

void setup(){
pinMode(buttonPin, INPUT);
Serial.begin(9600);
buttonState=digitalRead(buttonPin);
attachInterrupt(0,countButtonPresses,FALLING);
}

void loop(){
while(Serial.available()==0){}
inByte = Serial.read();
switch (inByte)
{
case 99:
Serial.println(buttonCounter);
break;
case 100:
Serial.println(buttonCounter);
buttonCounter = 0;
break;
}
}

void countButtonPresses()
{
buttonCounter++;
}

You can also find this information on Thingivierse.

Carousel imageCarousel imageCarousel imageCarousel imageCarousel imageCarousel imageCarousel imageCarousel imageCarousel imageCarousel image