I am trying to figure out how to prevent registering false interrupts for a tipping rain gauge.
I have a weather meter kit (SENS-15901) connected to a Photon Weather Shield (DEV-13674) with a Particle Photon plugged in. The tipping bucket rain gauge registers an interrupt call every so often. The data is sent through a Particle webhook every 5 minutes to Influxdb. Below shows a 12 hour window of readings received every 5 minutes from influxdb. The large spike at 11:30 can be ignored as that was manual input while removing the reed switch. However, the small, random inputs you see are false triggers. The device is setup on a tripod under a patio cover and no possible rain or moisture going into the rain bucket during the 12 hour window. The readings after the large spike were with the reed switch removed from the case and placed on the support arm to ensure the magnet wasn’t somehow triggering the switch.
I have had the same results using a Particle Boron in place of the Photon (with an adapter plate to match Photon pinout). Once deployed I plan to use the Boron, but to save LTE data for development I’m using the Photon. The weather station is in central California where rain fall is infrequent and most often at a slow precipitation rate. Getting this to register correctly is important as it may not be uncommon to only have 0.011 inch of rainfall in a 5 minute period during a normal light rain event.
Here is the code that reads the Rain pin interrupt:
//===========================================================================
// Rain Gauge
//===========================================================================
int RainPin = D2;
volatile unsigned int rainEventCount;
unsigned int lastRainEvent;
float RainScaleInches = 0.011; // Each pulse is .011 inches of rain
void initializeRainGauge() {
pinMode(RainPin, INPUT_PULLUP);
rainEventCount = 0;
lastRainEvent = 0;
attachInterrupt(RainPin, handleRainEvent, FALLING);
return;
}
void handleRainEvent() {
// Count rain gauge bucket tips as they occur
// Activated by the magnet and reed switch in the rain gauge, attached to input D2
unsigned int timeRainEvent = millis(); // grab current time
// ignore switch-bounce glitches less than 10mS after initial edge
if(timeRainEvent - lastRainEvent < 10) {
return;
}
rainEventCount++; //Increase this interval's amount of rain
lastRainEvent = timeRainEvent; // set up for next event
}
float getAndResetRainInches()
{
float result = RainScaleInches * float(rainEventCount);
rainEventCount = 0;
return result;
}
Is there a way to fix this in software or do I need to create a hardware solution to debounce or filter out the noisy reed switch?