A MOSFET (Metal-Oxide-Semiconductor Field-Effect Transistor) is a voltage-controlled switch. A small voltage on the Gate pin controls a large current flowing between the Drain and Source. The gate draws almost no steady-state current, so a 3.3V GPIO pin can switch loads that pull tens of amps. That one property explains why MOSFETs sit inside nearly every motor driver, power supply, LED dimmer, and CPU.
Quick Takeaways
- A MOSFET is controlled by voltage at the Gate (V<sub>GS</sub>). A BJT is controlled by current at the Base.
- Pick a logic-level MOSFET (for example the IRLZ44N or AO3400) when driving from 3.3V or 5V microcontroller pins.
- Low R<sub>DS(on)</sub> means less heat. A good modern part measures in milliohms.
- Always add a gate resistor (100-330Ω) and a pulldown resistor (10kΩ) for reliable switching.
| Feature | N-Channel MOSFET | P-Channel MOSFET |
|---|---|---|
| Turns on when | V<sub>GS</sub> is positive | V<sub>GS</sub> is negative |
| Typical placement | Low-side switch (load to ground) | High-side switch (load to supply) |
| R<sub>DS(on)</sub> | Lower | Higher (about 2-3x for the same die size) |
| Cost | Lower | Higher |
| Ease of drive from MCU | Easy | Needs level shifting for high-voltage rails |
What Is a MOSFET?
A MOSFET is a four-terminal semiconductor device: Gate (G), Drain (D), Source (S), and Body (B). In discrete parts, the body is tied internally to the source, so you see three pins.
The gate sits on a thin insulating layer of silicon dioxide. No DC current flows through it. Applying a voltage to the gate creates an electric field that forms a conductive channel between the drain and source. Remove the voltage, and the channel disappears.
The Three Pins
- Gate (G): The control input. It behaves like a small capacitor (typically 500pF to several nF), so it draws current only while charging or discharging.
- Drain (D): Where load current enters an N-channel device.
- Source (S): Where current exits an N-channel device. It usually connects to ground in low-side circuits.
N-Channel vs. P-Channel Operation
For an N-channel MOSFET, current flows from drain to source when the gate is higher than the source by at least the threshold voltage (V<sub>GS(th)</sub>). For a P-channel MOSFET, the polarity flips: the gate must be lower than the source.
How a MOSFET Works: Enhancement Mode
Almost every MOSFET you buy is an enhancement-mode device. It is normally off and turns on when you apply gate voltage.
- V<sub>GS</sub> = 0V: No channel exists. The device blocks current. Only a tiny leakage current (I<sub>DSS</sub>, often microamps) flows.
- V<sub>GS</sub> reaches V<sub>GS(th)</sub>: A thin inversion layer forms. The device starts to conduct, but R<sub>DS(on)</sub> is still high.
- V<sub>GS</sub> well above threshold: The channel is fully formed. R<sub>DS(on)</sub> drops to its rated minimum. The device is fully on.
Threshold voltage is not the voltage at which the MOSFET is fully on. This mistake burns more hobby projects than any other. A part with V<sub>GS(th)</sub> of 4V will not switch properly from a 3.3V pin, even though 3.3V is close to 4V.
The Three Operating Regions
| Region | Condition | Behavior |
|---|---|---|
| Cutoff | V<sub>GS</sub> < V<sub>GS(th)</sub> | Off. No drain current. |
| Linear (Ohmic) | V<sub>GS</sub> > V<sub>th</sub>, small V<sub>DS</sub> | Acts like a resistor equal to R<sub>DS(on)</sub>. Use this for switching. |
| Saturation | V<sub>GS</sub> > V<sub>th</sub>, large V<sub>DS</sub> | Acts like a current source. Use this for amplifiers. |
For digital switching, you want the device in cutoff or deep in the linear region, never lingering in between.
Key Specifications on a MOSFET Datasheet
Read these parameters before buying a part.
| Parameter | Symbol | What It Means | Example (IRLZ44N) |
|---|---|---|---|
| Drain-Source Voltage | V<sub>DSS</sub> | Max voltage across D-S when off | 55V |
| Continuous Drain Current | I<sub>D</sub> | Max steady current (at 25°C case temp) | 47A |
| On-Resistance | R<sub>DS(on)</sub> | D-S resistance when fully on | 22mΩ at V<sub>GS</sub>=5V |
| Gate Threshold | V<sub>GS(th)</sub> | Voltage where conduction begins | 1-2V |
| Max Gate Voltage | V<sub>GS(max)</sub> | Absolute limit before oxide breakdown | ±16V |
| Total Gate Charge | Q<sub>g</sub> | Charge needed to switch on; drives switching speed | 48nC |
Power Dissipation Formula
When fully on, the MOSFET dissipates heat as a simple resistor:
P = I² × R<sub>DS(on)</sub>
At 10A through a part with 22mΩ: P = 100 × 0.022 = 2.2W. That requires a heatsink. At 10A through a 2mΩ part: P = 0.2W, and no heatsink is needed. This is why low R<sub>DS(on)</sub> matters.
Logic-Level vs. Standard MOSFETs
A standard MOSFET like the IRF540N needs about 10V at the gate to reach its rated R<sub>DS(on)</sub>. A logic-level MOSFET reaches full conduction at 4.5V or even 2.5V.
| Part | V<sub>DSS</sub> | R<sub>DS(on)</sub> | Full-On V<sub>GS</sub> | Works with 3.3V MCU? |
|---|---|---|---|---|
| IRF540N | 100V | 44mΩ | 10V | No |
| IRLZ44N | 55V | 22mΩ | 5V | Marginal |
| AO3400 | 30V | ~30mΩ | 2.5-4.5V | Yes |
| IRLB8721 | 30V | 8.7mΩ | 4.5V | Yes |
| 2N7000 | 60V | 5Ω | 4.5-10V | Small loads only |
Rule of thumb: Check the R<sub>DS(on)</sub> specification at your actual gate drive voltage. If the datasheet lists R<sub>DS(on)</sub> only at V<sub>GS</sub> = 10V, assume the part is not logic-level.
MOSFET vs. BJT: Why MOSFETs Win
| Factor | MOSFET | BJT |
|---|---|---|
| Control method | Voltage | Current |
| Input impedance | Extremely high (>10<sup>9</sup>Ω) | Low (kΩ range) |
| On-state loss | Resistive (I²R), very low | Fixed V<sub>CE(sat)</sub> drop (~0.2V) |
| Switching speed | Very fast (nanoseconds) | Slower (storage time) |
| Thermal runaway | Resistant (positive tempco) | Prone to it |
| Parallel operation | Easy | Needs balancing resistors |
| ESD sensitivity | High (gate oxide) | Low |
Three reasons explain the dominance of MOSFETs:
- Efficiency. Milliohm-level R<sub>DS(on)</sub> wastes almost no power as heat.
- Simple drive. No base current means GPIO pins drive them directly.
- Scaling. MOSFETs shrink to nanometer dimensions. Billions fit on a single CPU die as CMOS logic gates.
Circuit Diagram Breakdown: Low-Side N-Channel Switch
The most common MOSFET circuit places the load between the supply and the drain, with the source tied to ground.
+12V
|
[LOAD] (motor, LED strip, relay coil)
|
D
GPIO --[R1 220Ω]--G (N-MOSFET)
| S
[R2 10kΩ] |
| |
GND --------GND
Component Roles
- R1 (220Ω gate resistor): Limits the inrush current that charges the gate capacitance. It also damps ringing on fast edges.
- R2 (10kΩ pulldown): Holds the gate at 0V during microcontroller boot, when GPIO pins float. Without it, the load can turn on randomly.
- Flyback diode (for inductive loads): Place a diode such as the 1N4007 or SS34 across the motor or relay coil. Cathode goes to the positive rail. It clamps the voltage spike when the coil de-energizes.
Why Low-Side?
An N-channel device on the low side needs the gate only a few volts above ground. Any logic-level MCU can supply that. The tradeoff: the load’s ground is no longer true ground when the switch is off.
High-Side Switching
For loads that must stay grounded, use a P-channel MOSFET on the supply side. The gate must be pulled to the supply voltage to turn the device off. When the supply exceeds the MCU’s logic voltage (for example 12V), add an NPN transistor or a second small N-MOSFET as a level shifter.
Firmware: Controlling a MOSFET With Arduino and ESP32
Arduino (C++): PWM Dimming on a 12V LED Strip
// MOSFET gate connected to Arduino Pin 9 (PWM-capable, ~490Hz)
const int MOSFET_GATE = 9;
void setup() {
pinMode(MOSFET_GATE, OUTPUT); // Pin drives the gate through R1
digitalWrite(MOSFET_GATE, LOW); // Start with the MOSFET off
}
void loop() {
// Ramp brightness up: duty cycle 0 -> 255 (8-bit resolution)
for (int duty = 0; duty <= 255; duty++) {
analogWrite(MOSFET_GATE, duty); // Average load voltage = 12V * duty/255
delay(10);
}
// Ramp brightness down
for (int duty = 255; duty >= 0; duty--) {
analogWrite(MOSFET_GATE, duty);
delay(10);
}
}
ESP32 (Arduino Core 3.x): High-Frequency PWM
// ESP32 GPIO18 drives a logic-level MOSFET gate via 220-ohm resistor
const int GATE_PIN = 18;
const int PWM_FREQ = 20000; // 20kHz: above human hearing, quiet for motors
const int PWM_RES = 10; // 10-bit resolution: duty range 0-1023
void setup() {
// Core 3.x API: attach pin with frequency and resolution in one call
ledcAttach(GATE_PIN, PWM_FREQ, PWM_RES);
}
void loop() {
ledcWrite(GATE_PIN, 512); // 50% duty cycle (512/1023)
delay(2000);
ledcWrite(GATE_PIN, 1023); // 100% duty: fully on
delay(2000);
ledcWrite(GATE_PIN, 0); // 0% duty: fully off
delay(2000);
}
Note: On ESP32 Arduino Core 2.x, use ledcSetup(channel, freq, res) and ledcAttachPin(pin, channel) instead.
MicroPython (Raspberry Pi Pico)
from machine import Pin, PWM
import time
gate = PWM(Pin(15)) # GP15 drives the MOSFET gate
gate.freq(20000) # 20kHz PWM frequency
while True:
gate.duty_u16(32768) # 50% duty (65535 = 100%)
time.sleep(2)
gate.duty_u16(0) # Off
time.sleep(2)
Real-World Project: PWM Motor Speed Controller
This build drives a 12V DC motor at variable speed from an ESP32.
Parts List
| Qty | Component | Spec |
|---|---|---|
| 1 | ESP32 DevKit | 3.3V logic |
| 1 | AO3400 or IRLB8721 | Logic-level N-MOSFET |
| 1 | 220Ω resistor | Gate resistor |
| 1 | 10kΩ resistor | Gate pulldown |
| 1 | 1N5819 Schottky diode | Flyback protection |
| 1 | 12V DC motor | Under 3A stall current |
| 1 | 12V power supply | Shared ground with ESP32 |
Wiring Steps
- Connect the MOSFET source to GND.
- Connect ESP32 GPIO18 to the gate through the 220Ω resistor.
- Connect the 10kΩ resistor from gate to GND.
- Connect the motor between +12V and the MOSFET drain.
- Place the 1N5819 diode across the motor terminals, with the cathode on +12V.
- Tie the ESP32 GND to the 12V supply GND.
Use the 20kHz PWM code above. Increase the duty value to speed up the motor.
Protecting Against Voltage Spikes
Inductive loads generate spikes far above the supply voltage. Four protection layers help:
- Flyback diode across the load (mandatory for motors and relays).
- TVS diode on the supply rail for harsh environments.
- Optocoupler (such as the PC817) between the MCU and gate driver to isolate high-voltage domains.
- Gate zener (15V) from gate to source to clamp gate overvoltage.
Troubleshooting Common MOSFET Failures
| Symptom | Likely Cause | Fix |
|---|---|---|
| MOSFET runs hot | Not fully on; V<sub>GS</sub> too low | Use a logic-level part or a gate driver |
| Load turns on at power-up | Floating gate | Add a 10kΩ pulldown |
| MOSFET dies instantly | V<sub>GS</sub> exceeded ±20V, or ESD | Add gate zener; handle with ESD care |
| Load never turns off | Drain-source short, or flyback diode reversed | Test with a multimeter in diode mode |
| Motor stutters at low duty | PWM frequency too low or MOSFET too slow | Raise frequency to 20kHz |
| Voltage spikes crash the MCU | No flyback diode | Add a diode across the inductive load |
Testing a MOSFET With a Multimeter
- Set the meter to diode mode.
- Measure from source to drain (red on S, black on D for N-channel). You should read about 0.4-0.7V through the body diode.
- Reverse the probes. You should read OL (open).
- Touch gate to drain briefly with a finger, then retest D to S. A working device may now conduct both ways because the gate capacitance holds charge. Short gate to source to discharge it.
When to Use a Gate Driver
A microcontroller pin supplies only 20-40mA. Large MOSFETs have high Q<sub>g</sub>, so a weak pin charges the gate slowly. The device lingers in the linear region and overheats.
Use a dedicated driver such as the TC4427, IR2104, or MCP1407 when:
- Switching above 50kHz.
- Using MOSFETs with Q<sub>g</sub> above 30nC.
- Building half-bridge or H-bridge circuits.
- Driving a high-side N-channel device (bootstrap drivers like the IR2104 handle this).
FAQ
What is the difference between the gate, source, and drain of a MOSFET?
The gate is the control terminal. The source is the terminal that supplies charge carriers. The drain is where those carriers leave. In an N-channel device, current flows from drain to source when the gate voltage exceeds the source by the threshold voltage.
Can I drive a MOSFET directly from an Arduino or ESP32 pin?
Yes, if the MOSFET is logic-level. Check that R<sub>DS(on)</sub> is specified at V<sub>GS</sub> = 3.3V (ESP32) or 5V (Arduino Uno). Add a 100-330Ω series resistor and a 10kΩ pulldown. For fast switching or large MOSFETs, use a gate driver.
Why do MOSFETs get hot?
Two causes dominate. Conduction loss comes from I² × R<sub>DS(on)</sub> and grows with current. Switching loss occurs when the device passes through the linear region during transitions and grows with PWM frequency and gate charge. Fix conduction loss with a lower R<sub>DS(on)</sub> part. Fix switching loss with a stronger gate driver.
What is the difference between a MOSFET and a transistor?
A MOSFET is a type of transistor. The other major type is the BJT (Bipolar Junction Transistor). MOSFETs use voltage at the gate to control current and offer lower on-state losses and a simpler drive. BJTs use base current and suit some low-cost analog applications.




