Compute whether a load exceeds a GPIO's capability.
Choose between a MOSFET and a BJT as a load switch.
Explain inductive kickback and size a flyback diode.
Account for inrush and stall currents.
ME-2's capstone crossed this line once: a WS2812 strip wanting 480 mA from a pin rated for about 12 mA. This lesson makes the reasoning general, and adds the hazard that catches people who have already learned the current limit — inductance.
The first question is always arithmetic. What current does the load want, at what voltage, and continuously or in bursts? Compare against the pin's rating and against the total the chip can supply across all pins at once, which is a separate and smaller number than the per-pin limit multiplied by the pin count. If the load wins, a switch is required, and ME-2 L3's low-side n-channel MOSFET is the default answer: logic-level gate, RDS(on) specified at the gate voltage you actually have, a gate resistor, and a gate pull-down.
A BJT can do the same job and occasionally should. Its base needs continuous current — IC/β, so a 500 mA load at β=100 needs 5 mA of base drive, within a pin's ability but not free — and it drops about 0.2 V when saturated rather than millivolts. In exchange it is cheap, tolerant, and unbothered by the gate-threshold questions that make MOSFET selection fussy. For small loads either works; above an amp or so, the MOSFET's conduction loss wins decisively.
Now the hazard. Any coil — a relay, a solenoid, a motor winding — is an inductor, and CA-5 L2 established that inductor current cannot change instantly. Open a switch in series with a coil carrying current and the inductor will produce whatever voltage is required to keep that current flowing, which with a fast switch means hundreds or thousands of volts. That spike appears directly across the switching device and destroys it.
vL=Ldtdithe kickback, from CA-5
The flyback diode: reverse biased in normal operation, it conducts the coil's current when the switch opens.
The diode sits across the coil, oriented so that it is reverse biased — and therefore invisible — while the switch is closed and current flows normally. The instant the switch opens, the coil's bottom terminal flies upward; as soon as it exceeds the supply by one diode drop, the diode conducts and provides a path for the coil current to circulate and decay. The switch now sees only supply plus 0.7 V instead of a kilovolt.
Vswitch≈Vsupply+0.7Vclamped, with the flyback diode fitted
WORKED EXAMPLE
Sizing a relay driver
A relay coil: 12 V, 30 mA, inductance about 100 mH. Switched by a low-side MOSFET from a GPIO.
Load current is trivial, so conduction loss is irrelevant; almost any logic-level part works.
Without a flyback diode: opening the switch in, say, 1 µs would demand v=Ldi/dt=0.1×(0.03/10−6)=3000 V. The MOSFET's drain-source rating is perhaps 60 V. It dies on the first switch-off.
With a diode rated for at least 30 mA (any small signal diode qualifies) across the coil, the drain sees about 12.7 V. Decay time constant L/R using the coil's own resistance (400Ω at 12 V, 30 mA) is 0.1/400=0.25 ms — the relay releases in under a millisecond.
A 3000 V spike becomes 12.7 V, for the price of one diode.WORKED EXAMPLE
Inrush and stall
A small DC motor draws 200 mA running. Its stall current — with the rotor held — is often five to ten times that, and it draws stall current for the first tens of milliseconds of every start.
So the switch, the supply, and the traces must all handle perhaps 1–2 A briefly, not 200 mA.
Incandescent lamps behave similarly: a cold filament has a fraction of its hot resistance, so inrush is many times the steady current.
Design for the peak, then check the average for thermal purposes. Designing for the average alone produces a device that fails on startup — the worst kind of intermittent fault.
Size switches for stall and inrush; size heatsinks for average.
PRACTICE
Q1
A load draws 250 mA at 5 V. Can a 3.3 V GPIO rated at 12 mA drive it directly? What is the minimum you must add?
Q2
A solenoid with L=50 mH carrying 500 mA is switched off in 2 µs with no protection. Estimate the voltage that appears across the switch.
Q3
Why is a flyback diode invisible during normal operation, and what determines how fast the coil current decays through it once fitted?
Q4
A motor is specified at 300 mA. Give two reasons the switching device should be rated well above that.