Wiring guide

How to wire an LED to an Arduino Uno

To wire an LED to an Arduino Uno, connect A to pin 2 and C to GND. The Arduino Uno’s pin is 5 V and a 220 ohm resistor in series limits the current through the LED to about 14 mA, so nothing else is needed. The sketch below uses no library beyond what the board includes. It blinks the LED, half a second on and half a second off, printing LED on and LED off.

  • 5 V logic
  • Library: none
  • 2 wires, 1 helper parts
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.
Pin to pin

LED to Arduino Uno wiring table

Every wire in the circuit above, with the part’s pin names and the board’s own labels. The wire colors are the ones the circuit uses; on a real bench any colors work.

LED pinArduino Uno pinWire colorWhy
A (anode)pin 2, through R1 (220 Ω)amberThe long leg. Current flows in here, so it takes the signal, with the resistor in the way.
C (cathode)GNDblueThe short leg, on the flat side of the lens, goes to ground.
220 ohm resistorIn series with the anoden/aLimits the current. Without it the LED, the pin or both burn out.

Helper parts

The extra parts in the circuit above, and where their wires go:

FromToWire color
R1 (220 Ω) pin 12green
Voltage

Power and logic levels for LED and Arduino Uno

Logic level

The Arduino Uno’s pins are 5 V logic. A 5 V part can drive them directly; a part whose signal pins are limited to 3.3 V needs a level shifter.

This pair

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

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.

The sketch

The working code for the Arduino Uno

Library: none, the sketch drives the pin with digitalWrite(). This is the sketch the circuit above runs.

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);
}
Output

What you should see

The LED lights for half a second and goes dark for half a second. The serial monitor, at 9600 baud, prints LED on and LED off as the pin changes.

An LED that never lights is usually in backwards: the long leg, the anode, faces the resistor and the pin.

The serial monitor prints this, recorded from the circuit above running for two and a half seconds:

LED on
LED off
LED on
LED off
LED on
Pitfalls

Common mistakes wiring an LED to an 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.

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.