I've been trying to capture rising edge of an IR sensor output. This sensor's Vcc connected to Arduino 5V and it has a digital output pin. I've observed the digital output pin on an Oscilloscope. It's not noisy.
When I attach a rising edge interrupt on digital pin 2. It somehow captures both rising and falling edges. This response is the same for when it's set for FALLING or CHANGE.
I've tried code at below both on Arduino Uno and
volatile bool caughtAnInterrupt = false;
void setup() {
Serial.begin (19200);
pinMode(2, INPUT);
attachInterrupt(digitalPinToInterrupt(2), test, RISING);
}
void loop() {
if (caughtAnInterrupt){
Serial.println("Rising edge detected");
caughtAnInterrupt = false;
}
}
void test() {
caughtAnInterrupt = true;
}