Hello, I have a rain gauge simply acting like a switch. My circuit is composed by a pull down resistor and a capacitor for avoid bouncing. The problem is that sometimes (not always) the interrupt rutine service (attached on RISING) is called more than once.
Here's what I can see on serial monitor, I print the pin value and " I am in the IRS," when the isr is called. The code doesn't do anything more.
000000000000000000000 I am in the IRS, I am in the IRS, 1111111111111111000000000000000000
Do you think my swith is bouncing but I cannot see on serial monitor something like 00010111100 becuse the ISR is running?
Using an RC low pass circuit means you are generating an analog waveform, not a logic signal. You need a schmidt trigger too (Arduino pins have a little hysteresis and may be good enough, its hard to know). What's the R, what's the C, how are they wired up?
ok, it's true I am generating an analog wave but the interrupt pin are digital so they can only "say": I am under or over a value. I can solve the problem in this software way:
void my_interrupt_handler()
{
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
// If interrupts come faster than 200ms, assume it's a bounce and ignore
if (interrupt_time - last_interrupt_time > 200)
{
Serial.println("I am in the IRS");
}
last_interrupt_time = interrupt_time;
}
but I cannot anyway understand why 2 ISR are called if printing values I have never changing state like 000010111000 but always non bouncing like 0000011111111100000000...
Thanks for your suggestion
volatile int vaschetteSvuotate=0;
void setup()
{
Serial.begin(9600);
sei();
}
void loop()
{
attachInterrupt(1, my_interrupt_handler, RISING );
Serial.println(vaschetteSvuotate );
delay(3000);
}
void my_interrupt_handler()
{
vaschetteSvuotate++;
Serial.println("I am in the IRS");
}
This code do not provide any debouncing system. But my question is: why two interrupts occour if the sequence from digital pin rises only once? May be the 0s and 1s that make the ISR happen are not printed on serial monitor but they're lost?