When the LED current is greater than the pin's current.

Is it OK to connect a 20 mA LED to a 5 mA pin?

An indicator LED datasheet says it has 20 mA Continuous Forward Current.
A micro-controller datasheet says its pins are 5 mA.
The LED will be powered by the micro-controller pin.
Would connecting the LED to the micro-controller pin harm the pin?
Should the LED have a current limiting resistor?

Thank you.

wolfv:
Is it OK to connect a 20 mA LED to a 5 mA pin?

An indicator LED datasheet says it has 20 mA Continuous Forward Current.
A micro-controller datasheet says its pins are 5 mA.
The LED will be powered by the micro-controller pin.
Would connecting the LED to the micro-controller pin harm the pin?
Should the LED have a current limiting resistor?

Thank you.

Which microcontroller? Most AVR chips can supply up to an absolute max of 40mA, and 20mA is a safe level.

If the micro can really only supply 5mA safely, you can't drive the LED with it. You'd need to use a transistor, switched by the micro.

And LEDs always need a current-limiting resistor. That's the law.

OldSteve:
Which microcontroller?

Teensy LC has 4 - 20mA pins and 19 - 5mA pins.

Teensy LC has 4 - 20mA pins and 19 - 5mA pins.

Then use the 20mA pins, you cannot use the 5mA ones. If you can't use the 20mA pins you'll have to add some hardware.

wolfv:
Teensy LC has 4 - 20mA pins and 19 - 5mA pins.

Right, an ARM-Cortex processor. Is 20mA the absolute maximum current, or the safe maximum. If it's the safe maximum, try to do as Graynomad suggests, otherwise use an NPN small-signal transistor with it's base switched by the Teensy. A BC548 or similar would do nicely.

A 2K7 to 4K7 resistor could be used between the output pin and the base of the transistor, then if also powering the LED from 3.3V, the series resistance is calculated: R = ((3.3V-Vce(sat)) - Vf)/0.02 , where Vf is the LED's forward voltage and Vce(sat) is the voltage between the transistor's collector and emitter when it's turned on. (For such a small load, Vce(sat) can really be ignored.)

So if the LED Vf is 2.0V, the series resistance would be: R = (3.3-2.0)/0.02 = 65Ω. A 68Ω resistor would do the trick.

Can a current limiting resistor limit the current to 5mA?
A dim LED would be OK.

pin Supply Voltage Vs = 3.3
LED Forward Voltage Vf = 2.2
pin Current If = 5 mA
R = (Vs - Vf) / If = 220 Ohms

wolfv:
Can a current limiting resistor limit the current to 5mA?
A dim LED would be OK.

pin Supply Voltage Vs = 3.3

LED Forward Voltage Vf = 2.2
pin Current If = 5 mA
R = (Vs - Vf) / If = 220 Ohms

Yep. As long as 5mA is the safe maximum and not the absolute maximum.

OldSteve:
Yep. As long as 5mA is the safe maximum and not the absolute maximum.

What is the difference between "safe maximum" and "absolute maximum"?

Safe maximum means can be used continuously at this level
Absolute maximum means any transient greater than this level will cause damage

Thanks OldSteve and Jackrae.

wolfv:
Can a current limiting resistor limit the current to 5mA?

And note, you should never run a led without current limiting, in it's simplest form a resistor. Not even on the 20mA pins. And modern leds are very bright at 20mA so as an indicator 2mA is probably more then enough.