Aziz Bench

Switching loads from an ESP32 or Arduino with a MOSFET

A microcontroller pin gives a few milliamps at 3.3 or 5 V; an LED strip, a pump or a solenoid valve wants amps at 12 V. A MOSFET bridges the two, if it is the right one and wired the right way. This guide covers the circuit, how to read a MOSFET datasheet for a 3.3 V or 5 V pin, heat, PWM and the parts that work, with worked examples.

By AzizPublished 17 min read

Checked on 6 November 2026 against the makers’ datasheets and product pages (Alpha & Omega, Infineon, Vishay, onsemi, Microchip, Texas Instruments), Espressif’s and Arduino’s documentation. Heat and switching figures come from our transistor switch calculator, which uses only the values the datasheets guarantee.

The standard circuit: a low-side N-channel MOSFET

For DC loads up to a few amps, the switch goes between the load and ground: the load sits between the supply’s + and the MOSFET’s drain, the source goes to ground, and the pin drives the gate. This is called low-side switching, and it lets a 3.3 V pin control a 12 V or 24 V load, because the gate voltage is measured from the source, which is at ground.

ESP32GPIO25100 Ω10 kΩGDSAO3400A12 V load1N4007coils, motors12 V supply+12 VGNDone common groundESP32GPIO25100 Ω10 kΩGDSAO3400A12 V load1N4007coils, motors12 V supply+12 VGNDone common ground
Five parts around the MOSFET. The diode is only for inductive loads; an LED strip doesn’t need it.
PartValueWhy
MOSFETLogic-level N-channel, with RDS(on) guaranteed at your pin’s voltageSee the next section: this is where most projects go wrong
Gate resistor100 Ω, pin to gateLimits the spike of current into the gate capacitance (3.3 V ÷ 100 Ω = 33 mA at most) and damps ringing on long wires
Pull-down10 kΩ, gate to groundKeeps the MOSFET off while the pin floats during reset and boot
Flyback diodeAcross the load, cathode (the stripe) to +Motors, pumps, valves, relays: gives the coil’s current a path when the MOSFET turns off
Common groundThe supply’s − joined to the board’s GNDWithout it the gate voltage has no reference and the MOSFET doesn’t switch reliably

Gate resistor and pull-down as in our transistor switch calculator. Use a pin that is not a strapping pin (see the mistakes below).

Choosing a logic-level MOSFET

One line in the datasheet decides whether a MOSFET works from your pin: RDS(on) maximum at a stated VGS. The threshold voltage VGS(th) is not the voltage at which the MOSFET is on: it is where it barely starts to conduct, at 250 µA or 1 mA. Between the threshold and the lowest VGS with a guaranteed RDS(on), the datasheet promises nothing.

  • From an ESP32 (3.3 V): pick a MOSFET with RDS(on) guaranteed at 2.5 V. Espressif specifies the high output level as at least 0.8 × VDD with the pin sourcing current; a gate draws almost nothing once charged, so it sees close to 3.3 V, but 2.5 V leaves margin.
  • From an Arduino Uno or Nano (5 V): RDS(on) guaranteed at 4.5 V (or 4 V) is enough.
  • “Logic level” in a name or a shop listing is not a guarantee. The IRLZ44N, sold as logic-level for decades, is guaranteed from 4 V: fine at 5 V, not at 3.3 V.
10301003000246810gate voltage VGS (V)RDS(on) max (mΩ)ESP32 3.3 VArduino 5 VAO3400AIRLZ44NAOD4184AIRF52010301003000246810gate voltage VGS (V)RDS(on) max (mΩ)ESP32 3.3 VArduino 5 VAO3400AIRLZ44NAOD4184AIRF520
No dot, no guarantee: left of its first dot, a MOSFET may conduct, but how well is not specified.
N-channel (examples)Package, VDSRDS(on) guaranteedFrom 3.3 VFrom 5 V
AO3400A (Alpha & Omega)SOT-23, 30 V48 mΩ at 2.5 V, 32 mΩ at 4.5 VYes, about 2 AYes
IRLML6344 (Infineon)SOT-23, 30 V37 mΩ at 2.5 V, 29 mΩ at 4.5 VYes, about 2.2 AYes
Si2302CDS (Vishay)SOT-23, 20 V75 mΩ at 2.5 V, 57 mΩ at 4.5 VYes, about 1.5 AYes; listed as not recommended for new designs (NRND)
AOD4184A (Alpha & Omega)TO-252 (DPAK), 40 V9.5 mΩ at 4.5 V, 7 mΩ at 10 VNot guaranteedYes, well beyond 5 A on enough copper
IRLZ44N (Infineon)TO-220, 55 V35 mΩ at 4 V, 25 mΩ at 5 VNot guaranteedYes, up to about 7 A; an old design, still made
IRLB8721PbF (Infineon)TO-220, 30 V16 mΩ at 4.5 VNot guaranteedYes, but discontinued in 2025; still common in kits
FQP30N06L (onsemi)TO-220, 60 V45 mΩ at 5 VNot guaranteedYes, but discontinued in 2023; onsemi points to the FQP50N06L
IRF520 (Vishay)TO-220, 100 V270 mΩ at 10 V onlyNoNo: not logic-level

