LeepCast
Subscribe
All posts
Hardware

Switching Loads With a MOSFET: Logic-Level Gates, Gate Resistors, and Flyback Diodes for Microcontroller Projects

A microcontroller pin can supply a few milliamps; a motor or LED strip wants amps. Here is how a low-side N-channel MOSFET bridges that gap, how to read the datasheet numbers that matter, and how to size the gate resistor, pull-down, and flyback diode.

LeepCast8 min read

Almost every hardware project eventually needs to turn on something hungrier than an LED: a 12 V fan, an LED strip, a solenoid valve, a small DC motor. The microcontroller deciding when that happens can only source or sink a few tens of milliamps per pin, and it usually runs at 3.3 V or 5 V. The usual bridge between those two worlds is a single N-channel MOSFET wired as a low-side switch. The circuit has only four or five parts, yet each part exists to prevent a specific failure, and skipping one tends to produce a board that works on the bench and dies in the field.

The low-side switch in one paragraph

In a low-side switch the load connects between the positive supply and the MOSFET drain, and the MOSFET source connects to ground. The microcontroller drives the gate. When the gate sits a few volts above the source, a conductive channel forms between drain and source and current flows through the load to ground. When the gate returns to 0 V, the channel disappears and the load switches off. Because the source is tied to ground, the gate voltage is simply the GPIO voltage, which is what makes this arrangement so easy to drive from logic. The load supply can be 12 V or 24 V while the gate still only sees 3.3 V or 5 V, as long as the two circuits share a ground.

  • N-channel MOSFET: the actual switch, chosen for the load current and the gate voltage you have.
  • Series gate resistor (roughly 100 to 470 ohms): limits the current spike drawn from the GPIO pin at each edge and damps ringing.
  • Gate pull-down resistor (roughly 10 to 100 kilohms, gate to source): holds the MOSFET off while the microcontroller boots or the pin floats.
  • Flyback diode across any inductive load: gives coil current somewhere to go when the switch opens.
  • Common ground between the logic circuit and the load supply.

Threshold voltage is not turn-on voltage

The most misread line on a MOSFET datasheet is the gate threshold voltage, VGS(th). It is measured at a tiny drain current, often 250 microamps, and it marks the point where the device barely starts to conduct. A MOSFET at its threshold behaves like a large resistor, not a closed switch. The number that matters for switching is the on-resistance, RDS(on), and specifically the gate voltage at which that resistance is guaranteed.

The IRLZ44N, a common logic-level part, illustrates the pattern. Its datasheet lists a threshold between 1.0 and 2.0 V, but guarantees a maximum RDS(on) of 0.022 ohms at 10 V on the gate, 0.025 ohms at 5 V, and 0.035 ohms at 4 V. There is no guaranteed figure at 3.3 V at all. So the part is a solid choice for a 5 V Arduino, while on a 3.3 V board such as an ESP32 or RP2040 you would be relying on typical curves rather than guarantees. The rule that follows is simple: only trust an RDS(on) figure specified at or below the gate voltage your pin can really deliver. A part whose only RDS(on) row is at 10 V is not a logic-level MOSFET, whatever the product listing says.

Worked example: a 3 A LED strip on a 5 V microcontroller

Suppose a 12 V LED strip draws 3 A and is switched by an IRLZ44N in a TO-220 package with no heatsink, driven from a 5 V pin. Conduction loss in the MOSFET is the load current squared times the on-resistance: 3 × 3 × 0.025 = 0.225 W. The datasheet gives a junction-to-ambient thermal resistance of 62 °C/W for the bare package, so the die would sit about 14 °C above the surrounding air.

On-resistance climbs as the silicon heats up, so a cold-die calculation is optimistic. A cautious habit is to double the loss for margin: 0.45 W gives a rise of roughly 28 °C, putting the junction near 53 °C in a 25 °C room. That is comfortable against the 175 °C maximum, and leaving a wide gap below that limit is wise because enclosures trap heat. The same arithmetic at 10 A tells a very different story: 10 × 10 × 0.025 = 2.5 W cold, which would push a bare TO-220 well past safe territory and calls for a heatsink or a part with lower RDS(on).

The short script below packages these checks so you can rerun them with your own part and load. It uses only the Python standard library.

python
# Quick thermal and gate-drive sanity check for a low-side MOSFET switch.
# Defaults are IRLZ44N datasheet maxima at VGS = 5 V; replace them with your part's.

def check_switch(i_load, rds_on, r_theta_ja, t_ambient=25.0, hot_factor=2.0,
                 q_g=48e-9, f_pwm=1_000, v_drive=5.0, r_gate=220.0):
    p_cold = i_load ** 2 * rds_on
    p_hot = p_cold * hot_factor          # pessimistic: RDS(on) rises as the die heats
    t_junction = t_ambient + p_hot * r_theta_ja
    i_gate_avg = q_g * f_pwm             # charge per edge pair times edges per second
    i_gate_peak = v_drive / r_gate       # upper bound at the first instant of an edge
    return p_cold, p_hot, t_junction, i_gate_avg, i_gate_peak


p_cold, p_hot, tj, ig_avg, ig_pk = check_switch(i_load=3.0, rds_on=0.025, r_theta_ja=62)
print(f"conduction loss: {p_cold:.3f} W cold, {p_hot:.3f} W hot estimate")
print(f"junction estimate, no heatsink: {tj:.1f} C")
print(f"gate current: {ig_avg * 1e6:.0f} uA average, {ig_pk * 1e3:.0f} mA peak")

