Switch Contact Bounce

An Arduino hairball for an upcoming Digital Machinist column:

Arduino UNO clone - test setup
Arduino UNO clone – test setup

A short program monitors the switch. When it closes, the program reads the analog voltage from the pot and blinks the LED (on Pin 13, so you don’t need an external LED) for that number of milliseconds.

Some diligent rummaging produced a spectacularly bouncy switch (lower trace) with the output pulse (upper trace):

Contact Bounce - Matsuhita - NO 1
Contact Bounce – Matsuhita – NO 1

A longer timebase shows it’s rattling around for nearly half a millisecond:

Contact Bounce - Matsuhita - NO 2
Contact Bounce – Matsuhita – NO 2

The second pulse in the upper trace shows that the code gets around the loop() fast enough to retrigger on the same button push, which is part of the lesson in the column

A midrange timebase:

Contact Bounce - Matsuhita - NO 3
Contact Bounce – Matsuhita – NO 3

You could surely get a few random numbers out of that noise, although the first few bounces seem surprisingly consistent.

4 thoughts on “Switch Contact Bounce

  1. I was just building an interface for a rotary phone and had to debounce the dial pulses. I tried a few debounce libraries, but some had odd requirements that wouldn’t work with my code and others had resource contention with other libraries I was using. I finally just rolled my own dead-simple one.

    1. Back in the day, Strowger switches didn’t care about contact bounce; obviously, you’re using the wrong technology. [evil grin]

    1. Yeesh, that’s seriously overwrought, even by my standards.

      The tradeoff between “fast response” and “not glitchy” seems weighted toward the latter, but even 50 ms of delay makes you wonder if the switch has gone bad. For human-scale timing, reporting the first transition right away, then locking out the switch until things settle down seems to work well.

      The discussions on an old post cover the territory pretty well…

Comments are closed.