Just wanted to give something back to this great community:
Well, here's my LED driver, in fact 3 of them, one for each RGB channel. Each one will get its own thermal-shrinking insulation sleeve.
Red and black wires above are LED outputs, red and black wires below are power in, naked wire is the PWM switch input
This is a current source based on one N-MOSFET (T1) and one NPN transistor (T2):
The principle is very simple: the current that comes out from the Source pin of the T2 (S) must be the same as the one as enters the Drain pin (D), since current that enters the Gate (G) is zero. Therefore, by controlling the Source current we control the current through the LED, no matter the voltage on the LED. Setting the source current is fairly easy, since the BE voltage on a transistor is always around 0.5 V and the current that enters the T1 Base pin is also around zero. Therefore, the current through the R2 is Is=Ube/R2, that is R2=Ube/Is
So, if we want the current to be 700 mA, then the R2 has to be 0.5V/0.7A~0.7 Ohm! No matter the battery voltage, as long as it is above some 3.5 V, depending on the voltage on the LED. In practice, the current slightly depends on the input voltage, but does not depend at all on the diode voltage (or any consumer connected between Vcc and the Drain, for that matter), which is exactly what we need, since the diode voltage dramatically changes with the temperature. This way we completely override the problem with the changing voltage on the diode.
This is the Vcc-Current chart of the driver, driving one blue LED:
I used two 0,6 W resistors - 1 Ohm and 1.5 Ohm, resulting in 0.6 Ohm. Even though I used the same components in all the 3 drivers, the current varies from one to another from 0.70A to 0.73A - so you can see how it is hard to tweak. Fortunately enough, that does not affect the light intensity that much and it is still in the safe zone.
Now about switching the LED on and off: when the Gate pin is pulled up to Vcc, the Gate opens and the current flows. When the Gate is pulled down to 0V, the Gate closes and the current through the LED stops. That is done through a 100 kOhm resistor to minimize the pull-up current. By connecting it to a PWM signal from your controller, you can regulate the resulting current and the intensity of the light.
But, there is a caveat here - resistors that small are a pretty tricky thing to work with, because the very contact resistance between two wires ranges from 0.2 Ohm when not welded together (depending on the pressure used to hold them together and the properties of the wire) to around 0.05 Ohm when welded. And that's on each contact! So forget about testing it on a prototype board - you will just have to weld them directly on the other components as I did on the photo above, and tweak the resistors to get the right current.
Don't forget to insulate the pins with thermal-shrinking insulation sleeves to prevent wires from breaking off and short circuiting!
- T1 : any N-MOSFET with a T-220 package (IRFZ44N)
- T2 : any NPN transistor in a TO-92 package (BC337-40)
- R1 : 100 kOhm, at least 1/4 W
- R2 : 0.6 to 0.7 Ohm, at least 1/2 W - I used one 1 Ohm and 1.5 Ohm in parallel
Power dissipation considerations: Bare in mind that all the voltage difference between the input voltage and the voltage on the diode, minus 0.5 V on the R2, remains on the T1 FET, producing possibly significant heat (P = U * I). For example, if you power it with a 7V input and the voltage drop on the LED is 3.2V, then the remaining voltage on the T2 is 3.3V, producing 3.3*0.7 = 2,3 W which is quite much. If you keep it at 4.5V, then the power dissipation on T2 would be only about 0.5W. Therefore, keep the driver input voltage as low as possible!
Important note on pinout: The black output line is the floating one, while the red output is the same point as the power input! Therefore, when using several drivers in parallel, you must connect all the anodes of the LEDs to Vcc, and cathodes to the driver's black output line!
Important note on handling FETs: FETs (MOSFETs) are very sensitive components and are very easy to damage if you are not properly grounded. It is also likely that you'll burn it (electrically, not thermally) with your soldering iron. You'll now you did it if you notice that you cannot properly fade your LED: with a healthy MOSFET the light goes linearly up from 0 to 100%, while on a burnt one the LED will start lighting up at about 75% of PWM input level. Therefore, it is necessary to wrap all 3 pins with a piece of naked wire short-circuiting all pins, while you are soldering it. Once all the components are in place, you can wrap-off the short-circuiting wire.