From the course: Arduino: Prototyping

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Button debouncing

Button debouncing

- [Instructor] You're probably pretty familiar with how switches work on the Arduino. Depending on the circuit, pushing, pulling, or flipping the switch makes it go high or low. In reality, though, switches usually don't transition cleanly from one state to the other. On both the down and up motion, there can actually be a small bounce before the switch settles on its value. The settling time can be anywhere from a millisecond or less to several hundred milliseconds, depending on your switch. When your sketch loop runs slowly, and you only check your switch once every few hundred milliseconds, switch bouncing may not be much of a problem, but now that our prototype is using non-blocking code, the loop is running very fast, and it may read the switch value multiple times during the transition. This could result in several presses while the switch settles rather than a single one. To deal with this, we can use a technique…

Contents