Button on pin 12 lights the LED on pin 13, on an Arduino Uno
A pushbutton from 5 V to pin 12, held low by a 10k pull-down, lights the Uno’s own LED on pin 13 while it is pressed. The whole build, an Arduino Uno and 2 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner Runs in your browser. Free, and no account needed.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// A button on pin 12 lights the LED on pin 13.
//
// one side of the button -> 5V
// the other side -> pin 12, and a 10k resistor from pin 12 to GND
// the LED is the Uno's own, on pin 13
//
// The 10k is a pull-down: with the button up it holds pin 12 at 0 V, so the
// pin reads LOW instead of floating. Pressed, the button joins pin 12 to 5 V
// and it reads HIGH. (On the bench a 0.1 uF capacitor across the resistor
// smooths out the contact's bounce.)
//
// Hold the button on the canvas and watch the L LED on the board.
const int BUTTON = 12;
const int LED = 13;
int last = LOW;
void setup() {
pinMode(BUTTON, INPUT);
pinMode(LED, OUTPUT);
Serial.begin(9600);
Serial.println("Mokxi Uno: hold the button on pin 12");
}
void loop() {
int now = digitalRead(BUTTON);
digitalWrite(LED, now);
if (now != last) {
last = now;
Serial.println(now == HIGH ? "pressed: LED on" : "released: LED off");
}
delay(5);
}
Parts list
4 parts, plus the jumper wires. Every one is in the editor's parts bin.
- 1 × Arduino Uno R3
- 1 × Half breadboard
- 1 × Pushbutton
- 1 × Resistor, 10k Ω
How it is wired
4 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Ground: Arduino Uno R3 pin GND; Resistor, 10k Ω pin 1
- Arduino Uno R3 pin 12; Pushbutton pin 2a
- Arduino Uno R3 pin 5V; Pushbutton pin 1a
- Pushbutton pin 2b; Resistor, 10k Ω pin 2
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.