100nF

LED series resistor: the value, and the current you get

Compute the resistor from headroom, then find why one part number gives a 2:1 current spread on 3.3 V, what an MCU pin really delivers, and when to stop.

The equation takes one line. Subtract the LED’s forward voltage from the supply, and divide what is left by the current you want:

R=VS−n VFIFR = \frac{V_S - n\,V_F}{I_F}

For one red LED at 20 mA on a 5 V rail with VF=2.2V_F = 2.2 V that is 2.8/0.02=140 Ω2.8/0.02 = 140\ \Omega, and the nearest E24 value at or above it is 150 Ω. The LED resistor calculator does this, and the rest of this article is about the part the equation does not tell you: the current you actually get is not the current you designed for, and how far off it is depends almost entirely on the numerator.

That numerator — VS−n VFV_S - n\,V_F, the headroom — is the whole story. A real part number publishes a forward-voltage range, not a value. Würth’s WL-SMCW red 0603 (150060RS75000) specifies VFV_F between 2.0 V and 2.4 V at 20 mA. Fit one 150 Ω resistor and the current across a reel of those parts runs from 17.3 mA to 20.0 mA. Move the same 20 mA design to 3.3 V — which means refitting 56 Ω — and the same 0.4 V bin now spreads it from 16.1 mA to 23.2 mA; stack the supply and resistor tolerances on top and it is 13 mA to 26 mA. The bin did not change and the resistor was re-chosen for the rail. What changed is the headroom the bin is divided into.

A supply, a series resistor and an LED in a loop, with the supply voltage split into the LED forward voltage and the headroom across the resistor. The headroom is what the resistor divides by the current.
Fig 1 — The whole circuit, and the only quantity in it that is yours to choose. The LED takes the forward voltage its physics dictates; the resistor gets whatever is left, and that leftover — the headroom — divided by the current you want, is the resistance.

The load line, and why the bin is a current spread

An LED is a diode, so its current-voltage curve is exponential and steep. Near the datasheet test current that steepness is what makes the constant-VFV_F model useful: the LED holds its voltage and the resistor sets the current. The model’s weakness is not the curvature — it is that the curve’s position is a manufacturing outcome.

Plot the resistor’s load line, running from VSV_S on the voltage axis down to VS/RV_S/R on the current axis, and mark the two forward voltages the datasheet guarantees. Where the load line crosses each is a current, and the difference between them is what a single reel will hand you:

V_F min 2.0 V:  I = (5.0 − 2.0) / 150 = 20.0 mA
V_F max 2.4 V:  I = (5.0 − 2.4) / 150 = 17.3 mA
A current-voltage plane with the resistor load line falling from the supply voltage, crossing the two vertical lines that mark the minimum and maximum forward voltage of one part number. The two crossings are at different currents, which is the spread a single resistor produces.
Fig 2 — Why a datasheet with one part number still gives two answers. The load line is fixed by the supply and the resistor; the LED contributes a forward voltage anywhere between the published limits, and the current is wherever the two meet. For the Würth red 0603 on 5 V with 150 Ω that is 17.3 mA to 20.0 mA.

Headroom is the design, everything else is arithmetic

Differentiate the current with respect to the forward voltage and the result is as blunt as it looks:

ΔII=ΔVFVS−n VF\frac{\Delta I}{I} = \frac{\Delta V_F}{V_S - n\,V_F}

The resistance cancels. A ±0.2 V bin costs ±7 % of the current on a 5 V rail with one red LED, ±18 % on 3.3 V, and ±2 % on 12 V — and the resistor’s own tolerance does not appear in the expression at all. Buying 0.1 % resistors for an LED that sits on 1.1 V of headroom is spending money in the wrong place: the bin contributes ±18 %, a 1 % resistor contributes 1 %, and the 0.1 % part buys back a tenth of that one per cent.

