The first circuit almost everyone builds when learning electronics is an LED, a resistor and a battery. Even so, "what resistor do I use?" is one of the most repeated questions, and getting it wrong is behind most burnt-out LEDs.
Why does an LED need a resistor at all?
An LED isn't like an ordinary bulb. Once the voltage across it passes a certain threshold called the forward voltage (Vf), the current through it rises very quickly with any small increase in voltage. Connect it straight to 5 V and nothing limits the current except the tiny internal resistance of the battery and wires, so the current rises until the LED burns out.
The series resistor's job is to set the current: it "takes" the voltage difference between the source and the LED.
The formula
From Ohm's law, the voltage across the resistor is the supply voltage minus the LED's forward voltage, and the current is the current you want in the LED:
R = (Vs - Vf) / I
- Vs: supply voltage (battery or power supply)
- Vf: the LED's forward voltage (from the datasheet, or roughly from the table below)
- I: LED current in amps (20 mA = 0.02 A)
Forward voltage by colour
These are approximate values for a standard 5 mm LED; the datasheet of the LED you actually have is always more accurate:
| LED colour | Approximate forward voltage |
|---|---|
| Red | 1.8 – 2.2 V |
| Yellow / orange | 2.0 – 2.2 V |
| Old-style green (yellowish) | 2.0 – 2.2 V |
| Bright green, blue, white | 2.8 – 3.3 V |
As for current, most 5 mm LEDs have a maximum continuous current of about 20 mA. In practice, 5 to 15 mA gives very good brightness and extends the LED's life, especially for indicators.
Example: a red LED on 5 V
- Vs = 5 V, Vf = 2 V, and we want 15 mA.
- R = (5 − 2) ÷ 0.015 = 200 Ω.
200 Ω isn't a standard value in the E12 series you'll find in any shop. The nearest values are 180 and 220. Always pick the larger value so the current goes slightly down rather than up: with 220 Ω the current becomes 3 ÷ 220 ≈ 13.6 mA, which is excellent.
Don't forget the power
The resistor heats up, and the power it dissipates is:
P = I² × R
In our example: 0.0136² × 220 ≈ 0.04 W, so an ordinary quarter-watt (0.25 W) resistor is more than enough. The practical rule is to choose a resistor rated at least double the power you calculated.
Another example: a white LED on 12 V
- Vs = 12, Vf = 3.1, I = 20 mA.
- R = (12 − 3.1) ÷ 0.02 = 445 Ω → nearest larger value 470 Ω.
- Actual current ≈ 18.9 mA, power ≈ 0.17 W.
Here 0.17 W is close to the quarter-watt limit, so it's better to use a half-watt resistor so it doesn't run hot, or reduce the current to 15 mA.
More than one LED
In series
If you chain several LEDs, add up their forward voltages and subtract the total from the supply. Three white LEDs on 12 V:
- (12 − 3 × 3.1) ÷ 0.02 = 135 Ω → use 150 Ω (current ≈ 18 mA).
Make sure the total forward voltage stays below the supply by a reasonable margin. If the difference is very small, any slight change in battery voltage will change the brightness a lot.
In parallel
A classic mistake: several LEDs in parallel sharing one resistor. Even LEDs of the same type differ slightly in forward voltage, so the one with the lowest Vf draws more current, heats up, its Vf drops further, it draws even more... until it burns out, and then the next one follows.
The simple fix: every LED in parallel gets its own resistor.
LEDs on an Arduino or ESP32 pin
Exactly the same formula, and Vs is the pin voltage: 5 V on the Uno and 3.3 V on the ESP32. But there's another limit to respect: the pin's own maximum current. An Uno pin can safely supply up to about 20 mA (40 mA is an absolute limit you shouldn't approach), and ESP32 pins are weaker.
- Red LED from an Uno pin: (5 − 2) ÷ 0.01 = 300 → 330 Ω (about 9 mA).
- White LED from an ESP32 pin: (3.3 − 3) ÷ 0.01 = 30 Ω!
The second example shows a problem: the gap between 3.3 and 3 V is so small that any slight variation in the LED's Vf changes the current a lot, and the LED may be dim or not light at all. Here it's better to use about 68 to 100 Ω and accept less brightness, or drive the LED from 5 V with a transistor. That's also the solution if you want to drive several LEDs at once, because the total current of all the pins has a limit too. Details in the articles on Arduino pin limits and the transistor as a switch.
RGB LEDs
An RGB LED is three LEDs (red, green and blue) in one body, and each colour needs its own resistor, because red has a Vf of about 2 V while green and blue are about 3 V. On 5 V at 10 mA: red 330 Ω, green and blue about 200 Ω (220).
There are two types: common cathode (the long leg goes to ground and each colour turns on with HIGH) and common anode (the long leg goes to positive and each colour turns on with LOW). If the colours come out inverted in your code, you probably have the other type. Each colour's brightness is controlled with PWM.
Power LEDs (1 W and up)
A 1 or 3 W power LED runs at 350 mA or more. Here a resistor is a poor solution: it wastes a lot of heat, and the LED's own Vf drops as it warms up, so the current rises, so it heats more. The right approach is a constant current driver that holds the current steady whatever the voltage does, plus a heatsink, because a power LED without cooling dies quickly. Read the heatsink article.
Ordinary 12 V LED strips have the resistors fitted at the factory; you connect them straight to 12 V with no calculations. Smart LED strips are a story of their own in the WS2812B article.
LED not lighting?
- Polarity: the long leg is positive (anode), and the flat side of the LED body is negative (cathode). An LED connected backwards usually won't burn out on 5 V, it just won't light.
- Test it with a multimeter: in diode mode (the diode symbol), red probe on the long leg. Most LEDs will glow faintly and the display will show roughly the Vf. See the multimeter article.
- Resistor far too large: a kilohm instead of 100 Ω, for example, gives a very dim light. Read the colours correctly with the resistor colour code article.
- The LED was damaged earlier: an LED that ran without a resistor even for a second may be weak or open.
Summary
- Find the forward voltage and the right current from the datasheet.
- Calculate R = (Vs − Vf) ÷ I.
- Pick the nearest larger standard value.
- Calculate the power and choose a resistor rated at least double that.
And if you don't want to calculate by hand every time, the LED resistor calculator does all these steps and gives you the nearest standard value and the power straight away.
FAQ
Can I run an LED without a resistor on a 3 V coin cell? It sometimes works because the small battery's high internal resistance limits the current, which is the secret behind keyrings with an LED and a coin cell. But on any strong source, such as a power supply or power bank, you need a resistor.
Does the resistor go before or after the LED? It doesn't matter. In series the current is the same everywhere, so the resistor limits it from either side.
Why is a blue LED dimmer than a red one with the same resistor? Because its Vf is higher, so less voltage is left across the resistor and the current is lower. Calculate each colour separately.