Transistor as a Switch — NPN BJT Switching Circuit
A transistor used as a switch is one of the most practical electronics skills. It lets a microcontroller or logic signal (5V, a few milliamps) control high-current loads like motors, solenoids, and LED strips. This guide covers the NPN BJT switch in detail.
Open Transistor Switch SimulatorTransistor Switch Topology
How Transistor Switching Works
An NPN BJT has three terminals: Base (B), Collector (C), and Emitter (E). In switch mode, the transistor operates in two states:
- Cutoff (OFF): No base current → no collector current → switch is open. Load is off.
- Saturation (ON): Sufficient base current → transistor fully conducts → switch is closed. V_CE drops to ~0.2V. Load receives full supply voltage.
The load connects between the collector and the supply voltage. The emitter goes to ground. The control signal drives the base through a resistor.
Calculating the Base Resistor
To ensure the transistor saturates (fully turns on), the base current must be at least I_C / h_FE, where h_FE is the transistor's current gain (typically 100–300 for common transistors like the 2N2222 or BC547).
Example: Switching a 100mA LED strip from a 5V Arduino pin. h_FE (2N2222) = 150. I_B_min = 100mA/150 = 0.67mA. Drive at 3× = 2mA. R_B = (5 - 0.7) / 0.002 = 2,150Ω. Use 2.2kΩ standard value.
Protecting Against Inductive Loads
When switching inductive loads (motors, solenoids, relay coils), always add a freewheeling diode (also called a flyback diode) in reverse across the load — cathode to supply, anode to collector. When the transistor turns off, the magnetic field in the inductor collapses and generates a large voltage spike that would destroy the transistor without this diode.
Common diodes for this: 1N4007 (general purpose, up to 1A), 1N4148 (signal diode, up to 300mA).
NPN vs PNP for Switching
NPN transistors switch the low side (load between supply and collector, emitter to ground, control signal to base). This is the most common configuration for microcontroller use. PNP transistors switch the high side (load between emitter and ground, collector to ground). PNP requires the control signal to pull the base LOW to turn on, which is less intuitive for microcontroller use — an NPN or N-channel MOSFET is usually preferred.
MOSFET vs BJT for Switching
| Feature | NPN BJT (e.g. 2N2222) | N-channel MOSFET (e.g. 2N7000) |
|---|---|---|
| Control method | Current (base current) | Voltage (gate voltage, no current) |
| Gate/Base current | Requires ~1–10mA | Near zero steady state |
| On resistance | V_CE_sat ≈ 0.2V | R_DS_on typically < 0.1Ω |
| Good for | Small loads, simple circuits | Higher currents, efficiency |
Common Beginner Mistakes
No Base Resistor
Connecting the base directly to the control voltage without a series resistor draws too much base current, potentially exceeding the transistor's maximum base current rating and destroying it.
Transistor Not Saturating
If base current is insufficient (base resistor too high), the transistor stays in the active region rather than saturating. V_CE won't drop to 0.2V — the load doesn't receive full supply voltage and the transistor dissipates significant heat.
No Flyback Protection on Inductive Loads
Every motor, relay, and solenoid needs a flyback diode (1N4007) across the load in reverse polarity. The inductive kick when switching off can be 10× the supply voltage and will destroy the transistor immediately.
Wrong Transistor Type
NPN transistors switch the low side (emitter to ground). PNP transistors switch the high side (emitter to Vcc). Using the wrong type means the control logic is inverted and the switch may never fully turn on.