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.

Example 1

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.

References

  1. Excellent tutorial on using transistors as a switch, but I’m not convinced they addressed properly the issue of reduced gain in saturation
  2. Much more concise tutorial containing less theory and more practical
  3. Example showing how to create an H-bridge using transistors

TO DO:

  • 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

10 Responses to “How to Use A Transistor as a Switch”

  1. sakshi Says:

    nice..:)

  2. Mike Says:

    “Ic=250 * Ib”
    Why?
    TIP120 has hfe of 1000

    • michaelshiloh Says:

      Very good question, and understanding this is at the heart of working effectively with transistors as switches. The answer is pretty simple: Hfe of 1000 is only in the linear or active range. When the transistor is used as a switch we want it to be in saturation which minimizes the collector-emitter voltage drop Vce. Determining Hfe in saturation is not easy: it depends so much on the collector current and other factors. Some datasheets have graphs, but most sources I found recommend using a very conservative value of 10 (yes, only ten) to assure that the transistor is in saturation. Why then did I use 250? Look at Figure 2 in the datasheet. In the top right corner is this equation: Ic = 250 * Ib.

      If you are interested in understanding this further let me know and I’ll try to dig out some of the references I used. I’m pretty sure one of my sources was “The Art of Electronics”.

  3. Abraham Says:

    Yes, I’m interested in that reasoning too. Why is that equation provided in the graph? Is 1000 the “theoretical” gain while 250 is the more practical and more “safe” value to use?

    • michaelshiloh Says:

      The equation and the graph only apply when the transistor is operating in the linear or active region. When used as a switch, we want to drive it from cutoff to saturation as quickly as possible, so the information for the active region does not appy.

  4. Bo Says:

    Sorry, might be a stupid question but why do you choose 1A in the last step? Shouldn’t this be 1.25A?

    • michaelshiloh Says:

      Never apologize for a question! Not stupid at all. In this case the answer is quite simple. If you look at Figure 2 you’ll see that it doesn’t have a whole lot of precision, and there is a good line at 1A, so I used that to get in the ballpark. I guess I could have bumped Vbe(sat) up to 1.6V to allow for this. I should make this correction to avoid confusing others. Good call!

      In the end, though, you won’t find a perfect 175 Ohm resistor anyway – you’ll use a lower standard value to assure that there is enough current to drive the transistor well into saturation. The 175 Ohms that we calculated should be considered the maximum resistance.

      Good question.

  5. Mark Says:

    Sorry, but i have an additional question. In the datasheet of the PN2222A transistor there isn’t a figure with a formula like Ic/Ib = 10. I noticed that it is missing in more datasheets of different kind tranistors. How do i know what de Base current must be to keep de tranistor saturated?

  6. michaelshiloh Says:

    No apologies! That’s a good question.

    A good rule of thumb is to assume a worst case current gain of 10, so your steps should be:

    1. Calculate the maximum collector current you must deliver. Check that your transistor can handle this.
    2. Calculate Ib = Ic/10. This is your minimum base current required for saturation Ib(sat)(min)
    3. Make sure your controller can deliver that Ib(sat)(min)
    4. Check the datasheet for the maximum base current the transistor can handle Ib(max), and use a base resistor to limit Ib to something between Ib(sat)(min) and Ib(max)

    Don’t hesitate to ask if you have more questions

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


%d bloggers like this: