Sub topic 7
Why the LED needs a resistor, and how to size it
This chapter assumes you know what voltage, current and resistance are at an introductory level, and that you can read a basic Arduino sketch. You do not need to have built the circuit yet. The next chapter covers the breadboard wiring.
What goes wrong without a resistor
An LED (light-emitting diode) is not like a light bulb. A bulb's filament resists current by itself, so connecting it to a supply gives a modest, stable current. An LED behaves differently. Once the voltage across it reaches its forward voltage, it starts conducting, and a very small rise in voltage above that point produces a very large rise in current.
The consequence is simple. If you connect an LED directly between an Arduino pin and ground, the only thing limiting the current is the pin's own small internal resistance. The current can exceed what the LED tolerates, what the pin tolerates, or both. A standard 5 mm LED is typically rated for about 20 mA continuous current. An ATmega328P pin, as on the Uno, has an absolute maximum of 40 mA, and a recommended continuous limit nearer 20 mA. Boards based on other chips have different limits, so check your board's datasheet.
A series resistor fixes this. Because current in a series circuit is the same through every component, a resistor in line with the LED sets the current for both. The resistor absorbs the voltage that the LED does not use.
The three quantities you need
Sizing the resistor needs three numbers.
- Supply voltage (Vs). The voltage on the pin when it is HIGH. This is 5 V on an Uno and 3.3 V on many newer boards, such as the Nano 33 series and ESP32 boards.
- Forward voltage (Vf). The voltage the LED drops across itself while conducting. It depends on the LED's color and chemistry. It is found in the LED's datasheet or, failing that, estimated from the table below.
- Target current (I). The current you want through the LED. Many indicator LEDs reach good brightness at 5 to 15 mA, and 20 mA is a common maximum.
Typical forward voltages for 5 mm LEDs at around 20 mA:
| LED color | Typical Vf |
|---|---|
| Red | 1.8 to 2.0 V |
| Yellow | 2.0 to 2.2 V |
| Green | 2.0 to 3.2 V |
| Blue | 3.0 to 3.4 V |
| White | 3.0 to 3.4 V |
These ranges are wide because manufacturers differ. Treat them as estimates, and use the datasheet value if you have it.
Ohm's law applied to the circuit
Ohm's law states that the voltage across a resistor equals the current through it times its resistance:
V = I × R
In the LED circuit, the supply voltage divides between two parts. The LED takes Vf. The resistor takes whatever remains, which is Vs − Vf. The same current I flows through both. Substituting into Ohm's law and solving for R gives the sizing formula:
R = (Vs − Vf) / I
The diagram shows how the voltage is shared.
A worked calculation
Suppose you use a red LED with Vf = 2.0 V on a 5 V Uno, and you want 15 mA.
- The resistor must drop Vs − Vf = 5 − 2.0 = 3.0 V.
- The current is 15 mA, which is 0.015 A.
- R = 3.0 / 0.015 = 200 Ω.
Now check the same LED on a 3.3 V board at 10 mA:
- Voltage across the resistor: 3.3 − 2.0 = 1.3 V.
- Current: 0.010 A.
- R = 1.3 / 0.010 = 130 Ω.
The same LED needs a different resistor on a different supply.
Choosing a real resistor value
Resistors are sold only in standard values. The common E12 series includes 100, 120, 150, 180, 220, 270, 330, 390, 470, 560, 680 and 820 Ω, with multiples of ten above those. You will rarely get exactly the calculated value, so pick a standard value.
Always round up to the next available value, not down. A larger resistance means less current, which is the safe direction. For the 200 Ω result above, the next standard value is 220 Ω.
You can then work backward to find the actual current:
I = (Vs − Vf) / R = 3.0 / 220 ≈ 13.6 mA
That is a little under the 15 mA target and still clearly bright. Many tutorials use 220 Ω or 330 Ω for red LEDs on 5 V, because both give a safe and visible result with common parts. With 330 Ω the current is 3.0 / 330 ≈ 9.1 mA. It is dimmer, but entirely safe.
Reading the color bands
Through-hole resistors are marked with colored bands. For a typical four-band resistor, the first two bands are digits, the third is a multiplier, and the fourth is tolerance.
| Value | Band 1 | Band 2 | Band 3 (multiplier) |
|---|---|---|---|
| 220 Ω | Red | Red | Brown |
| 330 Ω | Orange | Orange | Brown |
| 470 Ω | Yellow | Violet | Brown |
| 1 kΩ | Brown | Black | Red |
If you are unsure, measure with a multimeter set to resistance, with the resistor out of the circuit.
Checking power dissipation
A resistor converts the energy it absorbs into heat. The power it dissipates is:
P = I × V = I² × R
For the 220 Ω resistor at 13.6 mA:
P = 0.0136 × 3.0 ≈ 0.041 W, or about 41 mW
Common through-hole resistors are rated for 1/4 W (250 mW), so this is well within the limit. In LED circuits at these currents the power rating is almost never a problem, but it is worth knowing how to check it.
Does the resistor go before or after the LED?
It does not matter electrically. The resistor and LED are in series, so the same current flows through both, and the order does not change that current. Place the resistor on either side of the LED. Many people put it on the anode side, between the pin and the LED, because it reads naturally from the pin onward. The LED's polarity still matters, as covered in the previous chapter.
What happens at different resistor values
Choosing a value is a trade-off between brightness and safety. The table shows the result for a red LED (Vf = 2.0 V) on 5 V.
| Resistor | Current | Result |
|---|---|---|
| 100 Ω | 30 mA | Above the 20 mA rating. Too much for the LED and the pin. |
| 150 Ω | 20 mA | At the limit. Bright, with no margin. |
| 220 Ω | 13.6 mA | Bright and safe. A good default. |
| 470 Ω | 6.4 mA | Clearly visible, noticeably dimmer. |
| 1 kΩ | 3.0 mA | Dim, but often still visible indoors. |
| 10 kΩ | 0.3 mA | Barely visible or dark. |
Perceived brightness does not rise in proportion to current, so halving the current does not halve what you see. This is why a modest margin below the maximum costs little in appearance and adds a good deal of safety.
Verifying the current with code
You can test your reasoning on the board. This sketch switches an LED on pin 8 on for two seconds, then off for two seconds, so you have time to measure with a multimeter in series with the LED. With the resistor you calculated, the reading should be close to your predicted current.
const uint8_t LED_PIN = 8;
void setup() {
pinMode(LED_PIN, OUTPUT);
}
void loop() {
digitalWrite(LED_PIN, HIGH);
delay(2000);
digitalWrite(LED_PIN, LOW);
delay(2000);
}Expect small differences. The actual pin voltage under load sags a little below 5 V, and the real Vf of your LED may differ from the table. A reading within 10 to 20 percent of the prediction is normal.
Common errors
- Using the wrong supply voltage in the formula. A 3.3 V board gives a different result from a 5 V board. Check what your board outputs.
- Forgetting to subtract Vf. Dividing the full supply voltage by the current gives a resistor that is too large. The LED will work but be dimmer than planned.
- Mixing units. Convert milliamps to amps before dividing. 15 mA is 0.015 A. Forgetting this gives a result 1000 times too large.
- Rounding down to a standard value. Round up so that the current stays at or below your target.
- Driving too many LEDs from the chip. Each pin has its own limit, and the chip has a total limit across all pins. On the ATmega328P, the datasheet gives a total of 200 mA across all I/O pins. Several bright LEDs on separate pins can approach it.
- Sharing one resistor between parallel LEDs. With one resistor feeding several LEDs in parallel, the LEDs do not share current evenly, because small differences in Vf shift the balance. Give each LED its own resistor.
Connecting this to the blink program
The resistor has no effect on the sketch itself. The code only decides whether the pin is HIGH or LOW. The resistor determines how much current flows during the HIGH periods. This separation is useful when you troubleshoot. If the LED is dim, the cause is likely in the circuit values, not in the code. If the LED never changes state, look at the code, the pin number, or the wiring.
Exercise
You have a green LED with Vf = 2.1 V, a 5 V board, and you want about 10 mA through the LED. What is the calculated resistor value, which standard E12 value do you choose, and what current results with that choice?
Show answer
The resistor must drop 5 − 2.1 = 2.9 V. R = 2.9 / 0.010 = 290 Ω. Round up to the next standard value, 330 Ω. The resulting current is 2.9 / 330 ≈ 8.8 mA, which is slightly below the 10 mA target and safe.
Exercise
A student uses a 100 Ω resistor with a red LED (Vf = 2.0 V) on a 5 V pin. What current is intended to flow, and why is this a problem even though the LED lights up?
Show answer
I = (5 − 2.0) / 100 = 0.030 A, or 30 mA. This exceeds the typical 20 mA LED rating and is above the recommended continuous current for an ATmega328P pin. The LED lights up, but it can overheat, lose brightness over time or fail, and the pin is stressed. A resistor of at least 150 Ω is needed, and 220 Ω gives a safer margin.
Exercise
A resistor in an LED circuit drops 3.0 V and carries 13.6 mA. How much power does it dissipate, and is a 1/4 W resistor adequate?
Show answer
P = I × V = 0.0136 × 3.0 ≈ 0.041 W (41 mW). A 1/4 W (250 mW) resistor is far more than adequate.