How to Use A Transistor as a Switch
How to use a transistor a switch (work in progress)
1. Let’s assume you want to switch a motor or a light bulb. The first step is to determine the voltage and current of the load, the thing you are trying to control.
In the case of the motor, if you know where it came from, you can look up the specifications on the manufacturers website. If you don’t know where it came from, you might have to take a guess or make some measurements.
For a light bulb, the voltage and wattage is usually printed on the bulb. To calculate the current, simply divide the wattage by the voltage. For example, a 12VDC light bulb rated at 24 Watts draws 24W/12V = 2 Amps.
- Can your transistor handle the load current through its collector?
- Can the transistor handle the supply voltage?
- Find the worst case current gain during saturation.
- Calculate the minimum base current needed to keep the transistor in saturation, using this worst case current gain and the load current
- Compare this base current to the maximum current your microcontroller (or other controlling circuit) can deliver.
- Find the very highest (worst case) Vbe.
- Calculate the voltage drop across the base resistor using Vbe and the controller output voltage.
- Calculate the required base resistor.
- Calculate the collector power dissipation
Jameco 400995 DC gear motor. According to the datasheet for this motor, at 12VDC with no load it only draws 76 mA, but if you stall the motor it shoots up to 1250 mA, or 1.25 Amps. A motor always consumes the maximum current when stalled.
Thus the load voltage is 12VDC and the maximum load current is 1.25 A
Vload = 12V
Iload(max) = 1.25A
In general, we can use both PNP or NPN transistors as switches. However, PNP transistors can only control the same voltage as is supplied to the Arduino chip. In this case, since the voltage we are controlling (12 V) is different from the Arduino voltage (5 V), we have no choice but to use an NPN transistor.
Next, we see what NPN transistors we have in our box of parts. Let’s pretend we have a PN2222A, a TIP31 and a TIP120.
Next, we need to check the datasheet for each transistor.
First we need to make sure that the transistor can safely handle the worst current we might draw. The parameter we are looking for is the maximum collector current, Ic(max).
The datasheet for the PN2222A shows Ic(max) = 0.6 A, which is too little for our needs.
The datasheet for the TIP31 shows Ic(max) = 3 A, which is safely above the 1.25 A our motor will draw if it is stalled. So the TIP31 is a contender.
Next we have to verify that the transistor can safely handle the supply voltage we plan to use. The parameter we are looking for is the maximum collector emitter voltage, Vceo(max).
The TIP31 comes in 4 versions, with Vceo(max) ranging from 40 V to 100 V, all safely above the 12 V we plan to use. So the TIP31 is still a contender.
Now we need to calculate whether we can provide sufficient base current to keep the transistor in saturation. First we need to find what the base current will be when the transistor is carrying the worst-case current of 1.25 A. According to Figure 2, Ic/Ib = 10 or Ic = 10 * Ib. This means that for our collector current of 1.25 A, we would need to deliver a base current of .125 A, which is too much for our Arduino, which can deliver (safely) at most 40 mA.
Finally let’s take a look at the datasheet for the TIP120. First, we see that Ic(max) = 5 A, and that Vceo(max) is 60, 80, or 100 V, so we are fine so far.
Next we check the base current. Again this is indicated in Figure 2, but this time Ic=250 * Ib or our collector current of 1.25 A requires a base current of 5 mA (5 * 250 = 1250), which is well below the maximum of 40 mA the Arduino can put out.
Finally we need to select a base resistor which will be low enough to ensure that the TIP120 remains saturated, but high enough to prevent the Arduino from trying to deliver more current than it should. We want a current between 5 mA and 40 mA, so let’s pick a midway point of 20 mA.
Back to Figure 2 where we see that when the collector current is 1 A, Vbe(sat) is about 1.5 V. Now if the Arduino is putting out 5 V, and Vbe is 1.5 V, that means that the resistor has a voltage drop of (5 – 1.5) or 3.5 V across it. Using Ohm’s law, R = V/I = 3.5/(20 mA)= 175 Ohms.
This example is from an excellent discussion here. To summarize: A strip of LEDs requires 400 mA at 12 volts, and is to be controlled from a Raspberry Pi.
A TIP120 is proposed.
- Can the TIP120 handle the load current? According to the first page of the datasheet, in the table titled “Absolute Maximum Ratings”, the maximum collector current Ic is 5A, well above our requirements.
- Can the transistor handle the 12V required? According to the same table as above, Vceo(max) is 60V, well more than we need.
- Find the worst case current gain during saturation. Note that on page 2 of the datasheet, the DC current gain hfe is quoted at 1000 minimum, but this is at Vce=3V, which is not saturated, so we can’t use that value. Instead, look at Figure 2 on page 3. In the top right corner of this graph is Ic = 250 Ib, so let’s use that value. This seems much higher than the worst case default we use of 10, but given this is a Darlington pair (2 transistors, one after the other), it’s not unreasonable.
- Calculate the minimum base current needed to keep the transistor in saturation, using this worst case current gain:
Ib = Ic/250 = 400 mA / 250 = 1.6 mA.
- Compare to the maximum current an output of the Raspberry Pi can deliver. There is some confusion over this, but as discussed on this page 1.6mA seems safe.
- Find Vbe. According to the graph in Figure 2, Vbe(sat) is below 1.5V all the way up to 1A, so by choosing a worst case Vbe(sat) of 1.5V we should be extremely safe.
- Now we calculate the voltage drop across the base resistor. The output voltage of the Raspberry Pi is 3.3V, so the voltage drop across the resistor is
3.3V – 1.5V = 1.8V
- Now we calculate the base resistor. Recall that the minimum base current we need to drive the transistor into saturation is 1.6 mA so
R = V / I = 1.8V/1.6mA =~ 1.2K ohm
- Finally, we should calculate the collector power dissipation, because it’s worse for a Darlington due to the higher Vce(sat). Using Figure 2 again, we see that Vce(sat) is about .75V, so the collector power dissipated is:
Pc(max) = Ic(max) * Vce(sat)(max) = 400mA * .75V = 0.3 W.
According to the “Absolute Maximum Ratings” table on page 1, the maximum power dissipation is 2W when the ambient temperature Ta = 25C, so we should be safe here as well.
- Excellent tutorial on using transistors as a switch, but I’m not convinced they addressed properly the issue of reduced gain in saturation
- Much more concise tutorial containing less theory and more practical
- Example showing how to create an H-bridge using transistors
- We have calculated this for the worst case current draw, which is when the motor is stalled. How does our transistor switch perform with the motor is operating at the other extreme, the no-load current of only 76 mA? How do we verify that the transistor is still saturated, i.e. turned on?
- This example of course requires a freewheeling diode, which will be added when I add the schematics.
- Include an example of a 2N2222 followed by a TIP31, to show how multiple stages can be used.
- Discuss briefly why we didn’t use a PNP transistor, and when it is appropriate to do so.
- Add schematics and diagrams from fritzing