Skip to content
Free Delivery on Orders Above Rs 999/- Pan-India
Cash on Delivery Available for Orders above Rs.500/- and Upto Rs 3000/-
SAVE more when you BUY more. Upto 30% Off on BULK PURCHASE
GST Invoices for Your Business
Dedicated Technical Support Team
Safely Delivering Genuine Products PAN INDIA

How to Wire a Push Button to Arduino: Pull-Up Resistors

How to Wire a Push Button to Arduino: Pull-Up Resistors
-
Written By - Robocraze -
📅 Updated on 09 Oct 2026
✨ Summarize with AI
✅ Prompt copied

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

HIGH

Pressed

LOW

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

  1. buttonPin = 2 assigns the button to digital pin 2.

  2. pinMode(buttonPin, INPUT_PULLUP) enables the internal pull-up resistor.

  3. digitalRead(buttonPin) reads the button state.

  4. LOW means the button is pressed.

  5. HIGH means the button is released.

  6. 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 INPUT_PULLUP or an appropriate external resistor

Connecting the button to the wrong legs

The circuit may remain open

Place a four-leg button across the breadboard centre gap

Treating LOW as pressed with normal pull-down wiring

The logic is reversed

With INPUT_PULLUP, pressed is LOW

Connecting the button to 5V while using INPUT_PULLUP

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

Excerpt

Learn how to wire a push button to Arduino using INPUT_PULLUP. Follow the wiring diagram, working code, pull-up vs pull-down explanation, and debounce tips.
Prev Post
Next Post

Leave a comment

Please note, comments need to be approved before they are published.

Thanks for subscribing!

This email has been registered!

Shop the look

Choose Options

Edit Option
Back In Stock Notification
Compare
Product SKU Description Collection Availability Product Type Other Details

Choose Options

this is just a warning
Login
Shopping Cart
0 items
FREE SHIPPING!
₹100 OFF
₹200 OFF
₹999
₹2500
₹4900
WhatsApp Chat Chat