Arduino / Beginner

Read a button with just two wires

Use the UNO R3 internal pull-up resistor to get a predictable pressed and released signal without a floating input.

By Harry Avraamides10 October 202625 min activity

Before you start
Complete the breadboard guide and know how to upload a sketch to an Arduino UNO R3.

You will leave with
The built-in LED follows a pushbutton, with readable status in Serial Monitor.

A useful first control is a button that makes the built-in LED light while you hold it. The important idea is a defined resting state. An unconnected input can change unpredictably; an internal pull-up gives this circuit a stable released reading. This untested educational procedure is scoped to the Arduino UNO R3 and an ordinary, unpowered momentary switch.

Materials and the two states

You need an UNO R3, USB cable, breadboard, two jumpers, and a normally open pushbutton. A multimeter helps identify the switch contacts. Do not substitute an illuminated industrial switch or a module with unknown electronics. This circuit has no connection from the button to 5V.

With INPUT_PULLUP, released means HIGH. Pressing the switch joins the input to ground, so pressed means LOW. Those meanings come from the wiring; HIGH does not universally mean “on”. See Arduino’s input pull-up example for the underlying input behaviour.

1. Identify and wire the contacts

  1. Disconnect USB. For a four-legged tactile button, find the permanently connected contact pairs using continuity mode. Do not assume that every pair opens when the button is released.
  2. Choose two contacts that have no continuity when released and continuity when pressed. Place the button so the breadboard does not join those two contacts accidentally.
  3. Connect one chosen contact to digital pin 2 and the other to GND. Check the complete path before reconnecting USB.

2. Upload the sketch

const byte buttonPin = 2;
unsigned long lastReport = 0;

void setup() {
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  const bool pressed = digitalRead(buttonPin) == LOW;
  digitalWrite(LED_BUILTIN, pressed ? HIGH : LOW);

  const unsigned long now = millis();
  if (now - lastReport >= 100UL) {
    lastReport = now;
    Serial.println(pressed ? "pressed" : "released");
  }
}

Select the UNO board and its connected port in the IDE. Open Serial Monitor at 9600 baud. The reporting interval limits the volume of text; it does not stop the loop from checking the button between reports. The built-in LED avoids introducing a second external circuit while you learn the input.

3. Test a small sequence

  1. Leave the button released for a few seconds. Expect a dark built-in LED and repeated “released” messages.
  2. Hold the button. Expect the LED to light and the message to change to “pressed”.
  3. Release and repeat several times. Watch the status while gently moving each insulated jumper to reveal a loose connection.
  4. Disconnect and reconnect USB with the button released. Confirm that the same resting state returns.

Troubleshooting and the next step

An always-pressed reading usually means the input is permanently connected to ground, perhaps through the button’s internally connected pair. An always-released reading suggests the switch never completes the path. Disconnect power before moving the button. Unexpected changes with no touch suggest a poor connection or a different sketch running on the board.

This program follows the current level; it does not count presses. Mechanical contacts may briefly bounce during a transition, even if your eye cannot see the LED flicker. Before using a button to toggle a mode or increment a counter, continue to the debounce guide. Keep this simple sketch as a known reference for checking future buttons and wiring.

Reference exercise · Read the evidence and checking record.

Your privacy, your choice.

This site currently loads no advertising or optional analytics scripts. Hosting includes aggregate traffic statistics and essential site-delivery functions. Optional services are off by default; changing these preferences does not activate them.

EssentialSite delivery and your saved privacy choices.Always on

Read the privacy notice