Maximum values at 25 °C from the makers’ datasheets. The 3.3 V currents keep a SOT-23 near a quarter of a watt, for a small board (see the heat section); the 5 V currents are the highest our calculator allows in free air at 25 °C, with 25 °C of margin below the maximum junction temperature, as on its part pages. AOS lists the AO3400A and AOD4184A as in full production, Infineon the IRLZ44N as active. Examples, not endorsements. On any alternative check RDS(on) at or below your gate voltage, VDS with margin over the supply (30 V for 12 V is common), VGS max, and the package’s thermal resistance. Parts sold under the same name by second-source makers have their own datasheets: read the one for the part you have.

Heat: conduction loss and the package

A MOSFET that is fully on behaves like a small resistor. It dissipates P = I² × RDS(on), and the junction warms by P × θJA above the air around it. RDS(on) also rises with temperature, to about 1.5 times at 125 °C, so a hot MOSFET gets hotter; our calculator raises it with the temperature until the two agree.

P = I² × RDS(on)(Tj) + P(switching)
Tj = Ta + P × θJA

An AO3400A carrying 2 A from a 3.3 V pin: 2² × 0.048 = 0.19 W at 25 °C, a little more once warm. With 5 kHz PWM it dissipates 0.26 W in all and its junction reaches about 58 °C: comfortable. The Si2302CDS in the same spot reaches about 104 °C: within its rating, but too hot to leave inside a box. The SOT-23 figures assume the makers’ test boards with a patch of copper on the drain; on a bare footprint they run hotter.

  • SOT-23: on a small module, with less copper than that, keep it to about a quarter of a watt: about 2 A for an AO3400A, 2.2 A for an IRLML6344, 1.5 A for an Si2302CDS. Our calculator’s part pages use the makers’ figures and allow more (3.4 A for the AO3400A).
  • TO-220 in free air: about 62 °C/W, so 1 W raises the junction by about 60 °C. Above 1.5 to 2 W add a heatsink; the calculator gives the heatsink’s °C/W.
  • TO-252 (DPAK): it uses the board as its heatsink: AOS gives 55 °C/W for the AOD4184A on a square inch of copper.

Pick the board, the MOSFET and the load: the calculator gives the verdict, the heat, the junction temperature, the diode and better options when a part doesn’t fit.Open the transistor switch calculator

PWM: frequency, gate charge and switching loss

LED dimming: any frequency above about 1.25 kHz avoids visible flicker. On the original ESP32, ledcAttach(pin, 5000, 13) gives 5 kHz with 13 bits of resolution (Arduino-ESP32 3.x); analogWrite() uses 1 kHz and 8 bits. An Arduino Uno’s analogWrite() runs at 490 Hz on pins 3, 9, 10 and 11 and 980 Hz on pins 5 and 6, with 8 bits.

Motors and pumps: the coil smooths the current, but frequencies in the audible range whine. About 20 kHz is above hearing: on an ESP32 that leaves 11 bits; on an Uno, Timer1 on pin 9 or 10 reaches 20 kHz with TOP = 799, about 9.6 bits.

Switching loss. At every edge the MOSFET passes through a half-on state, and the pin moves the gate charge Qg with only about 20 mA. An IRLZ44N (48 nC) driven from an Uno pin takes up to about 2.4 µs per edge. At 490 Hz that costs at most 42 mW; at 20 kHz, with a 3 A motor, up to 1.73 W, enough for the calculator to ask for a heatsink. Both are upper bounds: the calculator counts the whole Qg, while the half-on state lasts through only part of it. The real loss is lower, but at 20 kHz still more than the conduction loss. Fast PWM wants a MOSFET with a small gate charge, or a gate driver.