The practical rule that falls out of it: keep the headroom at least ten times the half-width of the VFV_F bin if the current matters to better than 10 %. For this red LED that is 2 V, which a 5 V rail comfortably provides and a 3.3 V rail does not.

Relative current error plotted against headroom voltage on log axes. The error rises steeply as headroom shrinks, passing ten per cent around two volts and exceeding fifty per cent below half a volt.
Fig 3 — The single most useful curve on this page. A ±0.2 V forward-voltage bin becomes a current error of ±0.2 V divided by the headroom, so headroom is not a detail of the design — it is the design. The three marked points are the same red LED on three common rails.

Blue and white LEDs do not run from 3.3 V

The same datasheet family makes the point sharply. The WL-SMCW blue 1206 (150120BS75000) specifies VFV_F from 3.2 V to 3.5 V at 20 mA. A nominal 3.3 V rail with a ±5 % tolerance falls to 3.135 V — below the minimum of that range, never mind the maximum. There is no resistor value that fixes this, because the problem is not the resistor. The LED is not dark: the datasheet’s own forward-current curve shows the typical part passing roughly 13 mA at 3.135 V with no resistor at all. The problem is that the current is then set entirely by where that part’s curve happens to fall — a bottom-of-bin part passes more, a top-of-bin part far less — and the resistor, with no headroom to divide, no longer sets anything.

This is why blue, white and UV indicators on 3.3 V boards either sit on the 5 V rail, run from a boost, or are accepted as dim and inconsistent. Anything in the InGaN chemistries — blue, true green, white, UV — lands in the 2.8 V to 3.8 V range and needs a rail above it with room to spare. The red, orange, yellow and yellowish-green AlInGaP and GaP parts sit near 2 V and are the ones that work on 3.3 V.

A grid of supply rails against the number of LEDs in series, marking each combination as workable, marginal or impossible using the published maximum forward voltages of a red and a blue LED.
Fig 4 — Which strings actually work, computed from the red part's published maximum forward voltage rather than its typical. A string is only designable if the worst-case bin still leaves headroom on the worst-case supply; a cell marked "no headroom" is not necessarily dark, it is a current the resistor no longer sets. That is the blue LED on 3.3 V: 3.5 V max against a 3.135 V rail.

The worst case, with every tolerance stacked

A design is not finished at the nominal. Stack a ±5 % supply, the published VFV_F range, a 1 % resistor and the E24 value actually fitted, all pushed the same way, and the same 20 mA intent lands very differently depending on the rail:

rail    R fitted   nominal    worst case         spread
3.3 V     56 Ω     19.6 mA    13.0 – 26.4 mA     2.03 : 1
5 V      150 Ω     18.7 mA    15.5 – 21.9 mA     1.41 : 1
9 V      360 Ω     18.9 mA    16.9 – 20.9 mA     1.24 : 1
12 V     510 Ω     19.2 mA    17.5 – 21.0 mA     1.20 : 1

For an indicator, 1.41:1 is invisible and 2.03:1 is merely noticeable across a row of boards. For anything measured — an optical sensor’s emitter, a backlight matched to a second panel — even 1.2:1 is a problem, and that is the point at which the resistor stops being the right circuit.

Note also what the 3.3 V row does at the top end: 26.4 mA against a part rated 30 mA continuous. One more adverse tolerance and the design is outside the datasheet.

Worst-case current bands for the same LED design on several supply rails, each drawn as a bar from minimum to maximum current with the nominal marked. The bars narrow sharply as the supply voltage and therefore the headroom rises.
Fig 5 — Every tolerance stacked the wrong way: ±5 % supply, the published ±0.2 V bin, a 1 % resistor, and the nearest E24 value fitted. The 3.3 V design is not a 20 mA design; it is a 13-to-26 mA design that happens to average 20.

The resistor is a heater

Whatever headroom buys in current stability, it costs in power. The resistor dissipates IF(VS−n VF)I_F(V_S - n\,V_F) and the LED consumes IF⋅n VFI_F \cdot n\,V_F, so the fraction of the supply’s power that becomes light-adjacent falls as the rail rises:

