Robots Atlas>ROBOTS ATLAS

Arduino for Beginners · Digital Inputs and Outputs

Debouncing — why a button "bounces" and how to fix it

Digital Inputs and Outputs

Introduction

A button's metal contacts do not close cleanly — on a press they repeatedly connect and disconnect the circuit over ~1-20ms. To the Arduino this looks like a burst of presses, so a single press can be counted several times. This lesson explains the mechanism of contact bounce, edge detection (the lastState variable), software debouncing based on delay() (simple but blocking) and millis() (non-blocking, a 20-50ms window), and hardware debouncing (an RC filter, a Schmitt trigger). It also shows why counting presses without debounce gives wrong results and how to trade window length against responsiveness.