Board and part

Arduino Uno LED Simulator: Wiring, Code and a Live Circuit

This is a red LED with a 220 ohm resistor, wired to an Arduino Uno and blinking live in your browser. The serial monitor prints LED on and LED off as the pin changes.

  • 5 V logic
  • No library
  • Pin pin 2
  • 220 ohm resistor
Arduino Uno · LEDlive0.000 s 0.00x
Click to open it in the editor
The circuit itself, running on the simulator with the sketch below. Press what can be pressed; click anything else to open it in the editor.
Connections

Wiring the LED to the Arduino Uno

Two connections matter: the pin to the resistor and the resistor to the LED’s anode, then the cathode to ground. The pin is pin 2 and the supply behind it is 5 V.

Every connection in the circuit above, with the board’s own pin names.

LED pinArduino Uno pinWhy
A (anode)pin 2The long leg. Current flows in here, so it takes the signal, with the resistor in the way.
C (cathode)GNDThe short leg, on the flat side of the lens, goes to ground.
220 ohm resistorIn series with the anodeLimits the current. Without it the LED, the pin or both burn out.

Power

A red LED drops about 2 V, so with 220 ohm in series a 5 V pin pushes about 14 mA through it: bright enough to see and gentle on the pin. The resistor can sit on either side of the LED; what matters is that it is in the loop.

Pins to leave alone on the Arduino Uno

Pins 0 and 1 are the USB serial port on a real Uno, so anything wired there fights the upload and the serial monitor. Pin 13 carries the onboard LED.

On a real bench

On a real bench the Uno stands beside the breadboard: the LED goes into the breadboard and male-to-male jumpers run from the Uno’s female headers to its rows. Power the Uno from USB while you build, and unplug it before you move a wire.

The sketch

The code, and what it does.

The sketch the circuit above runs. Open it in the editor, change a line and press Run: it compiles in your browser.

Blinking an LED on Arduino Uno pin 2
const int LED_PIN = 2;   // pin 2, through a 220 ohm resistor to the LED

void setup() {
  Serial.begin(9600);
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_PIN, HIGH);
  Serial.println("LED on");
  delay(500);
  digitalWrite(LED_PIN, LOW);
  Serial.println("LED off");
  delay(500);
}

pinMode(LED_PIN, OUTPUT) makes pin 2 drive its level instead of listening to it. digitalWrite(LED_PIN, HIGH) puts 5 V on the pin, which pushes current through the resistor and the LED to ground, and LOW takes it away.

delay(500) holds each state for half a second, so the LED blinks once a second. While delay() waits the board does nothing else; a sketch that must also do other work times itself with millis() instead.

Serial.begin(9600) opens the serial monitor. Serial goes over the USB cable, and the serial monitor in the editor reads it at whatever baud rate the sketch sets.

Pitfalls

Common mistakes with the LED on the Arduino Uno

Putting the LED in backwards

An LED passes current one way only. Backwards it stays dark and nothing is damaged. If it never lights, swap its two legs: the long leg, the anode, faces the signal.

Leaving out the resistor

An LED has almost no resistance once it conducts, so the only limit on the current is the pin. At 5 V that is far more than the LED’s 20 mA rating. The simulator burns the LED out and shows it dark for good, as a real one goes.

Using pins 0 and 1

Pins 0 and 1 carry the USB serial port on a real Uno. the LED wired there fights every upload and every Serial.print(). Start at pin 2.

FAQ

Questions and answers

How do I connect an LED to an Arduino Uno?

Wire pin 2 to a 220 ohm resistor, the resistor to the LED’s long leg, and the LED’s short leg to GND. In the sketch call pinMode(2, OUTPUT) and digitalWrite(2, HIGH).

What resistor value should I use?

Subtract the LED’s drop, about 2 V for red, from the pin’s 5 V and divide by the current you want. For 10 mA that is 300 ohm; 220 ohm is the common value because it is safe for any color.

Can I run an LED without a resistor on a pin?

No. The pin has no way to limit the current, so the LED or the pin is damaged. Always put a resistor in series.

Why does my LED stay dim?

Either the resistor is too large, or the pin is being driven with PWM at a low duty. A 220 ohm resistor with digitalWrite(HIGH) gives full brightness.

Build your own LED project

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