An LED (light-emitting diode) is a diode that emits light when current passes through it in the right direction. It's probably the first part you'll ever switch on in your electronics life, and this seemingly simple subject has details that make a big difference.
Why does it light up?
Inside the LED is a small crystal of a semiconductor material. When electrons cross the junction inside it, they lose energy, and that energy comes out as light. The colour of the light is set by the type of material, not by the colour of the plastic. That's why a blue LED needs a higher voltage than a red one: blue light has more energy.
And the LED is highly efficient: most of the energy comes out as light rather than heat, unlike an old bulb. That's why it lasts a very long time (tens of thousands of hours) if it runs within its limits.
The anode and cathode
Like any diode, an LED conducts in one direction:
- The anode (+): the longer leg.
- The cathode (−): the shorter leg, with a flat side on the LED body next to it.
If you fit it the wrong way round it won't light, and usually won't be damaged as long as the reverse voltage is small (about 5 V for most).
If the legs have been cut: set the multimeter to diode mode (the ▷| symbol). If the red lead is on the anode, the LED will glow faintly and the display will show a number. The other way round it shows OL. And on an SMD LED, the green mark or dot is usually on the cathode side.
The forward voltage
Each colour needs a certain voltage to light up, roughly:
- Red: about 2 V.
- Yellow and old green: about 2.1 V.
- Blue, white and bright green: about 3–3.3 V.
Why does it need a resistor?
Beyond the forward voltage, the current in the LED rises very quickly with any small increase in voltage. Without something to limit the current, the LED will burn out. The simplest solution: a series resistor. The full calculation is in the LED resistor article.
A quick example: a red LED from 5 V at 10 mA:
R = (5 − 2) ÷ 0.010 = 300 Ω → the nearest value is 330 Ω
And 10 mA is plenty for an indicator. Most modern LEDs light well even at 2–5 mA, which eases the load on the microcontroller pin and extends battery life.
Several LEDs
- In parallel: each LED with its own resistor. Don't use one resistor for several LEDs, because the forward voltage differs slightly between them, so one takes most of the current and burns out.
- In series: the voltages add up. 3 red LEDs (6 V) need a supply above 6, such as 9 or 12 V, and one resistor for the whole string.
The types
5 mm and 3 mm LEDs
The classic for indicators and experiments, with a typical current of about 5–20 mA.
SMD
Very small (0603, 0805…), and found in every modern device as an indicator, and in LED strips.
RGB
3 LEDs (red, green and blue) in one body. By mixing the colours in different proportions, you can make any colour.
There are two types: common anode (the anode shared on +) and common cathode (the cathode shared on −). Know your type before wiring, because the logic in the code is inverted.
Each colour needs its own resistor, because red has a lower voltage than blue and green. And from code:
analogWrite(9, 255); // full red
analogWrite(10, 100); // a little green
analogWrite(11, 0); // no blue → orange
With common anode, invert the values (255 − the value), because the pin must be LOW for the colour to light.
The addressable LED (WS2812 or NeoPixel)
Inside each LED is a small chip. You control hundreds of LEDs with a single data wire, each with its own colour. That's what's in smart LED strips. Be aware that each LED can draw up to about 60 mA at full white, so a 100-LED strip needs a strong supply. The details are in the WS2812 strip article.
The power LED
LEDs of 1 W and more for lighting. These need cooling and a constant-current source (driver); a resistor isn't enough.
Why? Because when an LED heats up, its forward voltage falls, so the current rises, so it heats up more. With a large current this can lead to thermal runaway. A driver holds the current steady whatever the voltage does, and a heatsink carries the heat away. See heatsinks.
Controlling brightness
Don't dim by lowering the voltage. Use PWM from the microcontroller: switching on and off very fast, and the proportion of on-time sets the brightness the eye sees. And if the LED or strip draws a large current, switch it through a MOSFET.
The eye isn't linear: the difference between 10% and 20% is very visible, and between 80% and 90% barely. For dimming to look smooth, use a curve instead of the raw values:
int level = 128; // from 0 to 255
int pwm = (long)level * level / 255; // approximate square for the eye
analogWrite(9, pwm);
Common faults
| Symptom | Usual cause |
|---|---|
| It doesn't light at all | Reversed, the resistor is far too large, or it's burnt out |
| It flashed for a moment and went out | Connected without a resistor and burnt out |
| Its light is dim | The resistor is large, or the voltage is close to the forward voltage |
| One LED in a row is brighter than the rest | One resistor for several LEDs in parallel |
| It flickers on camera | A low PWM frequency; raise it |
| A white LED has turned yellow and dim | It ran at high current and got hot for a long time |
FAQ
Can I run an LED on 220 V? Not safely with an ordinary resistor, because the power in the resistor would be very large and the circuit is dangerous. Use a ready-made LED lamp or a dedicated mains indicator, and read mains safety.
Why won't a blue LED light on 3 V? Because its forward voltage itself is about 3 V, so there's no spare voltage for the resistor, and the current is very weak. You need a slightly higher supply, such as 3.3 or 5 V.