Electronics Intermediate: Power, Transistors, Op-Amps and Logic
Transistors as Switches
In this lesson you will
- Explain how a transistor switches a load
- Calculate a base resistor for saturation
- Compare bipolar transistors and MOSFETs, and protect against inductive spikes
Introduction
The transistor is the most important invention in electronics. Billions sit inside every computer chip. For hobby projects, the most common use is as an electronic switch: a small signal from a microcontroller turns a larger current on and off, for an LED strip, a motor or a relay.
The simple explanation
A transistor is a valve for current. A small current into one pin lets a much bigger current flow between two others.
The NPN bipolar transistor
An NPN bipolar junction transistor (BJT) has three pins:
- Base (B): the control input
- Collector (C): where the load current enters
- Emitter (E): where it leaves, connected to ground
Roughly: when a small base current flows (and the base is about 0.7 V above the emitter), a much larger collector current can flow. The ratio is the current gain, β (often 100 or more, but it varies a lot between parts and conditions).
An NPN transistor switching an LED. The input drives the base through a resistor.
Choosing the base resistor
To use a transistor as a switch, you want it fully on, called saturation. A safe rule of thumb is to supply a base current of about one tenth of the collector current.
For the circuit above:
LED current (collector current) ≈ (5 − 2) ÷ 150 = 20 mA
Base current ≈ 20 mA ÷ 10 = 2 mA
Base resistor = (5 − 0.7) ÷ 0.002 = 2150 Ω → use 2.2 kΩWith 2.2 kΩ, the base current is (5 − 0.7) ÷ 2200 ≈ 1.95 mA. When the input is 0 V, no base current flows, and the LED is off.
The base resistor is essential. Without it, the base-emitter junction acts like a diode and passes too much current, damaging the transistor or the driving pin.
Quick quiz
Why is a resistor always placed in series with the base of a switching transistor?
Check the ratings
Look at the datasheet for:
- Maximum collector current (for a small-signal transistor, often around 100 to 800 mA)
- Maximum voltage between collector and emitter
- Power dissipation, because a transistor that is not fully on gets hot
- Current gain at the current you use
For heavier loads, choose a power transistor or a MOSFET, with a heatsink if needed.
MOSFETs
A MOSFET is controlled by voltage at its gate, with almost no gate current. N-channel logic-level MOSFETs switch well from a 3.3 V or 5 V microcontroller pin and can handle large currents with very low resistance when on, so they stay cool.
- Check that the gate threshold is low enough for logic-level drive.
- A small resistor in series with the gate and a large pull-down resistor (such as 10 kΩ) from gate to ground keep it off when the control pin floats.
- MOSFETs are sensitive to static and over-voltage.
PNP and high-side switching
A PNP transistor (or a P-channel MOSFET) works with opposite polarities, and is used to switch the positive side of a load. It is slightly more complicated, since the control signal must be pulled up to switch it off.
Inductive loads need a flyback diode
Relays and motors are inductors. When they switch off, the collapsing field creates a large voltage spike. Put a flyback diode across the load, with its cathode toward the positive supply, so the spike is safely absorbed. Without it, the transistor can be destroyed.
Troubleshooting
- Load always on: the transistor may be wired in backwards, or the base is floating or too high.
- Load never on: the base resistor is too high, the emitter is not grounded, or the pins are mixed up. Look up the pinout, since packages differ.
- Transistor hot: it is not saturating, or the load current is too high.
Try it yourself
Design a transistor circuit to switch a 12 V relay coil of 60 mA from a 5 V microcontroller pin. Calculate the base resistor for a base current of 6 mA, which is (5 − 0.7) ÷ 0.006 ≈ 720 Ω, so choose 680 Ω. Draw it with a flyback diode.
Summary
- A small base current lets a larger collector current flow, so a transistor can switch a load.
- Use a base resistor sized for about one tenth of the collector current to saturate it.
- MOSFETs switch with voltage and handle more current, and flyback diodes protect against spikes from relays and motors.
Lesson complete
+20 XP
Nice work. Keep going while it is fresh.
Sources and further reading