Running it prints a conduction loss of 0.225 W cold and 0.450 W hot, a junction estimate of 52.9 C, and a gate current of 48 uA average with a 23 mA peak. The gate numbers are the subject of the next section.

The gate is a capacitor, and that sets the resistor

No current flows into a MOSFET gate once it has settled, but the gate behaves like a capacitor that must be charged on every turn-on and drained on every turn-off. Datasheets express this as total gate charge, Qg. For the IRLZ44N the maximum is 48 nC at a 5 V gate drive. Texas Instruments' MOSFET driver guide breaks turn-on into stages: the gate first charges up to the threshold with no drain current yet, then drain current ramps up, then the gate voltage stalls on a flat step called the Miller plateau while the drain voltage collapses, and finally the gate climbs to its full drive level, which sets the final on-resistance. Switching loss happens during the middle two stages, when the device carries current and blocks voltage at the same time.

Two consequences follow. First, the average gate current is just the gate charge times the switching frequency, so it is tiny at low PWM rates but grows linearly: 48 nC at 1 kHz is 48 microamps, while the same part at 25 kHz needs about 1.2 mA on average. Second, the instantaneous current at each edge can be far larger, because an uncharged gate looks almost like a short. Measurements published by Wolles Elektronikkiste found an Arduino pin pushing on the order of 100 mA into an unresisted gate for a fraction of a microsecond, against a 20 mA pin rating. A series resistor caps that peak at roughly the drive voltage divided by the resistance, which is why 5 V across 220 ohms gives the 23 mA figure in the script. The price is slower edges and therefore more switching loss, which matters at tens of kilohertz but is negligible for an LED strip at 1 kHz.

Why the pull-down resistor is not optional

Between power-up and the moment firmware configures the pin as an output, a GPIO is typically a high-impedance input. A MOSFET gate attached to a floating pin can pick up enough stray charge to turn partly on, leaving the device sitting in its linear region where it dissipates heat while the load flickers or runs at half power. A resistor from gate to source drains that charge and guarantees the off state. Placing it on the MOSFET side of the series resistor keeps the gate held low even if the wire to the microcontroller is unplugged. That forms a small voltage divider with the series resistor, but with 220 ohms against 10 kilohms or more the gate still receives about 98 percent of the pin voltage.

Inductive loads need a flyback diode

Motors, relays, and solenoids store energy in a magnetic field. The voltage across an inductor is its inductance times the rate of change of current, so when the MOSFET snaps off and tries to stop that current in nanoseconds, the coil generates whatever voltage it needs to keep current flowing. That spike lands on the drain and can exceed the MOSFET breakdown rating, at which point the device absorbs the energy in avalanche or fails outright. The DigiKey forum discussion of this effect demonstrates a relay coil lighting a neon lamp, which needs roughly 100 V to strike, when switched off without protection.

The fix is a diode connected across the load, cathode to the positive supply and anode to the drain. During normal operation it is reverse biased and does nothing. At turn-off it gives the coil current a loop to circulate in until the energy is spent, clamping the drain to about one diode drop above the supply. Choose a diode rated for at least the load current and the supply voltage; a Schottky part responds quickly and drops less voltage. Do not count on the MOSFET's internal body diode for this job, because it sits between drain and source and does not provide a path around the coil.

There is one trade-off worth knowing. Because the clamp holds the coil voltage low, the current decays slowly, so a relay with a plain diode releases noticeably later than one without. If release time matters, adding a Zener in series with the diode lets the coil voltage rise to a controlled higher level, which makes the current fall faster while still keeping the drain below its rating.

Common mistakes

  • Using a 10 V-rated standard MOSFET such as an IRFZ44N, which looks similar to the IRLZ44N but is not specified for logic-level drive.
  • Leaving out the pull-down, then wondering why the motor twitches at reset.
  • Wiring the flyback diode backwards, which shorts the supply through the diode the moment the switch closes.
  • Running high PWM frequencies directly from a GPIO into a large-gate-charge MOSFET, where the edges become slow and the part warms up from switching loss rather than conduction loss.

When a bare low-side MOSFET is the wrong tool

  • The load must stay connected to ground, as with some sensors or devices sharing a chassis; that calls for a high-side switch, typically a P-channel MOSFET with a small driver transistor or a dedicated high-side switch IC.
  • You are on 3.3 V logic and cannot find a part with RDS(on) guaranteed at 2.5 V or 3.3 V; use a gate driver or a level-shifting transistor stage instead of hoping.
  • You need fast PWM, tens of kilohertz or more, into a large MOSFET; a gate driver IC supplies the amps of peak current that a GPIO cannot.

Build checklist

  1. Confirm the MOSFET drain-source voltage rating is comfortably above the load supply, including any spikes.
  2. Find an RDS(on) row specified at or below your GPIO high voltage, and compute I squared times R with a margin for heat.
  3. Add a series gate resistor so the peak current stays near the pin's rating.
  4. Add a gate-to-source pull-down on the MOSFET side of that resistor.
  5. Fit a correctly oriented flyback diode across every inductive load.
  6. Tie the logic ground and load ground together with a wire thick enough for the load current return path.
Share

Enjoyed this?

Get the next deep dive in your inbox. No spam — just the stories worth reading.

Subscribe to the newsletter

Comments