Skip to content
You Start with one site
Amounts in Start with one site
Electronics · Concept

Transistor as a switch

One idea Beginner 5 min read
Found this useful?

Your hand turns a small valve handle, and a large flow of water starts or stops. A microcontroller pin can give only a few milliamps (about 8 mA on an STM32F103, 20 mA on an ATmega328P), which is far too little for a relay or a motor. A transistor used as a switch is that valve: a small current from the pin controls a large current through the load.

BaseThe handle. A small current goes in here from the pin.A few mA
CollectorThe load connects here. The large current comes in.70 mA and more
EmitterBoth currents leave here, to ground.0 V

See it

Predict first

A 3.3 V pin drives a transistor through a base resistor. The transistor has a current gain of 75, and its relay needs 70 mA. Someone fits a 10,000 Ω base resistor to protect the pin. What happens?

See it: a pin, a transistor and a relay

Base current
Load current
Heat in the transistor

The thin line into the base is the small current from the pin. The thick line through the relay is the large current it controls. The bar shows where the 5 V goes: a transistor that is fully on keeps only 0.2 V for itself. Make the base resistor too large and the transistor keeps much more, which the relay loses.

The idea

A common transistor has three legs: the base, the collector and the emitter. A small current into the base lets a much larger current flow from collector to emitter. The current gain, written β, is how many times larger: at least 75 for the 2N2222.

A switch must be fully off or fully on. With the pin at 0 V no base current flows, and the transistor is off. To turn it fully on (engineers say saturated), give the base 3 to 10 times the load current divided by β. Then only about 0.2 V stays across the transistor. The base resistor sets the base current:

RB = (VGPIO − VBE) ÷ IB

RB is the base resistor, VGPIO the pin voltage, VBE the 0.7 V the base keeps, IB the base current you want

This is the bipolar transistor. The other family, the MOSFET, is turned on by a voltage and takes almost no current from the pin. The rule is the same: fully on or fully off.

One worked number

The question

A relay coil draws 70 mA from 5 V. A 2N2222 transistor (β at least 75) switches it from a 3.3 V pin. What base resistor turns the transistor fully on?

Show the worked solution, 3 steps
  1. Find the smallest base current that could work

    IB = IC ÷ β = 70 mA ÷ 75 = 0.93 mA.

  2. Add a margin

    About five times the minimum makes sure the transistor is fully on: use 5 mA.

  3. Find the resistor

    RB = (3.3 V − 0.7 V) ÷ 0.005 A = 2.6 V ÷ 0.005 A = 520 Ω. Buy 470 Ω or 560 Ω. The figure opens at 520 Ω: the relay has its 70 mA.

The mistake to avoid

A transistor is not fully on because the load does something. With too little base current the relay may still click weakly, so the circuit looks alive. But the transistor is partly on, a large voltage sits across it, and that becomes heat. In the figure, 10,000 Ω makes five times the heat of 520 Ω while the relay gets less than a third of its current. Use the minimum gain from the datasheet, and add the margin.

A second trap: a relay or motor is a coil, and a coil makes a high voltage when its current stops. A diode across the coil protects the transistor.

Check yourself

Question 1

An LED strip draws 200 mA. The transistor has a minimum gain of 100 and the pin gives 5 V. You want five times the minimum base current. Which base resistor?

Question 2

A small motor runs slowly from its transistor, and the transistor is too hot to touch. The motor runs at full speed when connected straight to the supply. What is the most likely cause?

Question 3

A datasheet gives the current gain of a transistor as 75 minimum and 300 typical. Which value do you use to choose the base resistor?

Where you meet it

  • Relays and valvesThe controller of a pump, a cold room or an irrigation valve switches each coil through a transistor.
  • Motors and fansA MOSFET carries 0.5 A to a 12 V fan and wastes about 10 mW, so it needs no heat sink.
  • LightingLED strips take several amperes. A pin switches them through a MOSFET, often with PWM to dim them.
Key points
  • A small base current controls a large load current. The pin never carries the load.
  • A switch is fully off or fully on. Partly on means heat in the transistor and a weak load.
  • Minimum base current = load current ÷ minimum gain. Give 3 to 10 times that.
Found this useful?

Discussion

    Comments show your name. Be kind, stay on the topic.