Summary
Connect a push button to Arduino without an external resistor using INPUT_PULLUP. Learn the wiring, active-low logic, working code, toggle control, and button debouncing.
To wire a push button to an Arduino, connect one terminal of the button to a digital input pin and the other to GND. Configure the pin using INPUT_PULLUP to enable the Arduino's internal pull-up resistor. The input reads HIGH when the button is released and LOW when pressed, so you do not need an external pull-up resistor for this basic circuit.
What You Need
-
Arduino Uno or another compatible Arduino board
-
Momentary push button
-
Breadboard
-
Jumper wires
-
LED and a 220–330Ω resistor (optional, for visual feedback)
You can use the Arduino's built-in LED on many boards, so an external LED is not necessary for the first test.
How a Push Button Works
A push button is a momentary switch. Pressing it connects its contacts; releasing it disconnects them.
The Arduino reads the button through a digital input pin. However, when a switch is open and the input has no defined electrical connection, the pin can float. A floating input may randomly read HIGH or LOW, even when the button has not been pressed.
A pull-up or pull-down resistor gives the input a defined default state.
Push Button Wiring Diagram
Basic circuit: one side of the push button connects to digital pin 2, and the other connects to GND.
Connection table
|
Push button connection |
Arduino Uno |
|---|---|
|
One terminal |
Digital pin 2 |
|
Opposite terminal |
GND |
|
Internal pull-up |
Enabled in code |
Most four-legged tactile push buttons have two pairs of internally connected legs. Place the button across the breadboard's centre gap so pressing it connects the two sides.
Important: With INPUT_PULLUP, connect the button to GND, not 5V. The internal resistor keeps the input HIGH while the button is released.
What Is INPUT_PULLUP in Arduino?
INPUT_PULLUP configures a digital input and enables the Arduino's internal pull-up resistor.
The resistor keeps the input at a defined HIGH state when the button is not pressed. Pressing the button connects the input to GND, making it LOW.
|
Button state |
Pin 2 reading |
|---|---|
|
Released |
|
|
Pressed |
|
This is called active-low logic: the input becomes LOW when the button is activated.
Pull-up vs pull-down resistor
Pull-up resistor
-
Holds the input HIGH by default.
-
Button connects the input to GND.
-
Commonly used with Arduino's
INPUT_PULLUP. -
No external resistor is needed for the basic circuit.
Pull-down resistor
-
Holds the input LOW by default.
-
Button connects the input to the positive logic supply.
-
Usually requires an external resistor.
-
Pressing the button makes the input HIGH.
For a beginner Arduino project, INPUT_PULLUP is usually the simplest option because it avoids an external pull-up or pull-down resistor.
Arduino Push Button Code
This sketch reads a button on digital pin 2 and turns the built-in LED on when the button is pressed.
const int buttonPin = 2;
const int ledPin = LED_BUILTIN;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
}
void loop() {
int buttonState = digitalRead(buttonPin);
if (buttonState == LOW) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}
How the code works
-
buttonPin = 2assigns the button to digital pin 2. -
pinMode(buttonPin, INPUT_PULLUP)enables the internal pull-up resistor. -
digitalRead(buttonPin)reads the button state. -
LOWmeans the button is pressed. -
HIGHmeans the button is released. -
digitalWrite()switches the built-in LED accordingly.
Upload the sketch, press the button, and check whether the LED turns on. Release the button to turn it off.
How to Make a Push Button Toggle an LED
The previous example keeps the LED on only while the button is pressed. A toggle button changes the LED state with each press and keeps that state until the next press.
For example:
-
First press: LED turns ON.
-
Second press: LED turns OFF.
-
Third press: LED turns ON again.
Use this sketch:
const int buttonPin = 2;
const int ledPin = LED_BUILTIN;
int ledState = LOW;
int lastButtonState = HIGH;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, ledState);
}
void loop() {
int buttonState = digitalRead(buttonPin);
// Detect a new press
if (buttonState == LOW && lastButtonState == HIGH) {
ledState = !ledState;
digitalWrite(ledPin, ledState);
delay(50); // Simple debounce
}
lastButtonState = buttonState;
}
This is a simple demonstration. The short delay helps reduce repeated triggers, but a more robust implementation should debounce both press and release transitions.
Why Does an Arduino Push Button Trigger Multiple Times?
A physical button does not always make one clean electrical transition. Its metal contacts can briefly bounce between open and closed states when pressed or released.
The Arduino may interpret these rapid transitions as multiple presses. This is called switch bounce.
Symptoms include:
-
An LED toggles twice after one press.
-
A counter skips numbers.
-
A program registers several button events.
-
A menu jumps past an option.
How to debounce a push button
For a simple project, a short delay can help:
delay(50);
However, delays can pause other program tasks. For projects that need responsive controls, use a non-blocking debounce method based on millis() or a suitable button-handling library.
Debouncing is especially important for toggle switches, counters, menu controls, and any program where one press should produce exactly one event.
Common Push Button Wiring Mistakes
|
Mistake |
Why it causes problems |
Fix |
|---|---|---|
|
Forgetting the pull-up or pull-down |
The input may float |
Use |
|
Connecting the button to the wrong legs |
The circuit may remain open |
Place a four-leg button across the breadboard centre gap |
|
Treating |
The logic is reversed |
With |
|
Connecting the button to 5V while using |
The wiring does not match the intended circuit |
Connect the button between the input pin and GND |
|
Ignoring switch bounce |
One press may register multiple times |
Add debounce handling |
|
Forgetting the ground connection |
The input may not behave as expected |
Check the button's connection to Arduino GND |