Tomdee

3Apr/111

Monitoring a gas meter using an Arduino and a simple photo transistor

If I could turn my heating on and off remotely, I wanted a way of knowing whether it had worked! This lead me to come up with a way of reading my gas meter. This also has the nice side effect that I can monitor my usage long term and see if the extra control I have over my boiler gives me any reduction in my gas usage.

As far as I know, there aren't any off the shelf solutions for monitoring gas usage. Some meters come with a pulse counter though often these are sealed off and not intended for actual use. Some meters come with a silvered digit on the mechanical read out which makes spotting that digit easier. Unfortunatly, my gas meter has neither of these features.

The hardware

I chose to use the SY-CR102 from Maplin as it was both cheap and easy to get hold of. It provides both an infrared LED and phototransistor on a single package. I had to email them to get the data sheet, but it's not particularly informative - SY-CR102 datasheet.

I soldered it onto a little vero board following the circuit used here. I hooked it up to my arduino and used a bungee cord to fix the whole thing to my gas meter.

SY-CR102 attached to gas meter using bungee cord

SY-CR102 attached to gas meter using bungee cord

This arrangement allows me to see each revolution of the little red dial, which gives a resolution down to about 1/2 a penny of gas.

The software

Ideally, the SY-CR102 would give me a strong enough reading that I could use it to drive on of the interupt pins on the arduino. It gets nowhere near this unforunately. The signal drifts up and down with temperature and and the reading, which has a range of 0-1023, only changes by about 15 when the needle goes under the sensor. Thankfully, the needle never moves that fast so a software based polling approach is feasible.

The shape of the signal is a little odd, dipping as the needle approaching the sensor, then rising to a sharp peak before dipping again as the needle moves past the sensor. I found that the best approach to recording the passing of the needle was to tracking the highest value seen, and count a "tick" when the value fell by a certain threshold amount. This allows me to ignore the slow drift caused by temperature changes and to ignore the first dip as the needle nears the sensor whilst still counting the larger drop from the central peak.

To avoid having to fix a threshold amount, I record an array of threshold and can then choose which one to use on the fly. This allows me to monitor the values and choose a stable region. Moving the sensor, means I have to reperform this manual calibration.

 

void checkGasSensors()
{
  int reading = analogRead(analogInPinGas); 

  for (int ii = 5; ii < MAXDROP ; ii++)
  {
    if (reading > newHigh[ii])
    {
      newHigh[ii] = reading;
    }

    if ((newHigh[ii] - reading) > ii)
    {
      // A big fall has been witnessed
      gasTicks[ii]++;
      newHigh[ii] = reading;
    }
  }
}

 

Comments (1) Trackbacks (0)
  1. Why do you need the vero board? Sorry this is a bit of a noob question – I thought you could use the Arduino to poll?
    Thanks, Duncan


Leave a comment

No trackbacks yet.