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.
Circuit Diagram
Step-by-Step Guide
Before calculating anything, establish how much current the load draws. Example: switching a 9V LED strip drawing 100mA.
- Supply: 9V
- Load current (I_C): 100mA = 0.1A
- Control signal: 5V GPIO pin (max 40mA output, we will use ~5mA)
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.
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
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.
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