Wire a push-button to a digital pin and make your board respond — your first taste of input, and the basis of every interactive project.

So far your board has only talked. Now it’s going to listen. Reading a button is the simplest form of input, and it introduces one idea that trips up almost every beginner: a pin that isn’t held at a known voltage will read random noise. The fix is a pull-down resistor.

What you’ll need

i

Why the pull-down resistor?

When the button is open, the input pin is “floating” and reads HIGH or LOW at random. The 10 kΩ resistor gently ties the pin to ground, so it reads a steady LOW until the button connects it to 5 V.

Wire it up

  1. Place the button across the breadboard’s centre channel.
  2. Connect one side of the button to 5 V.
  3. Connect the other side to digital pin 2.
  4. From that same pin-2 row, add the 10 kΩ resistor down to GND.
  5. Double-check: pin 2 sees 5 V only while pressed, GND otherwise.
  6. Power up and upload the sketch below.

The code

const int BUTTON = 2;
const int LED = 13;

void setup() {
  pinMode(BUTTON, INPUT);
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int pressed = digitalRead(BUTTON);
  digitalWrite(LED, pressed);   // LED mirrors the button
  Serial.println(pressed);
}

Press the button and the on-board LED follows. Open the Serial Monitor and you’ll see it flip between 0 and 1 in real time.

!

Seeing flickers? That’s bounce.

Mechanical contacts “bounce” for a few milliseconds, registering several presses from one push. The fix is debouncing — ignore changes that happen within ~50 ms of the last one. A great next guide.

Swap INPUT for INPUT_PULLUP and you can even skip the external resistor — the board has one built in. Once your project reacts to a button, sensors are the same idea with richer data.