An LED is a diode, not a resistor. Past its forward voltage the current climbs almost vertically, so a small change in supply voltage produces a large change in current. Connect one straight across a supply and it will draw whatever the source can deliver until something fails. The series resistor is what turns an uncontrolled voltage source into a controlled current.
Working it through
A red LED on a 5 V rail, driven at 20 mA. Red LEDs drop about 2.0 V, so the resistor has to absorb 5 − 2 = 3 V. R = 3 / 0.02 = 150 Ω, which happens to be a standard value. The resistor dissipates P = I²R = 0.02² × 150 = 0.06 W, well inside a quarter-watt part.
Change the LED to blue, which drops around 3.2 V, and the resistor sees only 1.8 V. R = 1.8 / 0.02 = 90 Ω, so you would fit 91 Ω or 100 Ω. Note how much more sensitive this circuit is: the same 0.2 V variation in forward voltage between two blue LEDs from the same reel shifts the current by over 10%.
Typical forward voltages
| Colour | Forward voltage | Typical current |
|---|---|---|
| Infrared | 1.2 – 1.6 V | 20 – 100 mA |
| Red | 1.8 – 2.2 V | 20 mA |
| Amber / yellow | 2.0 – 2.2 V | 20 mA |
| Green | 2.0 – 3.2 V | 20 mA |
| Blue | 3.0 – 3.4 V | 20 mA |
| White | 3.0 – 3.4 V | 20 mA |
These are starting points. The datasheet for the part you actually have is the real answer, and forward voltage drifts down as the junction heats up.
Series or parallel
Multiple LEDs in series share one current, so their brightness matches and you need one resistor. The supply has to exceed the sum of the forward voltages with enough headroom left for the resistor to do its job — aim for at least 20% of the supply across the resistor, or the circuit becomes sensitive to every variation.
LEDs in parallel on a single shared resistor is a common mistake. Forward voltages never match exactly, so the LED with the lowest drop takes most of the current, runs hottest, drops further, and takes even more. Give each parallel branch its own resistor.
Driving from a microcontroller pin
An ESP32 or Arduino pin is usually rated for 12 – 40 mA, with a much lower total across the whole chip. Running several LEDs at 20 mA directly from GPIO pins can exceed the package limit even when each individual pin is inside spec. For more than two or three, switch them with a transistor or use a dedicated LED driver.
When a resistor is the wrong tool
The resistor wastes the headroom voltage as heat. For a single indicator that is irrelevant. For power LEDs — anything over about 350 mA — the loss becomes the dominant term and the current still moves with supply voltage and temperature. Use a constant-current driver instead.