Pick the chip and the frequency: the calculator gives the duty resolution, the exact frequency and the code for Arduino, ESPHome and the SDKs.Open the PWM calculator

When to add a gate driver

Two cases call for one: a MOSFET that is not guaranteed at your pin’s voltage but suits the load (a 3 A motor from a 3.3 V ESP32), or PWM fast enough that a pin can’t move the gate charge quickly. A gate driver takes the logic signal and drives the gate with an amp or more from a 10 to 12 V supply. For the 3 A motor at 20 kHz from an ESP32, our calculator finds that an IRLZ44N driven at 12 V by a gate driver dissipates 0.52 W and stays near 57 °C.

Gate driver (examples)Key specsWhy it fits
Microchip TC4427Two non-inverting channels, 1.5 A peak, 4.5–18 V supply, input high from 2.4 VTakes a 3.3 V signal; also in an 8-pin DIP package for breadboards
Texas Instruments UCC27517AOne channel, 4 A source and sink, 4.5–18 V, TTL/CMOS inputs independent of the supplyTakes a 3.3 V signal; SOT-23-5, the replacement TI points to for the UCC27517

From Microchip’s and TI’s product pages. On any alternative check that the input threshold is below your logic high, that the supply range covers the gate voltage you want, and keep the gate below 80 % of the MOSFET’s VGS maximum: 12 V suits a ±20 V gate, not a ±12 V one.

A bipolar transistor can stand in for a slow job: a small NPN that pulls the gate to ground, with a resistor pulling it up to 12 V, gives a 12 V gate swing from a 3.3 V pin. It turns the MOSFET on only as fast as the pull-up resistor charges the gate, so it suits on/off switching and low PWM frequencies, not 20 kHz. It also inverts the logic. While the pin is low or floating (during reset, boot and flashing, or with the board unpowered), the pull-up turns the MOSFET on and the load runs: the opposite of what the 10 kΩ pull-down does in the standard circuit. For a load that must stay off by default, add a second NPN stage to invert the logic back, or use a non-inverting gate driver such as the TC4427 with 10 kΩ from its input to ground.

High-side switching with a P-channel MOSFET

Some loads must keep their ground: a module whose ground is shared with the microcontroller through a data line, or a device you want to cut from its positive supply. Then the switch goes on the + side. A P-channel MOSFET sits with its source on the supply; a resistor from gate to source keeps it off, and pulling the gate down turns it on. A 3.3 V pin can’t do that directly on a 12 V rail (its high level is still 8.7 V below the source, so the MOSFET never turns off), so a small NPN does the pulling.

ESP32GPIO2610 kΩBCENPN10 kΩ3.3 kΩGSDAO3401Aload12 V supply+12 VGNDESP32GPIO2610 kΩBCENPN10 kΩ3.3 kΩGSDAO3401Aload12 V supply+12 VGND
Pin high, NPN on, gate pulled down, load on. The 10 kΩ and 3.3 kΩ divider keeps the AO3401A’s gate within its ±12 V rating on a 12 V rail.

With an AO3401A on 12 V and 1 A, the calculator keeps the gate at about 9 V with that divider, and the MOSFET dissipates 62 mW (open the example). The logic is not inverted: pin high, load on. Any small NPN works as the level shifter: 2N3904, BC547 or an SMD MMBT3904.

P-channel (examples)Key specsFits when
AO3401A (Alpha & Omega)SOT-23, −30 V, 85 mΩ at −2.5 V, 60 mΩ at −4.5 V, VGS ±12 VUp to about 2 A; on supplies above about 9.6 V add the R2 divider
AOD4185 (Alpha & Omega)TO-252, −40 V, 20 mΩ at −4.5 V, 15 mΩ at −10 V, VGS ±20 VSeveral amps; on 12 V no divider is needed
IRF9540N (Infineon)TO-220, −100 V, 117 mΩ at −10 V only, VGS ±20 VFine on 12 V, where the gate swings the full 12 V: 0.55 W and about 59 °C at 2 A in free air

From the makers’ datasheets (AOS lists the AOD4185 in full production). A P-channel MOSFET is never a “logic-level” question here: the gate swing comes from the load supply, so check VGS max against that supply.

Typical loads, and which diode

