Embedded Systems
What resistor does an LED need on an Arduino?
An LED on a 5 V Arduino pin needs a series resistor, usually 220 Ω to 1 kΩ. To pick one, take the LED's forward voltage from 5 V and divide by the current you want, then remember the pin has about 25 Ω of its own inside. A red LED at 10 mA needs about (5 − 2) ÷ 0.01 − 25 = 275 Ω, so a standard 270 Ω.
Why it needs one
An LED keeps a nearly fixed voltage across itself, and above that its current rises steeply. Nothing inside it holds the current back. On a bare 5 V pin, only the pin's 25 Ω limits it, and a red LED tries to draw around 100 mA: past the LED's rating and far past the pin's 40 mA damage limit. The resistor sets a safe current for both.
Live experiment
The LED still needs a resistor
Pin 9, a 220 Ω resistor and Pip, a red LED, back to GND. Switch pin 9 HIGH and about 12.5 mA flows. Take the resistor out and see what about 100 mA does. Then flip Pip round.
“An LED on a pin” is lesson 3 of 6 in Blink Bay, Embedded Systems World 1. Free with an account. Lessons unlock in order, so you’ll do the 2 before it first.
Currents at a glance
Forward voltages vary by colour: about 2.0 V for red, 2.2 V for green, 3.2 V for blue and white. From a 5 V pin, counting its 25 Ω:
| Resistor | Red (2.0 V) | Green (2.2 V) | White (3.2 V) |
|---|---|---|---|
| 220 Ω | 12 mA | 11 mA | 7.3 mA |
| 330 Ω | 8.5 mA | 7.9 mA | 5.1 mA |
| 1 kΩ | 2.9 mA | 2.7 mA | 1.8 mA |
All of them sit under the pin's safe 20 mA. Most modern LEDs are bright at 5 to 10 mA, so 220 Ω or 330 Ω suits a light you want to see across a room, and 1 kΩ is plenty for a status indicator.
Work one out
A green LED (2.2 V) on pin 9 through 150 Ω:
Still under 20 mA, so it's safe, if bright. Leaving out the pin's 25 Ω gives a slightly bigger answer, 18.7 mA, so the quick estimate errs on the safe side.
Wire it the right way round
- The LED's longer leg, the anode, faces the pin, through the resistor
- The shorter leg, the cathode, by the flat edge of the case, goes to GND
- The resistor can sit on either side of the LED: it's one loop with one current
Backwards, the LED doesn't light, and nothing is harmed. Then pinMode(9, OUTPUT) in setup() and digitalWrite(9, HIGH) turn it on.
Free lesson
Now build it yourself
Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.
“An LED on a pin” is lesson 3 of 6 in Blink Bay, Embedded Systems World 1. Free with an account. Lessons unlock in order, so you’ll do the 2 before it first.
Or start from the very first lesson, no account neededWork it out
Practice questions
Three quick questions from the lessons. Pick an answer to check it.
Show the answer
Answer: The GND pin. GND is the board's − end. Every loop that starts at a pin ends there, like the loop back to a battery's − terminal.
- Why not “The 5V pin”? The 5V pin is a supply, a + end. Current from an output pin returns to the board's − end, GND.
- Why not “The USB cable”? The USB cable powers the board, but your circuit's current comes back in through the GND pin.
- Why not “Pin 13”? Pin 13 is just another output. The loop closes through GND, which every circuit on the board shares.
Show the answer
Answer: Nothing in the LED holds the current back. An LED straight on a pin takes far too much current and burns out, and can harm the pin too. The resistor keeps the flow gentle.
- Why not “LEDs are too bright otherwise”? It's not about brightness: without a resistor the current runs far past the LED's rating and damages it.
- Why not “Resistors make it blink”? The blinking comes from the code switching the pin. The resistor only sets how much current flows.
- Why not “The pin is too weak”? The pin isn't too weak for a bare LED; it's too strong. The resistor limits the current it can push through.
Show the answer
Answer: Stays dark. An LED only lets current through one way, from its long leg to its short leg. Backwards, nothing flows, so it stays dark (and doesn't burn out either).
- Why not “Blinks”? Blinking needs the code to switch the pin. Backwards, the LED stays dark whatever the pin does.
- Why not “Glows”? An LED conducts only from its long leg to its short leg. Backwards, no current flows, so it can't glow.
- Why not “Burns out”? With no current flowing, nothing heats it. Reversed on a 5 V pin, the LED just stays dark.
“An LED on a pin” is lesson 3 of 6 in Blink Bay, Embedded Systems World 1. Free with an account. Lessons unlock in order, so you’ll do the 2 before it first.
Questions people ask
Is 220 Ω or 330 Ω better for an LED on an Arduino?
Both are safe on a 5 V pin. 220 Ω gives a red LED about 12 mA and 330 Ω about 8.5 mA. Modern LEDs are bright at a few milliamps, so 330 Ω, or even 1 kΩ for an indicator, is usually plenty and kinder to the pin.
Does the resistor go before or after the LED?
Either side works. The pin, resistor, LED and GND form one loop with one current, so the resistor limits it wherever it sits.
Which leg of an LED goes to the Arduino pin?
The longer leg, the anode, faces the pin. The shorter leg, on the side with the flat edge, is the cathode and goes to GND. Backwards, the LED simply stays dark.
Related topics
- How much current can an Arduino pin supply?About 20 mA per pin: what that runs, what it doesn't, and how a transistor takes the load.
- Ohm's law explainedV = I × R: set any two of voltage, current and resistance and the third follows.
- How does a diode work?A one-way valve for current: anode, cathode, the 0.7 V forward drop and Schottky diodes.
- The Arduino Blink sketch, explained line by lineFour lines that blink an LED, the sum behind the blink rate, and what happens when it's too fast to see.