Summary of Debounce an input using Arduino
This article explains how to implement input debouncing using an Arduino, ensuring a button press is registered only once despite potential signal noise. It uses the millis() function to track time intervals for confirming button presses. The circuit includes an LED connected to pin 13 and a pushbutton connected to pin 2 with a 10K resistor to ground. The code toggles the LED state on each valid button press, inverting the logic so the switch reads HIGH when pressed.
Parts used in the Debounce Input Project:
- Arduino Board
- Momentary button or switch
- 10K ohm resistor
- Breadboard
- Hook-up wire
- LED (internal to Arduino on pin 13)
This example demonstrates how to debounce an input, which means checking twice in a short period of time to make sure it’s definitely pressed. Without debouncing, pressing the button once can appear to the code as multiple presses. Makes use of the millis() function to keep track of the time when the button is pressed.
Circuit
image developed using Fritzing. For more circuit examples, see the Fritzing project page
Schematic
Code
The code below is based on Limor Fried’s version of debounce, but the logic is inverted from her example. In her example, the switch returns LOW when closed, and HIGH when open. Here, the switch returns HIGH when pressed and LOW when not pressed.
Debounce
Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There’s
a minimum delay between toggles to debounce the circuit (i.e. to ignore
noise).
The circuit:
* LED attached from pin 13 to ground
* pushbutton attached from pin 2 to +5V
* 10K resistor attached from pin 2 to ground
* Note: On most Arduino boards, there is already an LED on the board
connected to pin 13, so you don’t need any extra components for this example.
Hardware Required
- Arduino Board
- momentary button or switch
- 10K ohm resistor
- breadboard
- hook-up wire
For more detail: Debounce an input using Arduino