I am working on a project where I need to light up to seven LEDs from a single micro-controller pin. I know that is not something that can generally be done, but I was looking at LEDs and found this one that lists If as 2mA. If I understand everything correctly, I should be able to use a 1k resistor and have it work fine. Since I rarely understand everything correctly, I am wondering what I am missing.
Modern microcontrollers can typically output up to 50mA or so on each pin but there's usually a limitation on the total output on all pins, like for example 100-150mA through all output pins. The maximum current on each pin and overall also goes down with voltage: for ex a microcontroller may do 50mA per pin with 5v input, but only 20mA per pin if powered with 3.3v..3.6v
It's safer to just assume around 10-15mA maximum on each output pin.
If you want to use a single resistor to limit the current, you can use this formula to limit the current :
Input voltage - ( number of leds in series x forward voltage of led ) = Current (in A) x Resistance value.
So for example, if you have
2 red leds with a forward voltage of
2v and you power everything using
5v and you want to limit at
5mA then:
5v - (2 leds x 2v) = 0.005A (5mA) x R
so R = (5-4) / 0.005 = 1 / 0.005 = 200 ohms , so you'd use either two 100 ohm resistors in series, or 210 ohm (less current) or 180 ohm (a big higher current)
7 leds is a bit odd.. if you can make it 8 then you can make 4 pairs of 2 leds in series, so then you'll have 4x the minimum current, 2x the forward voltage to deal with.
Below is a transistor tutorial, how to use one transistor to turn on or off something. Very easy for beginners to understand.
Remember though, don't use the transistor to actually limit the current to the leds, use the transistor like an on/off switch.
You'll still need a resistor to limit the current.