A push button lights an LED, no code, on an Arduino Uno
An LED, a 220 ohm resistor and a push button in a loop from the Uno’s 5 V pin to ground: hold the button and the LED lights. The board is only the power supply. The whole build, an Arduino Uno and 3 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 About 10 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $30. On Mokxi they're free.
What you'll learn
- A circuit as a closed loop
- A button as a gap that closes
- Current limiting with a 220 ohm resistor
- Using the board as a power supply
- Difficulty: Beginner
- Time: About 10 minutes
- Board: Arduino Uno R3
- Parts: 5
How it works
The button, resistor and LED form one loop from the 5V pin to GND. The button is a gap in that loop. Pressing it closes the gap, current flows through the resistor and the LED, and the LED lights.
The Uno acts only as a 5 V power supply here. The sketch just prints a hello line at the start, and its loop is empty, so nothing is read or controlled by code.
Parts list
5 parts, plus the jumper wires. They retail for about $30; on Mokxi they're free.
- 1 × Arduino Uno R3In Starter Kit, Claw Machine Kit, Vending Machine Kit.
- 1 × Half breadboard
- 1 × PushbuttonIn Starter Kit, Christmas Lights Kit, Logic Lab Kit.
- 1 × Resistor, 220 ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 1 × LED, redIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
Kits that can build it
These 12 starter kits have every part in the circuit. Each kit's page lists what else it can build.
- ELEGOO UNO R3 Super Starter Kit
- ELEGOO UNO R3 Most Complete Starter Kit
- Arduino Starter Kit
- Freenove Ultimate Starter Kit
- ELEGOO UNO R3 Basic Starter Kit
- SunFounder Starter Kit for Arduino Uno R3
- SunFounder Inventor Lab Kit
- REXQualis UNO R3 Super Starter Kit
- LAFVIN Super Starter Kit
- keyestudio Super Starter Kit
- Vilros Arduino Uno 3 Ultimate Starter Kit
- Adafruit MetroX Classic Kit
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| LED, red pin C | Arduino Uno R3 pin GND |
| Pushbutton pin 1a | Arduino Uno R3 pin 5V |
| Resistor, 220 Ω pin 1 | Pushbutton pin 2a |
| LED, red pin A | Resistor, 220 Ω pin 2 |
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// A push button lights an LED: a circuit with no code in it.
//
// 5V -> push button -> 220 ohm resistor -> the LED's long leg (anode)
// the LED's short leg (cathode) -> GND
//
// The button is a gap in the loop. Pressed, it closes the gap, current flows
// from 5 V through the resistor and the LED to ground, and the LED lights.
// Let go and the loop is open again. Nothing here needs the processor: the
// Uno is just a 5 V supply, which is why the sketch only says hello.
//
// Hold the button on the canvas.
void setup() {
Serial.begin(9600);
Serial.println("Mokxi Uno: hold the button to close the circuit");
}
void loop() {
}
Code walkthrough
The key functions of the sketch, and what each one does.
setup sketch.ino
Starts the serial port at 9600 baud and prints one message. It does not set up any pin, because the LED is wired straight to 5V.
void setup() {
Serial.begin(9600);
Serial.println("Mokxi Uno: hold the button to close the circuit");
}loop sketch.ino
It is empty on purpose. The LED is switched by the button alone, so the processor has nothing to do.
void loop() {
}Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- The LED does not light when you press the button. This project
Check the LED direction. The long leg (anode) goes toward the resistor, and the short leg goes to GND. - You looked for the code that controls the LED. This project
There is none. The button and the wiring do the work. - The input reads random HIGH and LOW when the button is not pressed. Pushbutton
A floating pin picks up noise. Add a 10 k pull-down or pull-up resistor, or use INPUT_PULLUP and wire the button between the pin and GND. Then pressed reads LOW. - The button seems always pressed, or never changes. Pushbutton
A 4-leg tactile switch has legs joined in pairs. Place it across the breadboard center gap so the pairs sit on different rows. Wired along one side, the legs are already connected. - The LED is dim, burns out, or the pin reads wrong because the resistor value is off. Resistor
Read the color bands again. A 220 ohm to 330 ohm resistor suits a typical LED on 5 V. 10k is a common pull-up or pull-down value. Check with a multimeter if unsure. - A pull-up or pull-down resistor is missing, so the input floats and reads random values. Resistor
Tie the input to 5 V or ground through about 10k. Or use INPUT_PULLUP and wire the switch to ground. - The LED does not light, or it lights once and then dies. LED
LEDs have polarity. The longer leg (anode) goes toward the positive side. Always add a series resistor, about 220 ohms to 1 k ohm on a 5 V pin. - A blue or white LED stays dark on 3.3 V. LED
Blue and white LEDs drop about 3 V, so 3.3 V leaves almost nothing for the resistor. Use a 5 V supply, or a smaller resistor and a red or green LED.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.