Battery Powered LED
A self-contained circuit: flip the switch to power an LED from a 9V battery.
- Beginner
- LED & Lighting
- 5 parts
Opens in your browser with the parts, wiring and code already in place. Press Run to watch it work, then change anything you like.
How it works
This is a pure hardware circuit with no Arduino: the positive terminal of a 9 volt battery goes to a switch, then through a resistor and the LED, and back to the battery’s negative terminal. Closing the switch completes the loop so current flows and the LED lights; opening it breaks the loop. The resistor matters even more here than in the Arduino examples: with 9 volts across an LED and nothing to limit the current, the LED would burn out.
The sketch is empty on purpose, because the Arduino is not part of this circuit; the simulator just expects setup() and loop() to exist. Click the switch in the editor to open and close it. It shows the idea behind every circuit on this site: current needs a complete loop from the power source, through the parts, and back.
Parts
- Battery 9V
- Switch
- Resistor
- LED
- GND
Wiring
- Battery 9V + → Switch A
- Switch B → Resistor A
- Resistor B → LED Anode (+)
- LED Cathode (-) → GND
- Battery 9V - → GND
Arduino code
// Battery Powered LED
// A pure hardware circuit: the switch closes the loop
// between the 9V battery, resistor and LED.
void setup() {
}
void loop() {
delay(1000);
}
Try changing it
- Select the resistor and look at its value. A typical LED runs at about 10 milliamps and drops about 2 volts, so from a 9 volt battery you want roughly (9 − 2) ÷ 0.01 = 700 ohms. Try other values and think about what each would do on a real board.