Here’s a simple circuit for driving LEDs at constant current. I like this one because it can be built with a variety of different components based on what you have on hand. I built my version with two 2N2222A transistors and a sense resistor from my resistor kit.
How does it work?
A small current on the CONTROL line causes the DRIVE transistor to switch on and sink through the SENSE resistor. The FEEDBACK transistor only operates when the voltage at the SENSE resistor is greater than its VBE, or turn-on voltage. When it turns on, it draws some current away from the base of the DRIVE transistor, reducing its gain and causing it to drop more voltage. This negative feedback will cause the whole system to equilibrate such that the SENSE resistor is seeing exactly the FEEDBACK transistor’s VBE.
Why is this better than a ballast resistor?
You can drive a variety of LEDs with different forward voltages without worrying about changing any of the components (provided that you are comfortable using the same current). The DRIVE transistor will just drop more or less volts as necessary.
Also, if you’re trying to drive some high-current LEDs, you’re more likely to have common transistors that can handle the power dissipation than you are to have high wattage resistors. This makes prototyping and experimentation easier.
Finally, depending on your LEDs and your power supply, you could end up using fewer components by driving multiple LEDs in a string, rather than driving each LED separately.
Sizing components and calculating current and power
LEDs: You can use as many LEDs as you’d like provided that their combined forward voltage is less than the supply voltage minus VBE.
Power supply: Your input voltage needs to be at least the sum of the forward voltages of your LED string plus the minimum drop across the DRIVE transistor plus the VBE of your FEEDBACK transistor. Otherwise there won’t be enough voltage to turn on the LEDs.
Transistors: Anything NPN (or N-channel, if you’re using MOSFETs) you have handy has the potential to work. The most important thing to think about is how much voltage you’re expecting it to drop for you and what that means for power dissipation. This transistor will be acting in its linear region, so any voltage it doesn’t pass on from collector to emitter will turn into heat! For instance, let’s use an example of a 12V power supply and two white LEDs with a 3.2V forward voltage. The drive transistor will have to drop 12 V – (2 * 3.2 V + 0.6 V) = 5 V. If your target current is, say, 200 mA, then the transistor will be dissipating 5 V * 0.2 A = 1 watt of power. For some transistors this is no problem, but for others that’s a death sentence. Read your datasheet!
Sense resistor: This resistor sets the amount of current you want to pass through the LEDs. You can compute its value by taking the VBE of your FEEDBACK transistor and dividing by desired current. For instance, if you’re using a 2n2222A transistor with a VBE of 0.6 V, and you want to sink 200 mA of current, you would need a 3 ohm resistor. Power dissipation is straight forward, since you know the voltage and the current. Using our existing example, a 3 ohm sense resistor would see 0.6 V * 0.2 A = 0.12 watts. That’s small enough that you can use 1/4 watt resistors from a part kit with little worry.