How it works
An LED is a diode — it has an exponential I–V curve. Without a current limiting resistor, a small increase in voltage causes a large increase in current, which burns the LED out in milliseconds. The series resistor sets the operating current:
R = (Vs − Vf) / If
Where Vs is the supply voltage, Vf is the LED’s forward voltage at the desired current, and If is the target current. The resistor drops the remaining voltage: Vresistor = Vs − Vf.
Forward voltage (Vf)
Vf varies by LED colour and process — red LEDs are ~2.0 V, blue/white are ~3.2 V. It also varies with current: higher current shifts Vf slightly higher. The datasheet specifies Vf at a given If (typically 20 mA). For indicators running at 5–10 mA, the actual Vf will be slightly lower than the datasheet’s 20 mA figure. For a first-order calculation, use the typical Vf value.
Choosing the current
The maximum rated current for a standard 5 mm LED is typically 20–30 mA. For indicators you rarely need this much:
| If | Perceived brightness | Notes |
|---|---|---|
| 1–2 mA | Dim | Panel indicators in dark environments |
| 5 mA | Moderate | General-purpose indicator |
| 10 mA | Bright | Most applications |
| 20 mA | Very bright | Maximum for standard LEDs |
Human eyes are not linear — there is diminishing returns above 5 mA. For most status LEDs, 5–10 mA is sufficient and runs cooler.
Power dissipation
The resistor dissipates P = If² × R watts. At 20 mA through a 150 Ω resistor:
P = (0.020)² × 150 = 0.06 W = 60 mW
A standard 0603 or 0402 resistor is rated 0.1 W (100 mW). This is fine. At 5 V with an IR LED (Vf = 1.3 V) at 100 mA:
R = (5 − 1.3) / 0.1 = 37 Ω → use 39 Ω (E24)
P = (0.1)² × 39 = 390 mW
Use a 0.5 W or 1 W resistor here, not a 0402.
GPIO drive limits
Microcontroller GPIO pins have a maximum source/sink current. Typical limits:
| MCU | Max GPIO current | Max total package |
|---|---|---|
| STM32F4 | 25 mA | 120 mA |
| nRF52840 | 15 mA | 50 mA |
| RP2040 | 12 mA | — |
| ATmega328P | 40 mA | 200 mA |
| ESP32 | 12 mA | 40 mA |
For LEDs at 10 mA or less, direct GPIO drive is usually fine. For 20 mA or higher, use a small NPN transistor (e.g. BC847, 2N3904) or an N-channel MOSFET (2N7002) to switch the current from a lower-impedance supply rail. The GPIO then drives the base/gate rather than the LED directly.
Common mistakes
Using no resistor. Even with a current-regulated supply, the LED’s V–I characteristic is so steep that ±100 mV variation in Vs causes ±50% change in current. Always use a resistor.
Ignoring the E24 derating. The exact calculated value (e.g. 173 Ω) is not a stocked value. The nearest E24 is 180 Ω — which reduces current by 4%. Usually fine, but worth checking if you’re targeting a specific brightness spec.
Underrating the resistor. A 0402 or 0603 at 0.1 W is fine for indicator LEDs at 10–20 mA. At higher currents (IR LEDs for proximity sensing, power LEDs) check the dissipation and use a rated part.
Forgetting Vf varies with temperature. At −40 °C, Vf increases by roughly 2 mV/°C. For a blue LED at room temperature Vf = 3.2 V, at −40 °C Vf ≈ 3.33 V. At 5 V supply with a 91 Ω resistor, current drops from 20 mA to 18.5 mA. Probably fine for an indicator; potentially a problem for an IR sensor calibrated at room temperature.