# Control LEDS with PWM and transistors

I have three transistors that are each connected to 5 LEDs like so.

I am attempting to increase and decrease the current through the LED's in a linear fashion by increasing the current in the base of the transistor. So if I decrease the 3mA to 1.5mA, I want the LED current to go from 16.25mA to 8.125mA. However, currently this setup does not do this. The current in the LEDs does not significantly decrease until the current source is a small percentage of its current value.

The 3mA sources in my diagram are modeling the pwm outputs of a microcontroller. (Their max current.) I need to control the brightness of the LEDs by changing the duty cycle of each PWM.

I'd rather not have to use a LED driver. I'm also aware of the use of lookup tables to correct the exponential factor. Is that my only option?

• What is the $h_{fe}$ of the transistors? – Ignacio Vazquez-Abrams Apr 24 '15 at 21:52
• It's the 2N2222 so I believe its about 50. But I could be wrong. – codedude Apr 24 '15 at 21:57
• You're going to want to switch to something with better power handling; the transistors are going to start to burn as you pull them out of saturation. – Ignacio Vazquez-Abrams Apr 24 '15 at 22:02
• Any recomendations? – codedude Apr 24 '15 at 22:05
• A bit of searching finds the PHE13005, but the voltage handling is a little overkill. – Ignacio Vazquez-Abrams Apr 24 '15 at 22:20

## 1 Answer

Your problem is pretty straightforward. Your current limiting resistor is much too large. If your LEDs are in fact allowing as much current as you assert, the voltage across the resistor will be .08 x 30, or 2.4 volts. This leaves (at most) 0.9 volts across the LEDs, and that is not enough to allow them to produce much light at all.

You should resize your resistor, taking into account the forward voltage (Vf) of the LEDs, to allow maximum current with transistor fully on, and a transistor voltage drop of about 0.1 to 0.2 volts. Either that, or increase your source voltage.

Once you do that, you're still likely to have problems. With 5 LEDs in parallel, whichever one has the smallest Vf will hog current and glow more brightly than the others. In the worst case, this will cause it to get hotter, its Vf will drop, and it will hog even more current and get even brighter. At this worst-case limit, it will draw nearly 5 times as much current as you expect. If this level is too high, the LED may fail open, leaving the process to repeat in turn with the other 4, then the other 3, etc.

Finally, you need to examine the data sheet for your transistor and determine its current gain. This is the hfe which Ignacio referred to his comment. To make life more difficult, gain changes with current level, as you will see if you pay attention to the data sheet. But let's say that the gain is 100, which is a decent starting point for modern NPN signal transistors running at less than 100 mA. Keep in mind that, due to your large limit resistor, the current will never approach the 80 mA you think it will. Let's say 10 mA, just as a start. Then any base current above (10 mA / 100) will make no difference to the LED current, since the transistor is pulling as much current as it can, and the current is limited by the resistor and the LEDs. 10 mA/100 is 0.1 mA, or 3% of your nominal drive, and is entirely consistent with what you see.

In order to check this, fire up your circuit and connect the collector of your transistor to ground. Now measure the voltage across the 30 ohm resistor, and divide by 30, to give your total, maximum current. Divide this by 10 or so to get the base current you need. To understand why you divide by 10 rather than 100, start learning about transistor saturation.