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.
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.
- 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.
- Example 2 will be 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