firmwareMIT

Arduino Uno: button

breadboardhub/arduino-button
arduinounobuttonled
ShareXLinkedInFacebookRedditWhatsApp
B
Mike M
v1.0.0 · UpdatedNov 24, 2026 ·0 downloads ·0 forks
// Button: the LED lights while the button on pin 2 is pressed.
// The button connects pin 2 to GND, so pressed reads LOW.

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

void setup() {
  pinMode(BUTTON, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
}

void loop() {
  if (digitalRead(BUTTON) == LOW) {
    digitalWrite(LED, HIGH);
  } else {
    digitalWrite(LED, LOW);
  }
}
Description

Light an LED while a button is pressed. It compiles and runs on a virtual Uno in the browser. Press and hold the button. Then make the LED stay off while it is pressed.

Cite this design
@design{breadboardhub/arduino-button,
  title = {Arduino Uno: button},
  author = {breadboardhub},
  url = {https://www.breadboardhub.com/breadboardhub/arduino-button},
  version = {1.0.0}
}