LoadCurrentMOSFET (examples)Flyback diode
12 V LED strip (single colour)From the strip’s watts per metre: 24 W is 2 AAO3400A from 3.3 V up to about 2 A; IRLZ44N or AOD4184A from 5 V for moreNone: it’s resistive
12 V DC motor or pumpRunning current, and several times more at start or stallIRLZ44N or AOD4184A from 5 V; a gate driver from 3.3 VSchottky: 1N5819 up to 1 A, SS34 up to 3 A
12 V solenoid valveFrom the coil: 12 V ÷ 24 Ω = 0.5 AAO3400A1N4007 for on/off
12 V relay coilAbout 30 to 80 mAAO3400A, or a ready relay module1N4148

Diodes as our calculator picks them: 1N4148 (75 V, 150 mA average), 1N4007 (1000 V, 1 A), 1N5819 Schottky (40 V, 1 A), SS34 Schottky (40 V, 3 A). With PWM the diode conducts on every cycle, so use a Schottky rated for the load current.

Size a motor’s MOSFET and diode for the stall current, not the running current: check the motor’s datasheet, or measure the winding resistance and divide the supply voltage by it. A plain diode across a solenoid or relay makes it release a little more slowly; if the release time matters, the valve or relay maker’s application notes give the alternatives.

The IRF520 module trap, and better modules

The common red “IRF520 MOSFET driver module” connects its signal pin almost straight to the gate of an IRF520. That part’s threshold can be up to 4 V and its RDS(on) is guaranteed only at 10 V. From an ESP32 it may not turn on at all (our calculator says it stays off); from an Arduino it conducts only partly (not guaranteed at 5 V) and heats up with a few amps.

Modules built around the AOD4184A (often sold as “D4184” modules) are a real improvement from 5 V: 9.5 mΩ guaranteed at 4.5 V. From 3.3 V they are not guaranteed either, since the AOD4184A’s threshold goes up to 2.6 V and no RDS(on) is given below 4.5 V. Whatever the listing says, read the marking on the MOSFET and look it up.

Worked examples

A. A 12 V LED strip, 2 A, dimmed by an ESP32

AO3400A on GPIO25 with 100 Ω and 10 kΩ, no diode, PWM at 5 kHz with 13 bits. The calculator: 0.26 W of heat (42 mW of it from switching), junction about 58 °C at 25 °C ambient, 109 mV lost across the MOSFET. An IRLML6344 in the same place: 0.2 W, 45 °C. In the code, 4096 of 8192 is 50 %.

const int STRIP = 25;

void setup() {
  ledcAttach(STRIP, 5000, 13);
}

void loop() {
  ledcWrite(STRIP, 4096);
}

Open this example in the transistor switch calculator, then change the strip current or the PWM frequency.Example A in the calculator

B. A 12 V pump, 3 A, from an Arduino Uno

IRLZ44N on pin 9 with 100 Ω and 10 kΩ, an SS34 Schottky across the pump, analogWrite() at 490 Hz. The calculator: 0.29 W, at most 42 mW of it from switching, about 43 °C, no heatsink needed. An AOD4184A in DPAK, entered as a custom part, gives 88 mW of conduction loss: custom parts carry no gate charge, and its 17 nC (maximum at 4.5 V) adds at most 15 mW at 490 Hz. The same IRLZ44N from an ESP32 is not guaranteed: use a gate driver there, or an AO3400A if the pump draws under 2 A.

Open example B: Arduino Uno, IRLZ44N, 3 A pump at 490 Hz.Example B in the calculator

C. A 12 V solenoid valve from an ESP32

The valve’s coil measures 24 Ω, so it draws 0.5 A and 6 W at 12 V. An AO3400A with a 1N4007 across the coil, switched on and off (no PWM): 12 mW in the MOSFET, essentially cold. A 12 V relay coil of about 70 mA is even easier: the calculator picks a 1N4148 for it.

Open example C: ESP32, AO3400A, 0.5 A valve with its diode.Example C in the calculator

Common mistakes

  • No common ground. The supply’s − must connect to the board’s GND, or the gate voltage means nothing.
  • A floating gate at boot. Without the 10 kΩ pull-down, the load can twitch on at power-up or during flashing, while the pin is still an input.
  • A strapping pin. On an ESP32, a 10 kΩ pull-down on GPIO0 holds it low at reset and the board starts in download mode; GPIO2, 5, 12 and 15 are strapping pins too, and some boards show activity on GPIO5, 14 and 15 during boot. GPIO4, 13, 16 to 19, 21 to 23, 25 to 27, 32 and 33 are safer choices (not 16 and 17 on WROVER modules, which use them for PSRAM), as our ESP32 pinout shows.
  • A missing diode on a motor, pump, valve or relay. The voltage spike at turn-off can exceed the MOSFET’s VDS and destroy it, often after working for a while.
  • Trusting VGS(th). A threshold of 1 to 2 V doesn’t make a MOSFET work at 3.3 V; RDS(on) at your gate voltage does.
  • A MOSFET on the high side driven straight from the pin. An N-channel on the + side needs a gate above the supply; a P-channel on 12 V never turns off from 3.3 V.
  • Powering the load through the board. The dev board’s 5 V pin and its traces are not meant for amps: wire the load supply straight to the load and the MOSFET.

