Built-in project · Arduino Uno R3

An LED on the 5 V pin, on an Arduino Uno

No code at all: the Uno’s 5 V pin, a 220 ohm resistor and an LED to ground. Give the resistor 1k or 10k and watch the same LED dim. 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 About 5 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.

An LED on the 5 V pin · Arduino Uno R3live0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

What you'll learn

  • Ohm's law and picking a resistor
  • Why an LED must have a series resistor
  • LED polarity: anode and cathode
  • A circuit that works without code
  • Difficulty: Beginner
  • Time: About 5 minutes
  • Board: Arduino Uno R3
  • Parts: 4

How it works

The Uno is just a power supply here. Its 5V pin pushes current through a 220 Ω resistor and the LED to ground. The resistor decides how much current flows: about 14 mA, which makes the LED bright.

Swap in a bigger resistor, such as 1000 or 10000 ohms, and the current drops to about 3 mA or 0.3 mA. The LED dims to a glow. The sketch is not needed for the circuit to work. It only prints two lines to the serial monitor.

Parts list

4 parts, plus the jumper wires. They retail for about $30; on Mokxi they're free.

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 pinConnects to
LED, red pin CArduino Uno R3 pin GND
Resistor, 220 Ω pin 1Arduino Uno R3 pin 5V
LED, red pin AResistor, 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.

sketch.ino · Arduino Uno R3
// An LED on the 5 V pin: a circuit with no code in it.
//
//   5V    -> 220 ohm resistor -> the LED's long leg (anode)
//   the LED's short leg (cathode) -> GND
//
// The Uno is only a power supply here. Its 5 V pin pushes current through the
// resistor and the LED, and the resistor decides how much: with 220 ohm about
// 14 mA flows and the LED is bright. Click the resistor and give it 1000 or
// 10000 ohm, and the same LED gets about 3 mA or 0.3 mA and dims to a glow.
//
// Never leave the resistor out. With nothing to limit it, an LED across 5 V
// takes as much current as the supply can give and burns out.
//
// The sketch below does nothing but say so: the circuit works without it.

void setup() {
  Serial.begin(9600);
  Serial.println("Mokxi Uno: an LED on the 5 V pin, no code needed");
  Serial.println("Try 1k or 10k in place of the 220 ohm resistor");
}

void loop() {
}

Code walkthrough

The key functions of the sketch, and what each one does.

setup sketch.ino

Opens serial at 9600 baud and prints two lines: one saying no code is needed, and one suggesting you try 1k or 10k instead of 220 ohms. Nothing here touches the LED.

void setup() {
  Serial.begin(9600);
  Serial.println("Mokxi Uno: an LED on the 5 V pin, no code needed");
  Serial.println("Try 1k or 10k in place of the 220 ohm resistor");
}

loop sketch.ino

Empty on purpose. The LED is powered straight from the 5V pin, so there is nothing for the code to do.

void loop() {
}

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • The LED does not light This project
    Check its direction. The anode (A) goes to the resistor and the cathode (C) goes to GND.
  • The LED burns out This project
    Never leave the resistor out. Without it the LED takes all the current the supply can give.
  • 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.
  • Upload fails or nothing runs after wiring pins 0 and 1 to a module. Arduino Uno R3
    Pins 0 and 1 are the USB serial port. Move the module to other pins, or unplug it while uploading. Also check the right board is selected.
  • Pins misbehave or the board resets when you power motors or servos from it. Arduino Uno R3
    Each I/O pin gives about 20 mA, 40 mA max. Power motors and servos from their own supply and join its ground to the Uno's GND.

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.