FreeCircuitSim
April 20269 min readIntermediate

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 Simulator
Advertisement

Transistor Switch Topology

graph TD VCC["Vcc"] --> LOAD["Load"] LOAD --> C["Collector"] C --> NPN["NPN Transistor"] NPN --> E["Emitter"] --> GND["GND"] CTRL["Control (GPIO)"] --> RB["Base Resistor RB"] RB --> B["Base"] --> NPN style VCC fill:#1a3a4a,stroke:#00e5ff,color:#00e5ff style CTRL fill:#2a2a1a,stroke:#ffaa00,color:#ffaa00 style GND fill:#161b1f,stroke:#5a7080,color:#5a7080

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:

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).

I_B_min = I_C / h_FE
Minimum base current to guarantee saturation
R_B = (V_in - V_BE) / I_B
V_BE ≈ 0.7V for silicon NPN. Drive I_B at 5-10× I_B_min for reliable saturation.

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

FeatureNPN BJT (e.g. 2N2222)N-channel MOSFET (e.g. 2N7000)
Control methodCurrent (base current)Voltage (gate voltage, no current)
Gate/Base currentRequires ~1–10mANear zero steady state
On resistanceV_CE_sat ≈ 0.2VR_DS_on typically < 0.1Ω
Good forSmall loads, simple circuitsHigher currents, efficiency
Simulate N-MOSFET Switch

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.

Frequently Asked Questions

How do I calculate the base resistor for an NPN transistor switch?
Calculate minimum base current: I_B_min = I_C / h_FE. Then drive at 5-10× that for reliable saturation. Base resistor R_B = (V_in - 0.7V) / I_B. Example: 100mA load, h_FE = 100, drive at 2mA: R_B = (5-0.7)/0.002 = 2.15kΩ.
Why do I need a diode when switching a motor or relay?
Inductive loads (motors, solenoids, relays) generate a large reverse voltage spike when switched off as their magnetic field collapses. A freewheeling diode placed in reverse across the load provides a safe path for this energy, protecting the transistor.
What is the difference between saturation and cutoff in a transistor switch?
Cutoff is the OFF state: no base current, no collector current, transistor acts as open circuit. Saturation is the ON state: sufficient base current causes transistor to fully conduct, V_CE drops to about 0.2V, acting as a closed switch.
Keep Going
Ready to simulate this yourself?
Open the free simulator — no account, no download needed.
⚡ Open Simulator →
📍 Step 8 — first real IC
Continue Learning →
Next up: 555 Timer Circuit
Next: 555 Timer Circuit →

Related Guides

← Back to All Guides