I'm having the classic debouncing headache with the Arduino. The switch is meant to turn an led on and off. So if I use a toggle button (SPDT) would it still bounce? Maybe it won't since it not a push button. How much more would it cost to use toggle? It's just that it's a project I've been asked to do for my local Fabrication lab.

  • 1
    \$\begingroup\$ Most switches will bounce: tactile, toggle, rotary etc. Get used to it. I wonder if rubber keypads are better in this respect? Maybe someone can comment on that. \$\endgroup\$
    – Armandas
    Sep 19, 2012 at 10:48
  • 1
    \$\begingroup\$ I'm not clear on the issue here - is there some reason you can't just debounce the switch in firmware? \$\endgroup\$
    – Oli Glaser
    Sep 19, 2012 at 11:01
  • 1
    \$\begingroup\$ When you say you're having a headache, what exactly are the symptoms? If it's just controlling an LED, can you actually tell that the switch is bouncing ? \$\endgroup\$ Sep 19, 2012 at 11:40

3 Answers 3


Most SPST switch or pushbutton will bounce, because there are only two states: contact closed (for instance low level) and contact open (high level through a pull-up resistor). This may seem obvious, but it's that hesitation when opening/closing that causes the bounce; just once is enough to make a toggle not work.

You can debounce the switch with a capacitor, but since you're using it with a microcontroller it's cheaper to do it in software. I usually have a 32 ms (software) timer for keypad scans, and only accept a state change if it persists during two consecutive scans. That means you'll have a delay of maximum 64 ms, but since the button will be manually operated you won't notice such a short delay.

You mention a SPDT button, and that's the best solution if you want to do it in hardware.

But frankly, I see no reason for not doing it in software, and you'll have much more choice in SPST buttons than in SPDT buttons.

If you want a button which hardly bounces then I can recommend the Alps SKQG tact switch

which with the devices I tested had an initial bounce of less than 10 ns.

  • \$\begingroup\$ As a good rule of thumb, unless you're triggering an interrupt, software debounce is fine. If you are driving an interrupt, sometimes software debounce is fine, sometimes not. \$\endgroup\$ Sep 19, 2012 at 11:11
  • \$\begingroup\$ Also, debounce with a cap requires some thought if it happens to be on a pin used by the programming port, as I found out the hard way. \$\endgroup\$ Sep 19, 2012 at 11:14
  • \$\begingroup\$ The thing I do with buttons is setting a timer which interrupts and auto repeat every x mS depending on my needs. When it interrupt, it sets a bit somewhere. This bit is tested in the main loop. If the bit is set, it means enough time have passed and so I know it's time to get the buttons status, process them and clear the bit. The advantage of this method is that the ISR just sets a bit. This is the fastest interrupt you can make. \$\endgroup\$
    – CopperMaze
    Sep 1, 2014 at 19:41

The Ganssle Group has written a very comprehensive report called A Guide to Debouncing. In it, the author, Jack Ganssle, took 18 different switches and pressed each 300 times. He recorded the results using an MSO scope to look at the actual analog signal as well as the digital representation to simulate what a microcontroller would see.

analog versus digital

All the switches tested bounced differently. Some types worse than others. Some not at all. But even identical switches of the same type bounced differently.

Identical switches were not particularly identical. Two matching pairs were tested; each twin differed from its brother by a factor of two.

So, if you're going to use a switch, having to debounce it is just a fact of life.

Part 2 of the guide gives numerous methods to handle the debouncing problem.

The Set-Reset (SR) latch mentioned by stevenvh is discussed:

SR debouncer

As well as the cheaper RC method:

RC debouncer

But, as mentioned in the comments and other answers, if you have a microcontroller, you're probably better off doing it in software. The guide also discusses various algorithms that can be implemented.

From a very simple ISR:

simple ISR

To an expanded version to handle a whole port of switches:

multiple switch ISR

Give the whole report a good read. How to debounce a switch is a skill well worth having and one you will use throughout your career.

  • \$\begingroup\$ haha it's all good because am not electronics engineer. Am a trainee electrician who is very much interested in electronics because he didn't get a chance to do it at school. But you do have a point though I must admit. \$\endgroup\$
    – Ageis
    Sep 19, 2012 at 18:29
  • \$\begingroup\$ +1 for the Ganssle shout-out! His paper on switch debouncing is REALLY good. \$\endgroup\$ Sep 19, 2012 at 20:42

All dry* mechanical contact switches bounce. The amount varies.A SPDT switch is almost always break before make so staes are low / opemn / high.

You CAN get make before break SPDT switches but even those can bounce.

*Mercury wetting is used in some relays to improve current handling capability. I think these may tend to be bounce free but I have had no real-world experience of them, and they are rare and mercury wetting will not be found in had operated switches.

Software will debounce anything - time taken depending on how ultra-violent and ongoing the bounce is.

A Schmitt triggered input with suitable RC delay usually does a good job of debouncing. Bounce is possible if delay is too short relative to worst case boune times.

  • \$\begingroup\$ I think mercury wetting is no longer used because of RoHS. \$\endgroup\$
    – amadeus
    Sep 29, 2013 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.