Components · #7 of 52

Transistors/MOSFETs as Switches

GPIO Control, Load Current, Gate Drive, and Heat

Several MOSFET transistors photographed together.
A transistor switch lets a tiny logic signal control a larger current path. The trick is knowing which current goes where. · Mister rf, CC BY-SA 4.0

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

  1. Explain why GPIO pins control switches but should not carry load current
  2. Draw a low-side N-channel MOSFET switch with gate resistor and pull-down
  3. Distinguish BJT base current from MOSFET gate charge
  4. Use $P = I^2R_{DS(on)}$ to estimate MOSFET conduction heat
  5. Recognize why threshold voltage is not the same as fully-on gate drive
  6. 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:

A low-side N-channel MOSFET switch controlled by a GPIO pin.
In a low-side switch, the load connects to the positive supply and the MOSFET completes the path to ground. The GPIO touches the gate, not the load current. · TooFoo original

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.

A through-hole transistor package photographed on a white background.
Small through-hole transistors are easy to prototype, but the pin order is package-specific. Always check the datasheet before plugging one into a breadboard. · Evan-Amos, Public domain

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 BC546B small-signal transistor.
A BJT switch needs base current. The base resistor is not optional, because the base-emitter junction behaves like a diode. · Retired electrician, CC0

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.

Four projections of a TO-92 transistor package.
The same package shape can hide different pin orders and device types. Package familiarity is not a pinout. · John Dalton, CC BY-SA 3.0

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.

A MOSFET gate voltage curve showing the gate charging and the Miller plateau.
The gate is a capacitive node. A large MOSFET can need real charge movement before it becomes a low-resistance switch. · TooFoo original

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 RDS(on)R_{DS(on)}. Conduction loss is:

P=I2RDS(on)P = I^2R_{DS(on)}

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.

A MOSFET package heat path from die through package to copper and heatsink.
The electrical calculation gives watts. The mechanical package and board copper decide where those watts go. · TooFoo original
conduction loss: 0.18 W estimated rise: 18 degC junction estimate: 43 degC verdict: cool switch

Try these moves:

  1. Keep RDS(on)R_{DS(on)} fixed and double the load current. Watch heat rise by four times.
  2. Raise the gate drive from 2.5 V to 4.5 V. A real datasheet often shows lower on-resistance at the higher drive.
  3. Improve thermal resistance. This is what a larger copper pour, package tab or heatsink is trying to do.
A power MOSFET photographed close up.
Power MOSFETs are built to move current and heat. The tab, package and board copper are part of the electrical design. · Suyash Dwivedi, CC BY-SA 4.0
A power transistor mounted on a heatsink inside an audio amplifier.
A heatsink is not decoration. It is the continuation of the current calculation into thermal design. · Daniel Christensen, CC BY 3.0

A MOSFET carries 2 A with RDS(on) = 50 milliohms at the actual gate drive. About how much conduction power does it dissipate?

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.

A low-side MOSFET switch with a clamp across an inductive solenoid load.
The switch lesson and diode lesson meet at turn-off. A transistor switch needs a deliberate plan for inductive energy. · TooFoo original

The common relay or solenoid driver includes:

Why is a gate pull-down useful on a low-side MOSFET switch?

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 VGSV_{GS}. 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 VGSV_{GS} high. That is why high-side N-MOSFET switches use driver chips, charge pumps or a P-channel MOSFET for simple low-current jobs.

Practice 1 warm-up

A MOSFET switches a 1.5 A LED load. The datasheet gives RDS(on)=80R_{DS(on)} = 80 milliohms at your gate drive. Estimate conduction power.

Show worked solution

P=I2R=1.52×0.080=0.18P = I^2R = 1.5^2 \times 0.080 = 0.18 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.

Practice 2 core

A MOSFET datasheet says VGS(th)=2.0V_{GS(th)} = 2.0 V. The only RDS(on)R_{DS(on)} line is specified at VGS=10V_{GS} = 10 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.
  • VGS(th)V_{GS(th)} is not a fully-on guarantee. Check RDS(on)R_{DS(on)} at the gate voltage you really have.
  • MOSFET heat follows P=I2RDS(on)P = I^2R_{DS(on)}, 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.

full glossary →