Safety

  • Never switch mains with these circuits. The MOSFETs here are for low-voltage DC. For 230 V or 120 V loads use a certified relay module, a certified solid-state relay or a ready-made smart plug, and leave mains wiring to someone qualified where your rules require it.
  • Fuse the low-voltage supply. A 12 V supply that can give 10 A will push it into a short; a fuse sized for the wire protects it.
  • Heat. A TO-220 at 2 W in free air runs well above 100 °C at the junction and burns fingers at the tab; mount it on a heatsink and keep it away from plastic.
  • Stall and inrush. Motors, pumps and capacitive loads draw several times their running current at start: size the supply, the wire and the MOSFET for it.

Frequently asked questions

Can an ESP32 drive a MOSFET directly?

Yes, if the MOSFET’s RDS(on) is guaranteed at 2.5 V: the AO3400A or IRLML6344. Add 100 Ω in series with the gate and 10 kΩ from gate to ground. For bigger MOSFETs guaranteed only at 4.5 V, add a gate driver.

Is the IRLZ44N a logic-level MOSFET?

From 5 V, yes: its RDS(on) is guaranteed at 4 V and 5 V. From a 3.3 V ESP32 pin it is not guaranteed; use an AO3400A, or a gate driver with the IRLZ44N.

Why isn’t VGS(th) the voltage that turns the MOSFET on?

Because it is measured at a tiny current, 250 µA or 1 mA. A MOSFET is fully on only at the gate voltages listed with an RDS(on) value; between the two, the datasheet promises nothing.

Do I need the gate resistor and the pull-down?

The 10 kΩ pull-down, yes: it keeps the load off while the pin floats at boot. The 100 Ω series resistor limits the current spike into the gate and damps ringing; on short wires it is a good habit rather than essential.

Does an LED strip need a flyback diode?

No, a plain LED strip is a resistive load. Motors, pumps, solenoid valves, relays and fans do, across the load with the cathode to +.

Which PWM frequency should I use?

For LEDs anything above about 1.25 kHz; on an ESP32 5 kHz with 13 bits is a good default. For motors about 20 kHz to avoid whine, with a MOSFET of small gate charge or a gate driver, and a Schottky diode.

When does the MOSFET need a heatsink?

When I² × RDS(on), plus switching losses, takes the junction too close to its limit: about 1.5 to 2 W for a TO-220 in free air. A logic-level MOSFET switching a few amps usually dissipates well under 1 W.

Can I switch 230 V or 120 V with a MOSFET?

Not with these circuits, and not safely on a hobby board. Use a certified relay module, solid-state relay or smart plug for mains loads.

Sources

  1. Alpha & Omega: AO3400A product page
  2. Alpha & Omega: AO3400A datasheet
  3. Infineon: IRLML6344 datasheet
  4. Vishay: Si2302CDS datasheet
  5. Octopart: Si2302CDS-T1-GE3 lifecycle
  6. Infineon: IRLB8721PbF datasheet
  7. Octopart: IRLB8721PbF lifecycle
  8. Infineon (International Rectifier): IRLZ44NPbF datasheet
  9. Infineon: IRLZ44N product page
  10. Alpha & Omega: AOD4184A product page
  11. Alpha & Omega: AOD4184A datasheet
  12. onsemi: FQP30N06L discontinuance notice PD24792XB
  13. Vishay: IRF520 datasheet
  14. Alpha & Omega: AO3401A datasheet
  15. Alpha & Omega: AOD4185 product page
  16. Infineon: IRF9540N datasheet
  17. Diodes Incorporated: 1N4001–1N4007 datasheet
  18. onsemi: 1N5817–1N5819 datasheet
  19. onsemi: SS32–S310 (SS34) datasheet
  20. Microchip: TC4427
  21. Texas Instruments: UCC27517 and UCC27517A
  22. Espressif: Arduino-ESP32 LEDC API
  23. Arduino: analogWrite() reference
  24. Espressif: ESP32 series datasheet