Advertisements

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.

Advertisements

  1. #1 by madbodger on 2016-08-29 - 09:33

    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.

    • #2 by Ed on 2016-08-29 - 11:29

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

  2. #3 by solaandjin on 2016-08-29 - 12:01

    • #4 by Ed on 2016-08-29 - 13:13

      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…