5 V:    56 mW in the resistor,  44 mW in the LED   —  44 % to the LED
12 V:  196 mW in the resistor,  44 mW in the LED   —  18 % to the LED

At 5 V and 20 mA a 0603 resistor is comfortable. At 12 V, 196 mW is past what an 0603 is usually rated for and well past a derated one; that resistor is now a component with a package decision attached, and its self-heating changes its own value. The voltage divider calculator has the same power arithmetic in it for the same reason.

Two curves against supply voltage: the power burned in the series resistor rising steadily, and the fraction of the total power reaching the LED falling from about half at five volts to under a fifth at twelve volts.
Fig 6 — A series resistor is a heater that happens to set a current. At 5 V it wastes slightly more than the LED consumes; at 12 V it wastes four times as much. Above a few tens of milliamps this is the argument for a constant-current driver, not elegance.

Driving it straight from a microcontroller pin

The most common version of this circuit puts the supply end of the resistor on a GPIO. That works, and it introduces a resistance that is not on the schematic.

The ATmega328P datasheet (DS40002061B) guarantees an output high voltage of 4.2 V minimum while sourcing 20 mA from a 5 V supply at 85 °C, and an output low voltage of 0.9 V maximum while sinking the same. Read as a source impedance those are 40 Ω and 45 Ω. Put 40 Ω in series with the 150 Ω you fitted and the current falls from 18.7 mA to 14.7 mA — 21 % gone, into a part of the circuit that does not appear in the equation.

Three limits govern how many of these a part can drive, and the datasheet is explicit that they are separate:

DC Current per I/O Pin … 40.0mA DC Current VCC and GND Pins … 200.0mA

and, in the notes to the DC characteristics, the one that actually gets hit. For a pin that sources the LED current, as in this circuit:

The sum of all IOH, for ports C0 - C5, D0- D4, ADC7, RESET should not exceed 150mA.

and for the other common wiring — resistor to the 5 V rail, pin pulled low to sink the current — the same note gives a smaller figure:

The sum of all IOL, for ports C0 - C5, ADC7, ADC6 should not exceed 100mA.

Those are per-port-group budgets, and the groups are smaller than they look: ADC6 and ADC7 are analog inputs with no output driver, and RESET is the reset pin, so the sourcing group is eleven usable outputs. Eight indicators at 18.7 mA each is 149 mA — the whole 150 mA budget, with every individual pin comfortably inside its own 40 mA rating and the total still under the 200 mA supply-pin figure. Sink-wired, the six port-C pins alone are at 112 mA against a 100 mA limit. The constraint that fails is the one nobody looks up.

The practical answer is not a bigger pin. Modern LEDs at 2 to 5 mA are perfectly visible indicators — the red part above is specified at 120 mcd minimum at 20 mA, which is bright enough to be unpleasant to look at directly — and at 3 mA the pin’s own drop becomes negligible again.

The same load line drawn twice: once for an ideal five volt source and once for a microcontroller pin with the output resistance its datasheet implies. The pin version crosses the LED at a visibly lower current.
Fig 7 — What the datasheet's output-voltage specification does to the arithmetic. An ATmega328P pin guarantees only 4.2 V while sourcing 20 mA from a 5 V supply, which is an output resistance of 40 Ω in series with whatever you fitted — and it comes straight out of the current.
A stacked bar comparing the current drawn by a growing number of LEDs against three limits from the microcontroller datasheet: the per-pin absolute maximum, the per-port-group sum, and the total supply pin rating.
Fig 8 — The ceilings an ATmega328P datasheet sets, and where a bank of indicators meets each. The per-pin figure is the one everybody knows; the port-group sums are the ones that bite, because they are spent by pins that are individually well inside their own limit. Sourcing (pin high drives the LED) the group limit is 150 mA; sinking (resistor to 5 V, pin low) it is 100 mA.

