Arduino Button Debouncing
I recently built a little Arduino project that used one of these giant arcade buttons for input and I had a terrible time getting it to register properly. I was able to make it work in the end, but I thought I might document the process I used here for when I inevitably have to do it again and forget what I did.
What is Debouncing, Anyway?
Whenever an electrical contact is closed in a switch, button, relay, or other electromechanical device, it bounces between connected and disconnected a few times before it settles. This is true of lots of switches that don't need to be debounced, like lightswitches in your house, but a microcontroller sees all of these little ons and offs whereas your eyes don't. This is a problem because if we only expect one switching event per button press we might see some unusual behavior if there's more than one due to contact bounce.