Interrupt Problem

Hello Guys,
I have a problem with my arduino project. I have a interrupt on a button. If i click the button it should count as one click. But sometimes it recognizes a click as 2 or even 3 clicks.

Do anybody know this problem?

A button is not a good interrupt source because of contact bounce. You could add debouncing code to get around this, but the thing is that usually it's not necessary to use interrupts for a button. You are likely better off just polling the pin in your loop() function. Yes, this requires that you don't use blocking code like delay(), but that's a skill you need to learn anyway.

As a general rule: you don't need interrupts.

That definitely applies to buttons. It's hard to imagine a situation where an interrupt is needed for recording a button press, and quite impossible to have this make sense (as it implies the underlying program is done very poorly).

Examine the ‘change in state’ example that comes with the IDE.

While your at it, read this discussion about several things at same time:

https://forum.arduino.cc/index.php?topic=223286.0

netzpirat:
Hello Guys,
I have a problem with my arduino project. I have a interrupt on a button. If i click the button it should count as one click. But sometimes it recognizes a click as 2 or even 3 clicks.

Do anybody know this problem?

Yes, you are thinking the button operates once, but it bounces on timescales from microseconds to milliseconds in highly unpredictable ways. The interrupt handler is seeing this.

You have to debounce the signal in software, or else add a debouncing circuit in hardware. Try searching "debounce arduino"

Hii there,

This is taking place because of bouncing. Bouncing is seen in mechanical switches and to solve suh problem you need to debounce the signal. this can be done both by hardware and software. In hardware you can use the chip 74C14N, this should solve your problem.

That chip will not help at all to stop bounce.

A simple 1-100 nF cap in parallel with the switch, will.

You can use an RC filter and then a 74HC14 schmitt-trigger for rock solid debouncing, but a schmitt-trigger on its own is pointless.

The Arduino pins have a small amount of hysteresis so that a capacitor will often work, but its frankly
simpler to debounce in software, fewer parts are required.