Components · 3 min read

What Is an LED? How It Works and How to Connect It to Arduino

What is an LED, how does it work and how do you tell the anode from the cathode? LED resistor calculation, LED voltages by color, RGB LEDs and wiring to Arduino.

An LED (Light Emitting Diode) is a semiconductor that emits light when current flows through it. LEDs are everywhere, from phone screens and traffic lights to car headlights and the bulbs in your home. In electronics, almost everyone's first project is lighting an LED, because it teaches digital outputs, current limiting and timing all at once.

5 mm LED
5 mm LEDs in different colors. The long leg is positive (anode), the short leg is negative (cathode).

How does an LED work?

An LED is a diode: it lets current flow in only one direction. When connected the right way, electrons inside the semiconductor lose energy and emit light (photons). The color of the light depends on the semiconductor material, which is why red, green and blue LEDs run at different voltages.

How do you tell an LED's positive and negative legs apart?

  • The long leg is the anode (+), the short leg is the cathode (−).
  • The side with the flat edge on the LED's rim is the cathode.
  • If you look inside the LED, the large flag-shaped part is usually connected to the cathode.
  • An LED inserted backwards won't light but won't break either; flip it and try again.

Why shouldn't an LED be connected without a resistor?

An LED doesn't limit its own current. Just a little above its forward voltage, the current rises very fast and the LED can fail within seconds; the Arduino pin can be damaged too. That's why an LED always gets a series resistor. The resistor value is found with this formula:

R = (Supply voltage − LED voltage) / LED current

For example, with a 5 V Arduino, a red LED (about 2 V) and 15 mA: R = (5 − 2) / 0.015 = 200 Ω. The nearest standard value, 220 Ω, is used. To see this calculation and the actual current instantly, use the LED resistor calculator.

LED voltages by color

LED colorTypical forward voltage (Vf)Recommended resistor at 5 V (15 mA)
Red1.8–2.0 V220 Ω
Orange / Yellow1.9–2.1 V220 Ω
Green (classic)2.0–2.2 V200–220 Ω
Green (pure)3.0–3.2 V120–150 Ω
Blue / White3.0–3.3 V120–150 Ω
Infrared (IR)1.2–1.5 V240–270 Ω

You can find typical and maximum values for every color in the LED voltage table.

Connecting an LED to Arduino

  1. Connect a digital pin of the Arduino (e.g. 9) to a 220 Ω resistor.
  2. Connect the other end of the resistor to the LED's long leg (anode).
  3. Connect the LED's short leg (cathode) to the Arduino's GND pin.
  4. In the code, make the pin an output with pinMode(9, OUTPUT) and turn it on and off with digitalWrite.
C++ (Arduino IDE)
1const int LED = 9;
2
3void setup() {
4  pinMode(LED, OUTPUT);
5}
6
7void loop() {
8  // Yavaşça parlat / fade in (PWM, 0-255)
9  for (int i = 0; i <= 255; i++) { analogWrite(LED, i); delay(4); }
10  // Yavaşça söndür / fade out
11  for (int i = 255; i >= 0; i--) { analogWrite(LED, i); delay(4); }
12}
To adjust the LED's brightness, use the PWM pins (marked ~ on the Uno: 3, 5, 6, 9, 10, 11) and analogWrite. The code above gives the LED a 'breathing' effect.

What is an RGB LED?

An RGB LED contains three LEDs, red, green and blue, in a single package. By setting the brightness of each color separately with PWM you can get thousands of colors: red + green = yellow, green + blue = cyan, all three = white. RGB LEDs come as common cathode (common leg to GND) or common anode (common leg to 5 V); with common anode the code logic is inverted.

RGB LED

Addressable LEDs (WS2812B, NeoPixel)

Smart LEDs like the WS2812B each contain a tiny driver chip. This lets you control hundreds of LEDs with a single data pin and light each one in a different color. In LED strips each LED draws about 60 mA at full white, so long strips need a separate 5 V power supply.

