Interrupt routine triggers on falling edge

Hey everyone,

I'm just starting to mess around with interrupts, so I wrote this routine to toggle an LED with a SPDT limit switch. The N.C. contact is wired to ground, N.O. to +5v, and the common contact to pin 2.

The issue: Even though the interrupt routine is set to trigger on the rising edge, I notice that if I hold the limit switch for a second (to HIGH) and let go (to LOW), it still triggers the interrupt. What do you think the problem is? Do you think the switch still bounces when I let go as well? The program works how it should if I briefly tap the limit switch.

Edit: I found the problem, the code used an internal pullup resistor while I also had a 10k resistor wired to the +5V side of the limit switch. Removed the internal pullup resistor, and now the programming is functioning as it should.

const byte ledPin = 9;
const byte interruptPin = 2;
volatile byte state = LOW;
unsigned int count, 
             sum,  
             debounceStart, 
             debounceFinish = 0,
             debounceTime = 200;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), tBlink, RISING);
  Serial.begin(9600);
}

void loop() {
  digitalWrite(ledPin, state);
}

//variables [count] and [sum] are for troubleshooting purposes
void tBlink() {
  debounceStart = millis();
  sum = debounceStart - debounceFinish;

  //execute if it has been 200 ms since last change of sate (debouncing method)
  if(sum >= debounceTime) 
  { 
    state = !state;
    count++;
    Serial.println();
    Serial.print(count);
    Serial.print(" - ");
    Serial.print(sum);
    debounceFinish = millis();
  }  
}

Since you have declared the pin as INPUT_PULLUP, there is an internal resistor tied to that pin. When you let go of your switch, it is making contact with the N.C. side which you say is ground. All mechanical switches bounce, so as this contact is made, it most likely is briefly not making contact and the internal pullup pulls it high which gives your pin a RISING edge.

Bottom line: You need to debounce your pin

blh64:
Since you have declared the pin as INPUT_PULLUP, there is an internal resistor tied to that pin. When you let go of your switch, it is making contact with the N.C. side which you say is ground. All mechanical switches bounce, so as this contact is made, it most likely is briefly not making contact and the internal pullup pulls it high which gives your pin a RISING edge.

Bottom line: You need to debounce your pin

You are correct. Problem solved, Thanks!