Book a Consultation
10 Aug 2026 • 95 views

Arduino Tutorial: Reading a Push Button (Digital Input)

Blinking an LED is output — this tutorial covers the other half: input. You'll wire a push button and read its state to control an LED, which is the pattern behind nearly every physical interface an Arduino project uses.


Beginner

⌛ 20 min

🔧 What You'll Need

  • Arduino Uno
  • 1x push button (4-pin tactile)
  • Breadboard
  • 3x jumper wires

Wiring the Circuit

Place the button across the breadboard's center gap. Connect one leg to digital pin 2, and the diagonally opposite leg to GND. We'll use Arduino's internal pull-up resistor in software, so no external resistor is needed for the button itself. Wire an LED to pin 8 with a 220Ω resistor to GND, same as the Blink tutorial.

The Code

const int buttonPin = 2;
const int ledPin = 8;

void setup() {
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  int buttonState = digitalRead(buttonPin);

  if (buttonState == LOW) {   // pressed, because of INPUT_PULLUP
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  }
}

INPUT_PULLUP uses the Arduino's built-in resistor to hold the pin HIGH by default, so no external pull-up resistor is needed. This means the logic is inverted from what you might expect: the button reads LOW when pressed (connecting the pin to GND) and HIGH when released. The sketch checks for LOW to detect a press.

💡 Tip: Real buttons "bounce" — they register several rapid on/off transitions in the first few milliseconds of a press. For a simple LED-follows-button circuit like this it doesn't matter, but for counting button presses accurately, you'll want to add debounce logic in a later project.

Troubleshooting

  • LED is always on: You likely wired the button so it's always connecting the pin to GND — check it's actually across the breadboard's center gap, not shorted.
  • Nothing happens when pressed: Confirm you're using INPUT_PULLUP and checking for LOW, not HIGH.
  • Button feels stuck: Most 4-pin tactile buttons have two legs internally connected as pairs — make sure you're using legs from opposite pairs, not the same pair.

You now have both halves of the Arduino I/O model: reading input, writing output. The next tutorial adds a third dimension — reading a range of values instead of just on/off.

Share:
Get new projects in your inbox
One email a month. No spam — just new project drops and workshop dates.