Transistors/MOSFETs as Switches
GPIO Control, Load Current, Gate Drive, and Heat
The robot hand's fingertip board has one small vibration motor. The firmware wants a GPIO pin to turn it on for a haptic tick. The motor wants hundreds of milliamps for a moment, and the GPIO pin can only manage a few milliamps safely.
Connecting the motor straight to the pin is not bold. It is a way to turn a microcontroller into a fuse. The pin should make a decision. A transistor should carry the current.
A transistor is an active device. In this lesson we use it for the simplest active job: switching. A small control signal at the base or gate changes a larger current path. That larger current can feed an LED strip, relay, solenoid, fan, pump, heater or motor.
By the end, you can
- Explain why GPIO pins control switches but should not carry load current
- Draw a low-side N-channel MOSFET switch with gate resistor and pull-down
- Distinguish BJT base current from MOSFET gate charge
- Use $P = I^2R_{DS(on)}$ to estimate MOSFET conduction heat
- Recognize why threshold voltage is not the same as fully-on gate drive
- Add flyback protection for motors, relays and solenoids
GPIO is a signal, not a power rail
The current rating of a microcontroller pin is small because the silicon area is small and the package wires are small. A pin can light an efficient indicator LED. It should not be asked to start a motor, energize a relay coil or feed a strip of high-current LEDs. Even when a datasheet lists an absolute maximum current, that is not a design target. It is the edge of damage.
The design pattern is separation:
- GPIO carries the decision.
- The transistor switch carries the load current.
- The supply and ground return carry the energy.
The common beginner switch is a low-side N-channel MOSFET. Put the load between the positive rail and the MOSFET drain. Put the source at ground. Drive the gate high to turn it on. Pull the gate down so it stays off during boot and reset.
BJT versus MOSFET as a switch
A BJT is current-controlled enough for switching intuition: base current allows a larger collector current. To use a BJT as a saturated switch, you must provide enough base current. A forced beta around 10 is a common conservative design habit for saturation, even when the transistor's small-signal gain is much higher.
For a 300 mA relay coil, a forced beta of 10 asks for about 30 mA of base current. That may already be too much for a GPIO pin. A small BJT can still be useful for modest loads, but the base-current budget matters.
A MOSFET is different. Its gate is insulated. At DC, the gate draws almost no current. The GPIO pin charges or discharges a small gate capacitance, and the MOSFET channel changes resistance. That makes MOSFETs excellent GPIO-controlled switches, especially when the load current is much larger than the pin current.
Gate charge is why switching takes time
At DC the MOSFET gate is nearly open-circuit. During switching it behaves like a capacitor. The GPIO pin must move charge into the gate to turn the MOSFET on, then pull that charge back out to turn it off. A gate resistor slows the edge a little and damps ringing. A gate pull-down makes sure the MOSFET stays off while the microcontroller is booting or the pin is still floating.
For slow on-off control, gate charge is usually easy. For PWM, motor control and fast power conversion, gate charge becomes central. If you switch a big MOSFET slowly, it spends more time half-on, where voltage and current overlap and heat rises.
A switch still dissipates power
When a MOSFET is on, it is not a zero-ohm wire. The channel has an on-resistance, written . Conduction loss is:
Current is squared. Doubling load current makes four times the conduction heat. A part that is cool at 1 A can be hot at 2 A without any mystery.
Try these moves:
- Keep fixed and double the load current. Watch heat rise by four times.
- Raise the gate drive from 2.5 V to 4.5 V. A real datasheet often shows lower on-resistance at the higher drive.
- Improve thermal resistance. This is what a larger copper pour, package tab or heatsink is trying to do.
A MOSFET carries 2 A with RDS(on) = 50 milliohms at the actual gate drive. About how much conduction power does it dissipate?
-
Correct. P = I^2R = 2^2 x 0.050 = 0.20 W.
-
That misses the square on current.
-
That is ten times too high for 50 milliohms at 2 A.
-
That would require much higher resistance or current.
Inductive loads need a turn-off path
The diode lesson matters here. Motors, solenoids and relay coils are inductive. Their current does not stop politely when the MOSFET opens. If the schematic gives the coil no safe path, the voltage rises until something else conducts, often the MOSFET's avalanche rating, a protection diode you did not mean to use, or an arc.
The common relay or solenoid driver includes:
- A MOSFET or BJT sized for load current and heat.
- A gate or base resistor.
- A gate pull-down or base-emitter pull-down.
- A flyback clamp across the coil.
- A shared ground reference between the microcontroller and switch circuit.
Why is a gate pull-down useful on a low-side MOSFET switch?
-
Correct. The gate is capacitive and can float. A pull-down gives it a defined off state.
-
The drain-source path carries load current, not the pull-down.
-
A resistor from gate to source does not boost the load rail.
-
The pull-down controls gate state. It does not provide an inductive current path.
Why low-side switching is easier than high-side switching
An N-channel MOSFET turns on according to gate-to-source voltage, not gate-to-ground voltage. In a low-side switch the source is near ground, so a 3.3 V GPIO can create about 3.3 V of . In a high-side N-channel switch, the source rises toward the supply as the switch turns on, so the gate must be driven above the supply rail to keep high. That is why high-side N-MOSFET switches use driver chips, charge pumps or a P-channel MOSFET for simple low-current jobs.
A MOSFET switches a 1.5 A LED load. The datasheet gives milliohms at your gate drive. Estimate conduction power.
Show worked solution
W. That may be fine in a package with enough copper, but it is no longer zero. If the board has poor heat spreading, check the thermal resistance and package rating.
A MOSFET datasheet says V. The only line is specified at V. Is this a good direct switch for a 3.3 V GPIO? Explain.
Show worked solution
Not enough information, and probably not a safe choice. Threshold voltage only says the device barely starts conducting at a tiny current. For a direct 3.3 V GPIO switch, use a MOSFET whose on-resistance is specified at 2.5 V or 3.3 V gate drive, or use a gate driver that provides the voltage the MOSFET actually needs.
Key takeaways
- GPIO should make the control decision; the transistor should carry the load current.
- A low-side N-MOSFET switch is the default beginner pattern for DC loads.
- MOSFET gates draw little DC current but require charge movement during switching.
- is not a fully-on guarantee. Check at the gate voltage you really have.
- MOSFET heat follows , and inductive loads need flyback protection.
A transistor switch is where software starts touching power. The firmware toggles one pin, but the real circuit moves charge through a load, stores energy in coils, heats silicon and returns current through copper. Treat the switch as a whole current path, not a single magic part, and the next chapters on GPIO and PWM become much easier to trust.