WS2812B
WS2812B
WS2812B ring
WS2812B ring
8x8 NeoPixel matrix
8x8 NeoPixel matrix

Common mistakes

  • Connecting several LEDs in parallel with one resistor: the current isn't shared equally; give each LED its own resistor.
  • Drawing too much current from an Arduino pin: don't exceed 20 mA per pin or 200 mA for the whole board.
  • Trying PWM on a non-PWM pin: the brightness doesn't change; the LED only turns on or off.
  • Using a large resistor with blue and white LEDs on 3.3 V boards (ESP32, Pico): the LED will be very dim.
Don't stare at high-power LEDs (1 W and above) for long, and don't drive them directly from an Arduino pin; use a constant-current driver.

Frequently asked questions

What voltage does an LED run on?

It depends on the color: red needs about 2 V, blue and white about 3.2 V. However, you don't apply that voltage directly; you apply the supply voltage together with a resistor, which limits the current.

Should I use 220 Ω or 330 Ω for an LED?

With 5 V, both are safe for red, yellow and green LEDs. 220 Ω gives a brighter result (about 13 mA), 330 Ω a slightly dimmer one that draws less current (about 9 mA).

Can LEDs be connected in series?

Yes, as long as the total LED voltage is below the supply voltage. For example, three white LEDs (3 × 3.2 V = 9.6 V) can run from 12 V with a suitable resistor.

Why is my LED so dim?

The pinMode(pin, OUTPUT) line may be missing, the resistor may be too large, or you may be using a blue/white LED on a 3.3 V board. Use a smaller resistor and check your code.

How can I tell if an LED is broken?

Touch the LED's legs with a multimeter in diode mode; a working LED glows faintly in the right direction and the display shows its forward voltage. In the reverse direction it shows no reading.

See all projects
LED Blink
AR-1Beginner

LED Blink

The very first hello of electronics: switching a single LED on and off. The Arduino keeps the LED on for one second and off for one second, so you can easily follow every blink.

4.6(203)
1382
Traffic Light
AR-3Beginner

Traffic Light

A tiny copy of the traffic light you see on the road every day. Red stays on for two seconds, yellow flashes for a moment, green stays on for two seconds, then it goes back to red through yellow…

4.8(139)
490
Knight Rider LED Effect
AR-6Intermediate

Knight Rider LED Effect

The classic scanner light: a dot of light slides from one end of six LEDs to the other and then comes back.

4.8(107)
236
Using an RGB LED
AR-39Beginner
Premium

Using an RGB LED

Three colours hide inside a single LED: the RGB LED lights up red, then green, then blue, each colour on for half a second and off for half a second, before the cycle starts again.

4.9(74)
101
Smooth Color Transition with RGB Led
AR-40Beginner
Premium

Smooth Color Transition with RGB Led

A single RGB LED drifts slowly from red to green, green to blue and back to red, looping through the rainbow without ever stopping.

4.8(59)
78
Using a WS2812B LED Strip
AR-69Intermediate
Premium

Using a WS2812B LED Strip

Meet a smart LED strip where you can colour every single light on its own. The Arduino first lights the first five LEDs red, a second later turns the other five blue, then switches them all off and…

4.8(54)
70
ESP32 LED Fade with PWM
ES-8Beginner

ESP32 LED Fade with PWM

Smoothly changing the brightness of the LED from 0 to max, from max to 0. We control PWM with analogWrite() as in Arduino - the same syntax as ESP32 Arduino Core 3.0+ works without problems. Pin definition + pinMode + analogWrite is enough.

4.8(36)
55
Raspberry Pi Pico PWM LED Fade (Breathing Effect)
PI-14Beginner

Raspberry Pi Pico PWM LED Fade (Breathing Effect)

The LED doesn't just blink anymore, it breathes! With the Raspberry Pi Pico's PWM (Pulse Width Modulation), the LED's brightness slowly rises and then slowly fades, a calm "breathing" effect like a sleeping laptop's light. You'll learn the machine.PWM class, the 16-bit brightness value from 0–65535 with duty_u16() and the PWM frequency.

4