# Current Limiting Inputs Into Microcontroller

Discussion in 'Microcontrollers, Programming and IoT' started by KMor, Jul 17, 2015.

1. ### KMor

2
0
Jul 17, 2015
Hi all,

I am new to electronics so please excuse the simplicity of this question.

I want to power an LED with 15mA using a 5V supply. To limit the current I am using a 330R resistor and that is fine. I am switching the resistor on by outputting a low signal direct from an IO output of my microcontroller. I need to limit the current into the micro to approx. 5mA based upon the total current the micro can sink and the total number of LEDs I am controlling so can I add an additional current limiting resistor at the input pin of the micro to drop the remaining voltage (after taking into account the voltage drop across the LED) and therefore bring the current down to 5mA (I have calculated the use of a 560R based on LED Voltage Drop of 2.7V)?

I know I could set up the circuit in other ways such as switching a series of transistors to GND to light the LEDs or using Port Expanders and I2C or such like but I need to really limit the number of components due to space limitations so I thought my simple current limiting idea might work?

KMor

2. ### Harald KappModeratorModerator

10,609
2,370
Nov 17, 2011
I'm a bit confused.
You want to "power an LED with 15mA", but you want to "bring the current down to 5mA". Assuming you want to achieve the latter to stay within the limits of the µC, you get R=V/I where V=Vcc-Vout_low(µC)-Vled and I=Iled=5mA.
With Vcc=5V, Vled=2.7V, Vout_low(µC)=0V (worst case for this scenario) you have V=2.3V and therefore R=460Ω.
Use high brightness LEDs to get sufficient light from the LED at 5mA.

3. ### KMor

2
0
Jul 17, 2015
Thanks for your reply Harald, that makes sense. I think I was getting confused as to what exactly I was trying to achieve but I appreciate you clearing it up.

Cheers

KMor

4. ### Minder

3,020
640
Apr 24, 2015
A ULN2803/4 etc would not take up much more room than a bank of resistors.
M.

Arouse1973 likes this.
5. ### Harald KappModeratorModerator

10,609
2,370
Nov 17, 2011
You need the resistors in addition to the ULN...

6. ### AnalogKid

2,415
686
Jun 10, 2015
Yes, you need the LED current limiting resistors no matter how they are driven. But you don't need base current resistors for the 2003 (as opposed to individual driver transistors), and you can easily run 50 mA or more per LED if you want. Even if the micro is rated to handle 5 mA per output, running it there will decrease long-term reliability. If you can make room for it, consider a ULN2003/2803 mentioned above as a group LED driver. Let the micro be the micro and a power part be the power part.

For standard, garden-variety LEDs, assume 2.1 V Vf for green, 1.8 V Vf for red. If you use a ULN2003/2803, add 0.7 V Vcesat. For a 5 V rail, a green LED, and 15 mA, this works out to:

R - (5 - 2.1 - 0.7) / .015 = 150 ohms

ak