Interrupts fire Randomly

Troubles with interrupts firing inadvertantly on Duemilanove.

For the standard attachInterrupt() for pins 2,3 they work pretty good but the interrupts fire just by touching the wire connected to the pin. Sometimes they fire if I wiggle the USB connection. Should I be pulling these to ground somehow when the switch is open to these pins?

Here is a snippet of my code and interrupt handlers. I have 0.5 second of debounce software in the ISR. Pretty standard stuff…

In Setup()
/*

  • Setup I/O Pins
    */
    pinMode(lane3Pin, INPUT); // Setup digital pin 8 for input - ISR Lane 3
    pinMode(lane4Pin, INPUT); // Setup digital pin 7 for input - ISR Lane 4

/* External interrupts for lanes 1 and 2 are simple rising edge interrupts. */
attachInterrupt(0, processLane1, RISING);
attachInterrupt(1, processLane2, RISING);

If you want reliable results, avoid floating pins at all cost.
Depending on how your switches are wired, use pull up or pull down resistors.

You could also enable the internal pull up resistors with a:-

digitalWrite(2,HIGH);
digitalWrite(3,HIGH);

After you have initilised them as inputs.

Thanks for the feedback. I just added pullup resistors and changed my interrupts from rising to falling edges.

Floating pins are engraved invitations for Murphy to make you sad and very, very confused. No pins, even unused ones, should ever be left floating.

No pins, even unused ones, should ever be left floating.

Well that might be a little extreme advice. AVR I/O pins default to be input pins after a power up or reset condition. I’ve read many a sketch on this forum and I don’t recall any that set all unused pins to output mode or that enabled all the internal pull-ups of all the unused input pins.

Lefty

While I would agree with rocketgeek about unused pins in a strictly engineering context I think for what we are doing here it is a little bit of an overkill. Sure a floating input will pick up noise and transfer that noise into the rest of the processor’s circuitry but in the context of what we are doing then it is not going to affect the performance of a system. It is certainly not going to make the difference between something working and not working. It might affect long term reliability, that is once a year it might make an application malfunction once but maybe not even that often.
In discrete logic gates then floating unused pins can affect the propagation delay in a gate but we are not dependent on those parameters here, that can be left to high speed systems. Most of what we do is restricted to 16MHz and nowadays this is not considered a particularly high frequency.

So my take is yes but no. However, in this case where the pins were actually doing something defiantly they should not be left floating.