In this guide
Transistor Switches Explained: BJT and MOSFET Switching for Student Projects
A transistor switch is the most common way a small controller output drives a bigger load: a relay, a motor, a solenoid, a strip of LEDs, or a buzzer. The controller pin cannot supply that current itself, so the transistor does the heavy lifting while the pin only controls it. Used correctly, this is a cheap and reliable circuit. Used carelessly, it is also one of the fastest ways to burn out a pin, a transistor, or a load.
The problem: a GPIO pin is not a power supply
A typical microcontroller pin can source or sink roughly 20 mA, and often less in practice once several pins are loaded at once. A small relay coil may draw 70 to 100 mA, a DC motor several hundred milliamps at start-up, and an LED strip several amps. Connecting any of these directly to a pin will sag the pin voltage, reset the controller, or damage the output driver. The transistor solves this by separating control from power: a small control current (or voltage) at the input switches a much larger current through the load, which is powered from its own supply rail.
There are two families you will meet in student builds: the bipolar junction transistor (BJT) and the metal-oxide-semiconductor field-effect transistor (MOSFET). They switch for different reasons, and the mistakes you make with each are different too.
How a BJT switch works
A BJT has three terminals: base, collector, and emitter. In the common low-side switch arrangement, the load sits between the positive supply and the collector, the emitter goes to ground, and the controller drives the base through a resistor. When the base current flows, the transistor turns on and current flows from collector to emitter, pulling the load to ground.
Two states matter, and only two:
- Cutoff: no base current, so essentially no collector current. The switch is off, and almost the full supply voltage appears across the transistor.
- Saturation: enough base current that the transistor is fully on. The collector-emitter voltage drops to a small saturation voltage, typically 0.2 to 0.3 V for a small switching transistor, and almost the full supply voltage appears across the load.
The trap is the middle. A BJT that is only partly on drops a large voltage while passing a large current, and power dissipation is voltage times current. That is the state that overheats transistors. A switching BJT must be driven hard into saturation, not gently into its linear region.
Sizing the base resistor, step by step
Take a concrete example: a 2N2222 switching a 12 V load that draws 200 mA, driven from a 3.3 V controller pin.
- Find the collector current. Here, Ic = 200 mA, set by the load.
- Do not use the datasheet current gain at face value. A datasheet hFE of 100 or more applies in the linear region, not in saturation. For switching, use a forced beta of about 10 to 20, meaning you deliberately supply far more base current than the linear gain suggests.
- Pick the base current. With a forced beta of 20, Ib = Ic / 20 = 200 mA / 20 = 10 mA. That is within what a controller pin can supply, and it guarantees saturation.
- Calculate the resistor. The base-emitter voltage is about 0.7 V, so the resistor drops 3.3 V - 0.7 V = 2.6 V. Rb = 2.6 V / 10 mA = 260 ohms. Use the nearest standard value, 270 ohms.
- Check the power in the transistor. In saturation, P = Vce(sat) x Ic = 0.3 V x 0.2 A = 0.06 W, or 60 mW. That is comfortable for a small TO-92 transistor without a heatsink.
If the required base current comes out above what your pin can safely supply (roughly 10 to 20 mA for most student controllers), the BJT is the wrong choice for that load, or you need a Darlington pair or a MOSFET instead.
How a MOSFET switch works
A MOSFET is voltage-controlled rather than current-controlled. For an N-channel MOSFET in a low-side switch, the load sits between the supply and the drain, the source goes to ground, and the controller drives the gate. When the gate-source voltage exceeds the threshold, the channel conducts, and the drain-source resistance (Rds(on)) falls to a small value.
The number that matters most is Rds(on) at your actual gate voltage, not the headline figure on the first page of the datasheet. Many power MOSFETs are specified at a gate voltage of 10 V. Driven from a 3.3 V or 5 V pin, the same device may be only partly on, with a resistance many times higher than the headline value. That is the MOSFET version of the BJT linear-region trap, and it causes the same overheating.
The fix is to choose a logic-level MOSFET, one whose Rds(on) is specified at 4.5 V or 5 V gate voltage, such as the IRLZ44N family. Then do the power check: P = I squared x Rds(on). At 5 A through 0.025 ohms, P = 25 x 0.025 = 0.625 W. That is enough to need a small heatsink or a copper pour, even though the transistor is "on". At 1 A through the same device, P = 0.025 W, and no heatsink is needed. The same part, two very different thermal answers, decided by the square of the current.
Two small components complete a practical MOSFET switch:
- A gate resistor, typically 100 ohms, between the pin and the gate. It limits the inrush current that charges the gate capacitance and damps ringing on a long gate trace.
- A pull-down resistor, typically 10 k ohms, from gate to ground. It holds the MOSFET off while the controller pin is still an input during reset or boot, before your code configures it as an output. Without it, a motor or relay may twitch on every reset.
BJT or MOSFET: a practical decision table
| Situation | Better choice | Why |
|---|---|---|
| Load under 500 mA, parts bin only has 2N2222/BC547 | BJT | Cheap, forgiving, base resistor maths is simple |
| Load over 1 A | MOSFET | No steady base current, much lower on-state loss |
| Switching from a 3.3 V pin | Logic-level MOSFET | A standard MOSFET may not fully turn on at 3.3 V |
| Switching a load at high frequency (PWM above a few kHz) | MOSFET with a proper gate driver | Gate charge limits BJT speed and wastes power |
| You need the switch in the high side (between supply and load) | P-channel MOSFET or a high-side driver | An N-channel device on the high side needs a gate voltage above the supply rail |
| Very low cost, slow on/off, small load | BJT | One resistor, no pull-down needed |
Inductive loads need a flyback diode
Relays, motors, and solenoids store energy in their magnetic fields. When the transistor turns off, that energy has nowhere to go, and the collapsing field generates a voltage spike that can be many times the supply voltage, easily enough to destroy the transistor. The standard fix is a diode across the load, cathode to the positive supply side, anode to the transistor side. While the load is on, the diode is reverse-biased and does nothing. At turn-off, it gives the coil current a safe path to decay. A 1N4007 is adequate for small relays and motors; for fast PWM, use a Schottky diode or a fast-recovery type instead. This diode is not optional decoration: omitting it is the single most common cause of dead switching transistors in student builds.
Five mistakes that kill switching transistors
- No base resistor on a BJT. The base-emitter junction behaves like a diode. Without a resistor, the pin tries to force its full voltage across 0.7 V of junction, and the resulting current damages the pin, the transistor, or both.
- Driving a standard MOSFET from 3.3 V. The gate threshold is where conduction starts, not where it is complete. Check Rds(on) at your real gate voltage.
- No flyback diode on an inductive load. See above. The first turn-off can be the last.
- Sharing a ground badly. The load supply and the controller must share a ground reference, or the transistor has no complete control circuit. But route the heavy load current back to the supply on its own path, not through the controller's ground pin, or the switching noise will reset the controller.
- Switching the high side with an N-channel MOSFET and no driver. The gate must sit above the source, which sits near the supply rail when the switch is on. A plain pin cannot do that. Use a low-side switch when you can, and a P-channel device or a dedicated high-side driver when you cannot.
A one-evening bench routine
Build the switch on a breadboard with a 12 V lamp or relay as the load, a BJT first and then a MOSFET, and measure three things: the voltage across the transistor when on (it should be small, under 0.5 V), the voltage across the load (it should be nearly the full supply), and the transistor temperature after a minute of operation (warm is fine, too hot to touch is a design error, not bad luck). Change the base resistor or the gate drive, watch the on-state voltage move, and you will have an intuition for saturation and Rds(on) that no datasheet table alone can give.
Frequently asked questions
Can I switch a load with a transistor without a resistor at all?
No, not with a BJT: the base needs its resistor. With a MOSFET you can sometimes connect the gate directly for very small, slow loads, but a 100 ohm gate resistor and a 10 k pull-down cost almost nothing and prevent real problems, so include them by default.
Why does my transistor get hot even though the load is within its current rating?
Because the current rating assumes the transistor is fully on. If it is only partly on, it drops volts while passing amps, and that product is heat. Check saturation (BJT) or Rds(on) at your gate voltage (MOSFET) before blaming the part.
Can a transistor switch AC mains?
No. A single BJT or MOSFET is a DC switch. For mains, use a relay, a solid-state relay, or a triac circuit designed for mains, with proper isolation and enclosure. Student mains work belongs behind supervision and a proper enclosure, not on a breadboard.
Is a relay module better than a bare transistor switch?
For mains loads or for full electrical isolation, yes, a relay module is the right tool, and it already contains the transistor, flyback diode, and optocoupler. For low-voltage DC loads, a bare transistor switch is cheaper, smaller, faster, and quieter. Match the tool to the load.
Limitations
This guide covers low-voltage DC switching, the case student projects meet most often. It does not cover high-side gate drivers, half-bridge and full-bridge motor drivers, mains switching, or switching power-supply design, where layout, gate-drive current, and protection get substantially more demanding. Treat the worked numbers as design examples for the stated conditions: always re-check the datasheet of the exact part in your hand, because pinouts and ratings vary between manufacturers.