Have a strange issue that's got me scratching my head. Any help would be greatly appreciated.
I have a valve that dumps water for 5 minutes every half hour or so. The sketch sends an alarm if the valve doesn't dump within 1 hour. I built in a 10 minute hysteresis using detachInterrupt so that it isn't constantly interrupting for the entire 5 minute dump cycle. It is suppose to attachInterrupt after 10 minutes and wait for the next cycle.
I am using a vibration sensor. I tried 10K and 1K pullup to 5V. Grounding the input and to 5V. I tried rising edge and falling edge.
My problem is that after the interrupt is re-enabled, it runs the ISR and my timer is reloaded.
Trigger the interrupt.
vibration1Timer is loaded with millis correctly.
interrupt is detached correctly.
The first if statement behaves as expected.
When the second if statement becaomes true, it triggers the vibration1() routine even if the switch is hardwired to gnd.
const unsigned long vibrationDelay = 3600000; // Trigger siphon alert after no activity in 1 hour
const unsigned long interruptTimeout = 600000; // Disable interrupt for timeout period while siphon dumps
volatile unsigned long vibration1Timer = 0;
byte vibration1Value;
void setup()
{
attachInterrupt(1, vibration1, FALLING); // Config interrupt for bell siphon vibration sensor
}
void loop()
{
if ((millis() - vibration1Timer) >= vibrationDelay){
vibration1Value = 0;
} else {
vibration1Value = 1;
}
if ((millis() - vibration1Timer) >= interruptTimeout){
attachInterrupt(1, vibration1, FALLING); //doesn't work. Triggers interrupt routine instead.
}
}
void vibration1() {
vibration1Timer = millis();
detachInterrupt(1);
}
The full sketch is quite long and take about 2 seconds to go through the loop. I tried to post but the forum complained I have too many characters. I don't believe any other parts of the sketch would be affecting this operation.