Dimming: PWM is the only knob a resistor leaves you

With a fixed resistor the current is fixed, so the only remaining variable is time. PWM holds the peak at the design point and varies the duty cycle; the average current, the average power in the resistor, and the perceived brightness all scale with duty.

Two constraints set the frequency, and TI’s SLVA451 (Step-Down LED Driver With Dimming) states both while recommending about 100 Hz:

It must be kept low enough such that the turnon and turnoff delays of the TPS62150 do not significantly affect the dimming linearity. It also must be high enough to keep the LED flicker from being noticeable to the human eye.

The upper constraint is about the driver, not the LED; with a plain resistor and a GPIO the delays are nanoseconds and the frequency can be anything above the flicker threshold. A few hundred hertz is a safe floor, and higher is better if the LED will ever be seen in peripheral vision or through a moving camera shutter.

The alternative — analog dimming, reducing the current itself — is not available through a fixed resistor, and it is worse anyway for anything colour-critical: reducing an LED’s current shifts its forward voltage, its efficiency and, in phosphor-converted white parts, its colour point. PWM changes only how long the LED spends at the operating point it was designed for.

Two dimming methods drawn one above the other: a PWM waveform whose peak current stays at the design point while the duty cycle shrinks, and an analog method in which the current level itself falls. Only the PWM method keeps the LED at its designed operating point.
Fig 9 — PWM holds the current at its design point and changes only how long it flows, so the LED's colour and the resistor's dissipation stay where they were designed. TI's SLVA451 recommends about 100 Hz for dimming: fast enough not to flicker, slow enough that a driver's switching delays do not eat the duty cycle.

The derating nobody applies

Both Würth datasheets carry a derating curve on page 4 — forward current against ambient temperature — and it is not the front-page number. The 30 mA continuous rating holds flat from 0 °C to 50 °C. Above 50 °C the allowed current falls on a straight line, reaching about 14 mA at 85 °C, the top of the part’s own operating range, where the curve cuts off. Both parts share the same curve. Read at the points a designer cares about, the rating is 30 mA at 50 °C, about 28 mA at 55 °C, about 21 mA at 70 °C and about 14 mA at 85 °C.

The datasheets give no thermal resistance, but the power rating and the junction limit imply one, and it is worth computing to see what it means. The red 0603 is rated 72 mW at 25 °C ambient with a 95 °C junction limit, so:

θJA=TJ,max⁡−TAPdiss=95−250.072=972 °C/W\theta_{JA} = \frac{T_{J,\max} - T_A}{P_{\text{diss}}} = \frac{95 - 25}{0.072} = 972\ \text{°C/W}

which is an enormous thermal resistance, and entirely believable for a chip that size on two small pads — the same θJA-belongs-to-the-test-board problem that larger packages have, at a scale where it cannot be engineered away. The published 72 mW is exactly VF,max⁡×30 mAV_{F,\max} \times 30\ \text{mA}, and the blue part’s 105 mW is exactly 3.5 V×30 mA3.5\ \text{V} \times 30\ \text{mA}: the current rating and the power rating are the same statement at 25 °C.

Applied as a straight line from that 25 °C point, a single 972 °C/W would allow 17 mA at 55 °C and only 4.3 mA at 85 °C — about three times less than the vendor’s curve at the top of the range, and well below it at 55 °C, where the vendor still allows 28 mA. So the one-number model is a conservative estimate, not the derating; the vendor’s curve is the rating, and it is not a single-θJA line at all. Either way the direction is the same.

An indicator inside a sealed enclosure next to a regulator is not at 25 °C, and above 50 °C it is no longer a 30 mA part. That is one more argument for driving indicators at a few milliamps rather than at the number on the datasheet’s front page: at 3 mA the derating never arrives.

