Why an LED needs a resistor, and how to size one
- 192parts on the bench
- 25boards running now
- 1.00xreal time, on every board
An LED is a diode. Below about 2 V it barely conducts at all, and just above that it will take as much current as the rest of the circuit lets through it, with almost no further rise in voltage. Left with nothing else in the loop, an LED wired straight across a 5 V supply asks for far more current than it or the supply is built to give. The job of the series resistor is to be the thing that actually limits the current, since the LED will not do it for you.
The math is Ohm's law with the LED's own drop subtracted first. Pick the forward voltage, call it 2 V for a common red or green LED, subtract it from the supply, and divide the rest by the resistor: (5 V - 2 V) / 220 ohm is about 13.6 mA, comfortably inside what a small indicator LED is rated for. Halve the resistor and the current roughly doubles; double it and the current roughly halves. There is no single correct value, only a range that is bright enough to see and safely under the LED's rated maximum.
The circuit above has two LEDs so you can see the same choice made twice, in different contexts. On the left, a pushbutton, an LED and a 220 ohm resistor sit in one loop with the supply: hold the button and the LED lights at that same 13.6 mA, and letting go opens the loop instead of turning the current down gradually. On the right, a 2 Hz clock drives another LED and resistor with no button and no processor at all, so you see the resistor doing the identical job on a signal that changes by itself.
Mokxi's LED is modeled as that forward drop plus a small dynamic resistance, not as an idealized switch, so the anode net actually sits near 2 V while current flows, and the probe you see is not the instantaneous state either: it is a short-lived average of it, weighted the way an eye actually perceives brightness, with a time constant of about 8 milliseconds. That is why a fast-blinking LED looks like a study in perceived brightness rather than a strobe, and it is also why a PWM-dimmed LED, on the page about PWM, looks like it is fading smoothly instead of flickering.
Try lowering the resistor value on either LED in the editor and watch the current climb. There is no burnout model here: a resistor picked far too small only shows up as an unrealistic current on the probe, which is a safe way to see the mistake without anything actually failing.
Want the step-by-step version? The lesson "A first circuit" walks through this with checkpoints.
Open the lessonBuild this for real
Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.