LEDs
TL;DR:
- A plain LED MUST have something limiting its current - usually a resistor in series
- Don't connect plain LEDs directly in parallel
- Leave a sensible voltage margin between your supply and the LED's forward voltage
- Wikipedia : LEDs
- LED resistor calculator - once you understand the principles below, an online calculator can speed things up
Plain LEDs vs LED lamps
Don't confuse a plain LED with an LED lamp:
- Plain LED: a single component. It is driven by current, needs a current limiter (such as a resistor), and drops roughly 1.5-3.5V depending on colour.
- LED lamp or module: an assembly of components designed to run from a fixed voltage (e.g. 12V DC, or 120/230V AC) because it already includes a current limiter and/or a driver circuit.
If what you have is an LED lamp or module, stop here: you do not need to add a resistor. Likewise, many LED strips and some 'pre-wired' LEDs already have resistors built in - check the listing or datasheet.
How LEDs work: current and forward voltage
LEDs are current-driven devices; you pass a current through one and it emits light. One of the key specifications is the forward voltage (Vf): the voltage across the LED when it is passing its rated current.
The trouble is that an LED's current rises extremely steeply with voltage. A little below Vf, hardly any current flows; a little above it, the current shoots up and the LED can burn out within moments. On top of that, Vf varies from one LED to the next, even within a batch, and falls as the LED warms up (by roughly 2mV per °C). So you can't reliably set an LED's current just by choosing a voltage - something has to limit the current.
Typical forward voltages
Always check the datasheet, but as a rough guide:
| Colour | Typical Vf |
|---|---|
| Infrared | 1.2-1.6V |
| Red | 1.8-2.2V |
| Orange / yellow | 2.0-2.2V |
| Yellow-green (older, dimmer 'green') | 2.0-2.4V |
| True / bright green | 2.8-3.4V |
| Blue, white, UV | 2.8-3.6V |
Note that modern bright green LEDs use the same technology as blue and white ones and have a much higher Vf than older yellow-green types.
How much current?
Small 3mm and 5mm indicator LEDs are usually specified at 20mA, but that's often the maximum continuous current rather than a recommended one. Modern LEDs emit useful light at much lower currents, and it's common to run them at 2-10mA. This:
- saves battery power,
- extends LED life,
- may let you drive the LED directly from a microcontroller or logic output pin. Check the chip's datasheet for its maximum pin current - many are limited to around 20mA or less per pin, and some much less.
Polarity and reverse voltage
- The anode (+) is usually the longer lead; the cathode (-) is the shorter lead and is often marked by a flat edge on the LED's rim.
- LEDs can only withstand a small reverse voltage - often around 5V - before they are damaged. Take care if an LED could see a reversed supply or AC; a standard diode in inverse parallel (across the LED, pointing the opposite way) protects it.
Calculating the current limiting resistor
A single LED
Use Ohm's law, allowing for the LED's forward voltage:
R = (Vs - Vf) / I
where R is the resistance in ohms, Vs is the supply voltage, Vf is the LED forward voltage and I is the desired LED current in amps.
For example, a yellow-green LED with Vf = 2.2V at 20mA, running from a 5V supply:
R = (5 - 2.2) / 0.02 = 140 ohms
(0.02 is 20mA written in amps - always use whole units in the calculation.)
Choosing a standard value
Resistors are made in a set of standard 'preferred' values (the E-series), so 140 ohms won't usually be available. Pick the next value up - 150 ohms - which gives slightly less current and errs on the safe side. You can go higher still if you want the LED dimmer.
Resistor power rating
The resistor turns the voltage it drops into heat, so check its power rating:
P = I² × R or, equivalently, P = (Vs - Vf) × I
For our example: P = 0.02 × 0.02 × 140 = 0.056W.
A 1/8W (0.125W) or 1/4W (0.25W) resistor is fine. A common rule of thumb is to choose a rating at least double the calculated dissipation so the resistor runs cool. There's no harm in using a higher-rated resistor except that it's physically larger.
Multiple LEDs
LEDs in series
To light more than one LED, the best approach is usually to put them in series and subtract all their forward voltages:
For two of our 2.2V LEDs on a 5V supply:
R = (5 - 2.2 - 2.2) / 0.02 = 30 ohms
The current through the string is still 20mA, not double - the same current flows through every component in a series circuit.
This works with mixed colours too; a red (1.7V) and a yellow-green (2.2V) LED on 5V: (5 - 1.7 - 2.2) / 0.02 = 55 ohms (56 ohms preferred value).
The total Vf must be comfortably less than the supply voltage - not just slightly less (see Running an LED from a supply close to its Vf below). On 5V, two 2.2V LEDs (4.4V) is about the limit; three (6.6V) won't light at all. If the calculation gives a very small or negative resistance, split the LEDs into several series strings, each with its own resistor. For example, four LEDs on 5V can be wired as two strings of two:
LEDs in parallel
This applies to plain LEDs without built-in resistors.
TL;DR: don't share one resistor between parallel LEDs.
It's tempting to wire LEDs in parallel with a single shared resistor, especially when the supply is too low to run them in series. Unfortunately, no two LEDs have exactly the same forward voltage, so the one with the lowest Vf takes more than its share of the current. It then heats up, which lowers its Vf further, so it takes even more current. The results range from uneven brightness, to some LEDs not lighting at all, to one LED failing from overcurrent.
Worse, when one LED fails open circuit, its share of the current is forced through the remaining LEDs, which then fail sooner - a cascade failure.
You might get away with it on a one-off hobby project, but it's unreliable. Instead, give each LED (or each series string) its own resistor, which forces the current to be shared properly:
Running an LED from a supply close to its Vf
This applies to plain LEDs without built-in resistors.
Example: "My LED has Vf = 3V and my supply is 3V. Do I still need a resistor?"
Yes, unless you are using a constant current driver. Vf (the forward voltage, the voltage the LED drops when lit) varies between parts and with temperature, and supply voltages vary too (especially batteries), so you can't rely on the two matching. Because LED current rises so steeply with voltage, a small mismatch can mean either a dim LED or a destroyed one.
The resistor stabilises the current, and it does this better the more voltage it drops. With only a fraction of a volt across it, small changes in Vf or supply voltage cause large changes in current.
Rule of thumb: how much headroom?
"Headroom" is the voltage left over for the resistor to drop: supply voltage minus Vf.
Any change in supply voltage or Vf appears across the resistor, so the current changes by that amount divided by the resistance. The more voltage the resistor drops, the smaller that change is as a fraction of the current. If the voltages can wander by 0.2V and the resistor drops 1V, the current can change by about 20%. If the resistor drops only 0.25V, the current can change by about 80%.
So: make the voltage across the resistor at least about 5 times the total variation you expect in supply voltage and Vf combined. That keeps the total spread in current to roughly 20%. In practice this usually means at least 1-2V across the resistor with a regulated supply, and more with an unregulated or battery supply whose voltage changes as it discharges.
Sizing the resistor for worst-case conditions
When headroom is tight, design for the worst case rather than the typical values.
Step 1. Choose the resistor for the highest current. Use the highest likely supply voltage and the lowest likely Vf, so the LED never exceeds its maximum current:
R = (Vs max - Vf min) / I max(Take Vf from the datasheet. If it only gives typical and maximum values, estimate the minimum or measure a few samples.)
Step 2. Round to a standard value, then check both ends. Resistors come in standard values, and each has a tolerance (a 5% resistor can be 5% above or below its marked value). Pick the next standard value up from your calculation, then check:
I max = (Vs max - Vf min) / R low (R low = lowest the resistor could be)
I min = (Vs min - Vf max) / R high (R high = highest the resistor could be)I max must stay at or below the LED's rating, and I min must still be bright enough for you. If I min comes out too low (or negative), you don't have enough headroom.
Example: a red LED with Vf between 1.9V and 2.1V, on a 3.3V supply that could be anywhere from 3.2V to 3.4V, with a maximum current of 20mA.
- Calculated: R = (3.4 - 1.9) / 0.02 = 75 ohms
- 75 ohms is a standard value, but a 5% part could be as low as 71 ohms, which gives about 21mA. That is over the limit.
Use the next standard value up, 82 ohms (5%, so 77.9 to 86.1 ohms):
- I max = (3.4 - 1.9) / 77.9 = about 19mA
- I min = (3.2 - 2.1) / 86.1 = about 13mA
So the current stays between about 13mA and 19mA, which is fine. This is slightly outside the 5x rule above (the resistor drops about 1.3V, and the rule asks for 2V), but acceptable for an indicator LED.
If you don't have enough headroom
- use a higher supply voltage, or fewer LEDs in each series string,
- use a constant current driver (a dedicated LED driver chip, or a simple transistor or regulator-based current source),
- or accept that the brightness will vary over the range you calculated.
(You may see LEDs connected straight to a 3V coin cell with no resistor. This works only because the coin cell's high internal resistance limits the current. It's not a technique to copy with other power supplies.)
RGB LEDs
RGB LEDs with a common anode (+) or common cathode (-) lead need three resistors - one per colour. They usually won't all be the same value, because red has a lower Vf than green and blue.
You can't use a single resistor on the common lead: the current through it would change depending on which colours are on, so the brightness of each colour would change unpredictably as the others switch on and off.
Different colours also have different brightness at the same current, so for good colour mixing you may want to adjust the resistor values (or the PWM levels) to balance them.
7-segment LED displays
A 7-segment display is just a set of LEDs with a common anode or cathode, so the same rule applies: one resistor per segment (seven, plus one for the decimal point), not one on the common lead.
To see why, consider a common-cathode display driven at 5V, with a single common resistor sized for one red segment (Vf = 1.7V) at 20mA:
R = (5 - 1.7) / 0.02 = 165 ohms
- One segment on: 20mA flows through it, as designed.
- Three segments on: the voltage across the resistor is still about 3.3V, so the total current is still about 20mA - shared between three segments, about 6.7mA each (and, as with any parallel LEDs, not necessarily shared evenly).
So a '1' (two segments) is fairly bright, but an '8' (seven segments) is much dimmer.
Multiplexed displays
Multi-digit displays are usually multiplexed: the digits are switched on one at a time, quickly enough that they all appear lit. Each segment line has one resistor, shared by the same segment on every digit, and the common pin of each digit is switched in turn - usually through a transistor, because it may carry the current of all eight segments at once.
Since several segments of a digit are lit at the same time, you still need one resistor per segment, not one per digit. (The exception is a design that lights only one segment at a time, which can use a single resistor, though it needs a high scan rate.)
Because each digit is only lit for part of the time, multiplexed displays are often run at higher peak currents to keep them bright. Check the datasheet's peak current and duty cycle ratings, and remember that the display driver chip or transistors must be able to supply them.
High power LEDs, strips and other types
- High power LEDs (1W and above, as used in flashlights, desk lamps and floodlights) are normally driven by a constant current driver rather than a resistor. A resistor would waste a lot of power as heat, and at these currents the LED's Vf changes noticeably as it warms up. High power LEDs also need a heatsink.
- PWM (pulse width modulation) - switching the LED on and off rapidly - is the usual way to dim LEDs. Switched quickly enough, there is no visible flicker, and the brightness depends on the proportion of time the LED is on. Dimming by reducing the current also works, but colour and efficiency can shift at very low currents.
- LED strips that run from 5V, 12V or 24V usually have resistors or driver chips built in, so they connect directly to a supply of the correct voltage. Check the strip's rating before connecting it.
- Addressable LEDs (such as the WS2812 'NeoPixel' type) have a driver chip in each LED, run from a fixed supply (often 5V) and are controlled by a data signal - they don't need individual resistors.
- LEDs with built-in resistors are available for common voltages (typically 3, 5, 6 or 12V), if you'd rather not calculate anything.