Allowable forward current against ambient temperature. The datasheet derating curve holds the 30 mA continuous rating flat to 50 °C and then falls on a straight line to about 14 mA at 85 °C, the top of the operating range, where it cuts off. A fainter straight line from 25 °C shows the more pessimistic estimate a single thermal resistance derived from the power rating would give.
Fig 10 — The derating nobody applies, from page 4 of both Würth datasheets: 30 mA is the rating only up to 50 °C ambient, and at the 85 °C top of the operating range the same part is a 14 mA LED. The fainter line is what the power rating and junction limit alone would imply — 972 °C/W, 4.3 mA at 85 °C — which is a conservative estimate, not the vendor's curve.

Current is not brightness

Even with the current held exactly, two LEDs of the same part number are not equally bright. The red 0603’s luminous intensity is specified from 120 to 250 mcd at 20 mA, and the blue 1206’s from 90 to 145 mcd — 2.08:1 and 1.61:1 respectively, at a single test current.

No resistor tolerance touches that. If a row of indicators has to look matched, the answer is a part sold in intensity bins, a per-channel PWM trim, or accepting the variation; it is never a tighter resistor. And it means the 2:1 current spread of the 3.3 V design above is, in visual terms, roughly the same size as the spread the part has anyway.

Bars showing the published luminous intensity range of two LEDs at a single test current. Both span roughly a factor of two, so parts driven at identical currents are not equally bright.
Fig 11 — The limit of what any current-setting circuit can do. At exactly 20 mA the red 0603 is specified from 120 to 250 mcd and the blue 1206 from 90 to 145 mcd — 2.08:1 and 1.61:1 with the current held perfectly. Matching brightness across a panel is a binning problem, not a resistor problem.

Two things a resistor cannot do

Share. Two LEDs in parallel on one resistor do not split the current evenly. The lower-VFV_F part takes more of it, heats up, drops further and takes more still. How much more depends on the slope of the LED’s I-V curve near the operating point — a number these datasheets do not publish, which is itself the argument: a circuit whose current split depends on an unpublished parameter is a circuit that should not be built. One resistor per LED, or one per series string.

Hold a current against a moving supply. The resistor’s current follows VSV_S one-for-one above the forward voltage, so it amplifies supply variation rather than rejecting it. On a single lithium cell falling from 4.2 V to 3.0 V, the 150 Ω design delivers 13.3 mA down to 5.3 mA — a 2.5:1 change in current, on a battery that is behaving entirely normally.

That is what a constant-current driver buys, and SLVA451 states the reason in one sentence:

Regulating the LED with a constant current for constant brightness is desired, rather than constant voltage regulation.

LED current plotted against supply voltage for two circuits: with a series resistor the current rises in proportion to the supply, while a constant-current sink holds it flat until it runs out of compliance voltage.
Fig 12 — What the resistor gives up. Its current tracks the supply one-for-one above the forward voltage, so a battery falling from 4.2 V to 3.0 V cuts the LED current by 2.5:1, from 13.3 mA to 5.3 mA; a current sink holds the design point until it runs out of headroom and then stops. TI's SLVA451 gives the reason plainly: constant current is what constant brightness needs.

When to stop using a resistor

The decision is not about elegance. Four thresholds, in the order they usually arrive:

  • Headroom under about 2 V, or under ten times the VFV_F bin’s half-width. Below that the current spread is set by binning and there is nothing you can do about it with passive parts.
  • Above roughly 50 mA, where the resistor’s dissipation stops being an 0603-sized problem and the LED’s own VFV_F shift with temperature starts to matter.
  • Battery supplies, where the rail moves over the discharge curve and the brightness moves with it.
  • Anything measured rather than looked at — an optical sensor’s emitter, a matched backlight, a calibrated indicator.

Everything else is a resistor, and choosing it is one subtraction and one division. Work the value and the worst-case band out in the LED resistor calculator, which stacks the supply, VFV_F and resistor tolerances the wrong way and reports the current range rather than the nominal, then check the headroom against Fig 3 before ordering the reel.