How to Connect a Push Button to Arduino: Pull-up, Pull-down and Debounce
How do you connect a push button to Arduino? The inside of a 4-leg button, pull-up and pull-down resistors, INPUT_PULLUP, debounce and an example that toggles an LED.
A button is the simplest part for bringing a user's touch into an Arduino project. Pressed, it joins two contacts; released, it separates them. Simple as it looks, wired wrongly it reads random values or counts one press several times. In this guide we cover how to connect and read a button correctly.

Inside a 4-leg button
The 6×6 mm tactile button you'll use most on a breadboard has 4 legs but only 2 connection points: opposite leg pairs are already connected inside. Pressing the button joins the two pairs. If you seat the button across the center channel of the breadboard, each pair lands in separate rows and the right orientation is easy.
Why do you need a pull-up or pull-down resistor?
When the button isn't pressed, the Arduino's input pin isn't connected to anything; this is called a floating input. Such a pin picks up electrical noise and reads random HIGH or LOW values. The fix is to pull the pin to a fixed level through a resistor:
| Method | Wiring | Not pressed | Pressed |
|---|---|---|---|
| Pull-down | 10 kΩ pin → GND, button pin → 5V | LOW | HIGH |
| Pull-up (external) | 10 kΩ pin → 5V, button pin → GND | HIGH | LOW |
| INPUT_PULLUP (internal) | Button pin → GND, no resistor needed | HIGH | LOW |
The most practical way is pinMode(pin, INPUT_PULLUP): the Arduino's internal resistor of about 20–50 kΩ is enabled and you just connect the button between the pin and GND. The only difference is that the logic is inverted: a press reads LOW.
Debounce: why does one press count several times?
The moment the button's metal contacts touch, they vibrate for a few milliseconds and the circuit opens and closes many times. Because the Arduino reads so fast, it can see one press as 3–5 presses. This is called contact bounce. To fix it in software, new changes are ignored for about 50 ms after the last change.
1const int BUTTON_PIN = 2; // buton pin ile GND arasında / button between pin and GND
2const int LED_PIN = 13; // karttaki LED / onboard LED
3
4bool ledOn = false;
5int lastReading = HIGH;
6int stableState = HIGH;
7unsigned long lastChange = 0;
8
9void setup() {
10 pinMode(BUTTON_PIN, INPUT_PULLUP); // dahili pull-up / internal pull-up
11 pinMode(LED_PIN, OUTPUT);
12}
13
14void loop() {
15 int reading = digitalRead(BUTTON_PIN);
16 if (reading != lastReading) lastChange = millis(); // değişti / changed
17 if (millis() - lastChange > 50 && reading != stableState) {
18 stableState = reading; // 50 ms kararlı / stable for 50 ms
19 if (stableState == LOW) { // basıldı / pressed
20 ledOn = !ledOn; // LED'i değiştir / toggle LED
21 digitalWrite(LED_PIN, ledOn ? HIGH : LOW);
22 }
23 }
24 lastReading = reading;
25}This code toggles the LED once per press; holding the button doesn't keep toggling it. Because it uses millis() instead of delay(), the loop never waits and can do other jobs at the same time.
Common mistakes
- Inserting the button the wrong way: if you use an already-connected pair of legs, the button always reads as pressed. Turn it 90°.
- Not using a resistor: without a pull-up or pull-down the reading changes randomly.
- Expecting the wrong logic with INPUT_PULLUP: a press reads LOW, not HIGH; write your conditions accordingly.
- Using a long delay() for debounce: the program can't do anything during that time; timing with millis() is better.
- Using pins 34–39 on an ESP32: these pins have no internal pull-up; add an external resistor or pick another pin.
To place the button and resistor correctly on a breadboard, see What Is a Breadboard?, and to understand pull-up resistor values, What Is a Resistor?.
Frequently asked questions
What resistor do I need for a button?
10 kΩ is standard for a pull-up or pull-down. With INPUT_PULLUP you don't need an external resistor at all.
Why does the button read LOW when pressed?
With INPUT_PULLUP or an external pull-up, the pin is normally HIGH; the button connects it to GND, so it reads LOW when pressed. That's the expected behavior.
How long should the debounce time be?
20–50 ms is enough for most buttons. Old or low-quality buttons may need 80–100 ms.
How do I read several buttons?
Connect each button to its own pin and set them all to INPUT_PULLUP. For many buttons, use a keypad or read them on a single analog pin with different resistors.
Projects to build after reading this
See all projects
LED Control with a Push Button (Push)
Just like a doorbell: the light stays on as long as you press, and goes off when you let go.

Toggle an LED with a Button (On/Off)
Press the button once and the light comes on, press it again and it goes off, just like the light switch in your room.

Simple Piano with Buzzer and Button
Build your own little piano with eight buttons. Each button is one note, from low to high: do, re, mi, fa, sol, la, ti and high do.

Counter with 7-Segment Display and Buttons
A simple counter with three buttons: press one and the digit on the display goes up by one, press another and it goes down by one, and the third sends it back to zero.

ESP32 LED Control with Push Button (Push)
The LED lights up when the button is pressed and turns off when released. Shows how the ESP32's digital input pin and internal pull-up resistor are used. The INPUT_PULLUP mode eliminates the need for an external resistor.

ESP32 LED Control with Pushbutton (Toggle)
Each time the button is pressed the state of the LED changes: if it is on it turns off, if it is off it turns on. Classic toggle pattern. With debounce we clean up the mechanical noise of the pushbutton to ensure a single toggle with a single press.

Raspberry Pi Pico Button Toggle LED
Button + LED — next level! Unlike the basic button project, there is no need to hold the button. Press and release → LED on. Press and release again → LED off (toggle). Same circuit (LED GP14, Button GP2), but big code difference. Learn edge detection (capturing the 1→0 falling moment), state tracking, debounce (mechanical bounce filter). MicroPython's led.toggle() swaps state in one line. Foundation of all interactive button projects (mode switcher, IRQ, double-click).

Raspberry Pi Pico Button Debounce: IRQ vs Software Polling
If one press of a button made your code count 3-4 times, the culprit is contact bounce: the button's metal contacts open and close many times within microseconds as they touch! In this project we count the same button in 2 different ways and compare them side by side in Serial: RAW polling (catches the bounce and miscounts) and IRQ + software debounce (counts correctly).
More articles
BlueGrays app
Build this circuit step by step on your phone
Wiring diagram, code and parts list on one screen. 500+ Arduino, ESP32, ESP8266, Pico, mBot and micro:bit projects ready to build.
Scan with your phone
Point your camera at the code and your phone's app store opens.
or open the store

