FreeCircuitSim
April 2026Guided SimulationIntermediate

Build a Transistor Switch — Step by Step

A transistor switch lets a small control signal (from a microcontroller, sensor, or button) turn a much larger load on and off. It is the basis of motor drivers, relay drivers, LED arrays, and every digital-to-analog interface in embedded systems.

What you will learn: How NPN transistor switching works, how to calculate the base resistor, how to protect against inductive spikes, and how to test the circuit in the simulator before touching a real breadboard.

Circuit Diagram

graph TD VCC["Vcc (+5V or +9V)"] --> LOAD["Load (LED / Motor / Relay)"] LOAD --> COL["Collector (Pin C)"] COL --> NPN["NPN Transistor (2N2222 / BC547)"] NPN --> EMIT["Emitter"] EMIT --> GND["GND"] CTRL["Control Signal (MCU GPIO / 5V)"] --> RB["Base Resistor (RB)"] RB --> BASE["Base (Pin B)"] BASE --> NPN LOAD --> FD["Flyback Diode (if inductive)"] FD --> VCC style VCC fill:#1a3a4a,stroke:#00e5ff,color:#00e5ff style CTRL fill:#2a2a1a,stroke:#ffaa00,color:#ffaa00 style GND fill:#161b1f,stroke:#5a7080,color:#5a7080

Step-by-Step Guide

STEP 1
Know Your Load Current

Before calculating anything, establish how much current the load draws. Example: switching a 9V LED strip drawing 100mA.

💡 A transistor switch is like a tap controlled by a trickle of water: A small flow into the base (the tap handle) allows a much larger flow from collector to emitter (the main pipe). Turn off the trickle, the main flow stops instantly. That's current amplification — controlling big currents with tiny ones.
  • Supply: 9V
  • Load current (I_C): 100mA = 0.1A
  • Control signal: 5V GPIO pin (max 40mA output, we will use ~5mA)
Why this first? Everything else — the transistor choice, base resistor, and flyback diode — depends on I_C. Always start with the load, not the transistor.
STEP 2
Choose the Transistor

For 100mA you need a transistor with I_C(max) well above 100mA. The 2N2222A handles 600mA; the BC547 handles 100mA (right at the limit — use 2N2222 for safety margin). Check two specs:

  • h_FE (DC current gain): typically 100–300 for signal transistors. We will use h_FE = 100 (conservative).
  • V_CE(sat): voltage drop across transistor when fully on, typically 0.2V.
▶ See NPN Transistor
STEP 3
Calculate the Base Resistor

The transistor saturates (fully on) when I_B ≥ I_C / h_FE. We drive extra base current (overdrive factor of 5×) to guarantee saturation even with component variation:

I_B_min = I_C / h_FE = 100mA / 100 = 1mA

I_B_target = 5 × I_B_min = 5mA

R_B = (V_control - V_BE) / I_B = (5V - 0.7V) / 0.005A = 4.3V / 0.005 = 860Ω → use 820Ω standard value

⚠️ Common mistake: Using h_FE from the datasheet's best-case figure. Always use the minimum h_FE at your operating collector current. It drops significantly at high currents. The 5× overdrive factor compensates for this.
STEP 4
Add the Flyback Diode (for inductive loads)

If your load is a motor, relay, solenoid, or buzzer — anything with a coil — you must add a flyback diode. Connect it in reverse across the load (cathode to Vcc, anode to collector). A 1N4007 is perfect for most applications.

When the transistor turns off, the collapsing magnetic field in the coil generates a reverse EMF voltage spike — sometimes 10× the supply voltage. Without the diode, this spike destroys the transistor.

Real-world use: Every Arduino motor shield, relay module, and solenoid driver board has these diodes — often already included on the PCB. Understanding why they exist means you can add them to your own designs.
If switching an LED (not inductive): No flyback diode needed. LEDs are resistive loads with no stored magnetic energy.
STEP 5
Wire and Simulate

Connect in this order: Emitter → GND. Load → Collector. Vcc → Load. Base Resistor → Base. Control signal → Base Resistor. Simulate and verify V_CE ≈ 0.2V when control signal is high (transistor saturated).

▶ Simulate Transistor Switch ▶ Darlington for High-Current Loads
Test it: In the simulator, click the input switch on and off. Watch V_CE drop from ~9V (off) to ~0.2V (on). The LED should turn on and off cleanly. Try changing the base resistor to 10kΩ — does the LED still switch fully on?
📍 Next guided simulation
Continue Learning →
Next: Capacitor Charging Circuit
Next: Capacitor Charging →

Frequently Asked Questions

Why use a transistor instead of a mechanical switch?
A transistor switches silently, with no wear, in microseconds, and can be controlled by a microcontroller GPIO pin drawing milliamps. Mechanical switches wear out after millions of cycles, bounce when operated (causing false signals), and cannot be controlled by a microcontroller directly if the load current exceeds the GPIO rating (typically 40mA).
When should I use a MOSFET instead of a BJT?
Use a MOSFET (like the 2N7000 or IRLZ44N) when: switching currents above 500mA, switching high-frequency signals (PWM above 10kHz), or when gate drive current is limited (CMOS logic output). MOSFETs draw near-zero gate current in steady state and have lower on-resistance at high currents.
What is transistor saturation and why does it matter?
Saturation is when the transistor is fully conducting — both the base-emitter and base-collector junctions are forward biased. V_CE drops to about 0.2V. The load receives almost the full supply voltage. Without saturation (active region), V_CE is higher, the transistor dissipates power as heat, and the switch is not fully on.

Frequently Asked Questions

Why do I need a base resistor?
Without a base resistor, the GPIO pin or control source drives base current through only the 0.7V V_BE junction resistance, pulling excessive current that damages the driving circuit. The base resistor limits base current to the calculated value.
What is the flyback diode for?
Inductive loads (motors, relays, solenoids) store energy in their magnetic field. When the transistor switches off, this energy is released as a large reverse voltage spike. The flyback diode provides a safe path for this energy, protecting the transistor from overvoltage.
Can I use a MOSFET instead of BJT?
Yes, and often preferred. N-channel MOSFETs like the 2N7000 or IRF530 draw near-zero gate current, switch faster, and have lower on-resistance at higher currents. Connect gate to control signal through a 100 ohm resistor, source to ground, drain to load.
← Back to All Guides