I am following this excellent page as a guide: http://teachmetomake.wordpress.com/how-to-use-a-transistor-as-a-switch/
Using it, I worked through my use case of an raspberry pi connected to a TIP120 to drive a 12V LED light.
diagram from http://ctheds.wordpress.com/2007/10/30/tip-120/
What value of resistor should I use? I’ve seen several different values on web examples, so looks like I need to actually understand something rather than just cut’n’paste!!
So, my load uses 12V and lets say 300mA of current (I don’t know the actual value yet, but it will be around there).
Looking at the datasheet we can see from top line on the graph in figure 2 that when the collector current (IC) is 300mA then the voltage at the base (VBE) will be about 1.3-1.4V. Lets say 1.4V because this way we are heading in the direction of handling more current, i.e. getting a bit of a fudge factor safety margin.
So knowing that the voltage across the base needs to be 1.4V, and the pi puts out 3.3V logic high, the resistor will have a voltage across it of 1.9V.
The bottom line on the graph tells us that at the collector current (IC) of 300mA, the collector voltage is 0.5V. In other words, the transistor itself will ‘drop’ 0.5V across it, the rest of the supply voltage (12V) is presented across the load. So the lights will get a little bit less voltage (11.5V) than they are used to, but they should still work fine. If this voltage dropout is a problem I’ll have to use a relay or some other more exotic solution like an ultra-low dropout transistor
Also given in the corner of figure 2 on the datasheet is the current ratio at saturation, which is IC=250IB. So IB=IC/250, with our load of 300mA that gives a base current IB of 1.2mA. To be safe, we’ll make sure that we actually drive the transistor a bit harder than that, so that we can get it into saturation quickly and fully, say at 2.5mA.
So the resistor needs to pass 2.5mA and it has 1.9V across it. Ohm’s law says V=IR and therefore R=V/I; 1.9/0.0025= 760Ω/.
Next value up is 820Ω, will allow 2.3mA to pass, close enough, and still well over our calculated saturation point. The next resistor value down in the standard series is 680Ω – which would allow 2.8mA to pass and would also be just fine. So I’ll use whichever one of those is handy. I will investigate using a 10k pull down resistor on the base to ensure that the transistor is switched off when the raspberry pi is in a high impedance state (perhaps during booting), not sure if that will be necessary or not.