Why do I need a resistor when using LEDs on an Uno?

Arduino UNO.

I'm picking up my Uno again after a long time not using it. I thought I'd revisit the starter kit manual and rigged up some LEDs on pins 11, 12, and 13. Like the manual shows, I have some resistors before the LEDs and everything works fine. I pulled out the resistors and the LEDs still continue to work. I'm just a bit puzzled then, why the resistors are needed at all?

Power to the Uno is via the USB cable which I believe provides 5v input to the board?

I also understand the LEDs operate upto 30mA?

Am I exposing my LEDs to damage by not having the resistors? I left the Uno and the sketch running for over 24 hours and the LEDs really do seem to be working okay.

The resistors are to keep the led’s from drawing too much current.

if an LED is rated for 30mA and it is supplied 5v by an arduino pin,
then 5v*30mA = 166.6 ohm resistor will keep the led from drawing more than 30mA.

without the resistor the led will be able to draw much more current than that and will eventually damage the led and the arduino since the led is rated for 30mA and the arduino a max of 40mA

Thanks for the nice explanation. I didn’t know LEDs could pull seemingly, “unlimited” current in which case the resistors make sense.

"Shockley diode equation"

Diodes are non-linear components, highly non-linear.

I didn't know LEDs could pull seemingly, "unlimited" current in which case the resistors make sense.

Diodes (including LEDs) are non-linear. That is, their resistance changes with the applied voltage. Below the "breakdown" voltage ("operating" voltage for an LED) there is a lot of resistance and almost no current flows. Above the breakdown voltage, the resistance becomes almost zero and you'll get as much current as the Arduino (or other circuit) can provide.* You'll exceed the Arduino's I/O specs and/or the LED specs and one of those components might be damaged.

By limiting the current with a resistor (or other current-limiting circuit) and operating the LED at the correct current, the correct voltage "falls into place" and the remaining voltage is dropped across the resistor.

if an LED is rated for 30mA and it is supplied 5v by an arduino pin,
then 5v*30mA = 166.6 ohm resistor will keep the led from drawing more than 30mA.

It's true that you cannot get more than 30mA with a 166 Ohm resistor connected in series. But you'll actually get less. With about 2V dropped across the LED, you'll have about 3V dropped across the resistor and about 18mA through the resistor. That same current flows through the LED.

  • Under these over-current conditions, you'll no longer be getting 5V from the Arudino's I/O pins... If the Arduino survives and the LED is still working, you'll be getting a little more than the LED's operating/breakdown voltage.

Interestingly, a friend of mine bought a little starter kit, and hooked up the LED without a resistor. It was really bright, but apparently the Arduino, with its 40 ma. nominal current limit per pin, wasn't quite up to smoking it.

But, the output pin has been stressed and will some day cause problems and then, the question is why?

Hutkikz:
then 5v*30mA = 166.6 ohm

You mean / not *....

And as DVDdoug points out, the 5V should actually be ~3V, since ~2V are dropped over the LED.

Modern LEDs are pretty bright at very low currents btw, even under 10mA on some I have is blinding.

jrdoner:
Interestingly, a friend of mine bought a little starter kit, and hooked up the LED without a resistor. It was really bright, but apparently the Arduino, with its 40 ma. nominal current limit per pin, wasn't quite up to smoking it.

40 nominal is incorrect. 40 is the absolute maximum. 20 would be nominal.

That number in the data sheet does not describe the short circuit current, which isn't specified. It describes the absolute maximum allowable current. Notice that output voltages are specified at 20 mA.

LEDs are mostly cheap enough to be expendable. Not always so, is the Arduino. But it's really about learning to design things you can be confident will continue to work.

The output FETs on ATmega pads (that means the part of the chip connected to a pin) are about
30 to 40 ohms when on. This means currents of > 100mA will flow if the output is shorted, well
above the absolute maximum value. Use 150 ohms in series with a pin and you limit the max current
to under 30mA (for 5V supply) into a shorted output. You can routinely use such protection resistors on
outputs if you want (I think the Ruggeduino takes this approach?).

The principle reason for the abs max current rating is that the output transistors will overheat and
be destroyed - they are tiny on-chip transistors and can only take about 50mW (by my calculations).
Remember we are talking tiny fractions of a square mm for such things on a chip.