Transistors & MOSFET Switching: the short answer
A GPIO pin can supply only a few milliamps. To switch a motor, LED strip or solenoid you let the pin control a transistor, and the transistor carries the big current.
- Level
- Intermediate
- Time
- About 5 min
- Topic
- Semiconductors
Switch a load bigger than a pin can handle with a logic-level N-channel MOSFET.
Before this: Ohm’s Law, Power & Heat, Digital Inputs and Outputs
A GPIO pin can supply only a few milliamps. To switch a motor, LED strip or solenoid you let the pin control a transistor, and the transistor carries the big current.
The usual choice is an N-channel MOSFET as a low-side switch: load from + to the MOSFET's drain, source to ground, and the pin drives the gate through a 100 to 220 Ω resistor. Add a 10 kΩ from gate to ground so the load stays off while the board boots.
Pick a logic-level MOSFET. The datasheet value VGS(th) only says where it starts to turn on. What matters is RDS(on) at your gate voltage: look for a value given at 4.5 V (for 5 V boards) or 2.5 V (for 3.3 V boards). The IRLZ44N works well from 5 V; the AO3400A is a good small part for 3.3 V.
Heat in the MOSFET is I² × RDS(on). At 2 A and 0.025 Ω that is 0.1 W, fine without a heatsink.
Gate voltage decides how well it turns on
A MOSFET is controlled by the voltage between gate and source. The threshold voltage on the datasheet is where it just starts to conduct, not where it is fully on. For a switch you want the gate voltage at which the on-resistance is specified, which is why you need a logic-level MOSFET when driving from 3.3 V or 5 V.
A part like the IRLZ44N turns on well at 5 V. An IRF540 needs about 10 V and may stay half-on from a microcontroller pin, getting hot even though the circuit looks right.
Heat comes from resistance and from slow switching
When fully on, the power lost is I squared times Rds(on). A device with 0.03 Ω carrying 5 A loses 0.75 W, which needs a small heatsink. In PWM use, switching slowly adds loss because the device spends time half on. A gate resistor of 100 Ω limits ringing and current spikes, and a driver chip helps at higher frequencies.
Add a pulldown of about 10 kΩ from gate to source so the load stays off while the microcontroller pin is not driven, for example during start-up.
Inductive loads and polarity
Motors and relay coils need a flyback diode across the load. For high-side switching of a positive supply you need a P-channel device or a gate driver; a simple N-channel on the low side, between the load and ground, is the easiest design.
- Using a non-logic-level MOSFET on a 3.3 V pin, so it never fully turns on.
- Leaving out the gate pulldown, so the load flickers at power-up.
- Omitting the flyback diode on a motor or relay.
- P = I² × Rds(on)
- heat in a fully-on MOSFET
Work it with your own numbers: MOSFET switch
Practise this lesson with Maker
The explanation above is free for everyone. The practice for Intermediate lessons in every domain are part of the Maker plan at ₹499 a month, and Pro includes them too.
With Maker you also get: a worked example, a hands-on task, a 3-question check.
