so the meter - if you look closely you can see the gear that rotates in the attached pictures
I used the RadioShack Emitter and Detector #276-0142 set and some pvc and duck tape (to block the sun light and to hold it in place)
here's the meat of the code
because it get's full on sun I use filters for the cross over counts
#define gas_analog_in 4
#define gas_digital_out 4
void loop()
{
GasLoop();
}
unsigned long gasTotalCount = 0;
unsigned long gasLastCount = 0;
unsigned long gasG5count = 0;
unsigned long gaslastMillis = millis();
unsigned long gasReading = 0;
unsigned long gasReadingMax = 0;
unsigned long gasReadingMin = 1023;
unsigned int gasFlag = 0;
unsigned long gasTripHigh = 0;
unsigned long gasTripLow = 1023;
int gasTripOffset = 75;
float gasFilterL = 900;
float gasFilterOff = 900;
int gasOut = HIGH;
void GasLoop()
{
gasReading = analogRead(gas_analog_in);
gasFilterL += .01 * (gasReading-gasFilterL);
gasReading = gasFilterL;
if(gasReading>gasReadingMax) gasReadingMax = gasReading;
if(gasReading<gasReadingMin) gasReadingMin = gasReading;
if(gasReading<gasTripLow) {
gasFlag = 1;
} else if (gasFlag == 1 && gasReading>gasTripHigh) {
gasFlag =0;
gasTotalCount++;
}
if (gasReading>gasTripHigh) {
gasTripLow = gasReading - gasTripOffset;
gasTripHigh = gasReading;
}
if (gasReading<gasTripLow) {
gasTripHigh = gasReading + gasTripOffset;
gasTripLow = gasReading;
}
}
over the last two months I had:
Billed | MyReading | %Delta |
---|---|---|
12 | 11.88 | 1.00% |
11 | 11.16 | -1.45% |
so over the 2 months -0.17% (seeing they bill at 1ccf and I measure at .01)
I'm happy with results so far!