If you have ever tried to spin a DC motor or light up an LED strip directly from an Arduino or ESP32 pin, you have probably discovered the hard way that it does not work — or worse, you damaged your microcontroller. The missing piece in nearly every beginner's toolkit is the MOSFET, a simple component that lets a tiny signal from your microcontroller switch heavy loads on and off thousands of times per second.
This guide covers everything you need to know to start using MOSFETs in your projects: how they work, which ones to buy, how to wire them up, and the critical mistakes that burn components.
Why You Cannot Drive Motors Directly from GPIO Pins
An Arduino Uno GPIO pin can source or sink a maximum of 40 mA at 5V. An ESP32 GPIO pin is even more limited at roughly 12 mA at 3.3V. A typical small DC motor draws 200-800 mA, and a 12V cooling fan can easily pull 1-2A. An LED strip might demand 3-5A depending on its length.
Connecting a motor directly to a GPIO pin creates two problems:
- Insufficient current — the motor stalls or barely twitches because the pin cannot supply enough current.
- Damage to the microcontroller — drawing excess current through the pin can permanently destroy the GPIO or the entire chip.
You need a component that can act as an electrically controlled switch: something your low-power signal can toggle, which in turn connects or disconnects a high-power circuit. That component is the MOSFET.
What Is a MOSFET?
MOSFET stands for Metal-Oxide-Semiconductor Field-Effect Transistor. Despite the intimidating name, it functions as an electronic switch with three terminals:
- Gate (G) — the control terminal. Apply a voltage here to turn the switch on or off. Almost no current flows into the gate, making it perfect for microcontroller control.
- Drain (D) — where current flows in from the load.
- Source (S) — where current flows out (to ground, in the most common configuration).
When the voltage between Gate and Source (Vgs) exceeds a threshold, the MOSFET turns on and allows current to flow from Drain to Source with very low resistance. When Vgs drops below the threshold, the MOSFET turns off and current stops flowing. Unlike a mechanical relay, this switching happens in nanoseconds with no moving parts, no wear, and no sparking.
Think of it like a water valve: the gate is the handle (which takes almost no effort to turn), and the drain-to-source channel is the pipe that either allows or blocks a massive flow of water.
N-Channel vs P-Channel MOSFETs
There are two main types of MOSFETs, and picking the right one matters.
N-Channel MOSFETs are turned on by applying a positive voltage to the gate relative to the source. They are placed on the low side of the circuit — between the load and ground. This is the most common configuration for maker projects because the source connects directly to ground, making it easy to drive from a microcontroller.
P-Channel MOSFETs are turned on by applying a negative voltage to the gate relative to the source. They are placed on the high side of the circuit — between the power supply and the load. They are useful when you need to switch the positive rail, but they are generally more expensive, have higher on-resistance, and are trickier to drive from a microcontroller.
Rule of thumb: Use N-channel MOSFETs for most hobbyist projects. You will only need P-channel MOSFETs when building an H-bridge or when the load must connect directly to ground for other reasons.
Key MOSFET Specifications
Before buying a MOSFET, check these four specs in the datasheet:
Vgs(th) — Gate Threshold Voltage
The minimum gate-to-source voltage needed to start turning the MOSFET on. This is the most critical spec for microcontroller projects. A MOSFET with a Vgs(th) of 2-4V will not fully turn on with a 3.3V ESP32 signal. You need a logic-level MOSFET with a Vgs(th) under 2V to work reliably with 3.3V logic.
Rds(on) — On-Resistance
The resistance between drain and source when the MOSFET is fully on. Lower is better. This determines how much heat the MOSFET generates. An Rds(on) of 0.022 ohms at Vgs=5V means the MOSFET barely wastes any power. An Rds(on) of 0.2 ohms under the same conditions will generate significant heat at high currents.
Id(max) — Maximum Continuous Drain Current
The maximum current the MOSFET can handle continuously. Always choose a MOSFET rated for at least 2x your expected load current to provide a safety margin and keep temperatures manageable.
Vds(max) — Maximum Drain-Source Voltage
The maximum voltage the MOSFET can block when turned off. For a 12V motor, a MOSFET rated for 55V or 100V is more than sufficient.
Popular MOSFETs for Makers: A Comparison
Here are three MOSFETs you will encounter most often in the Indian maker ecosystem:
| Spec | IRF520 | IRLZ44N | IRF3205 |
|---|---|---|---|
| Type | N-Channel | N-Channel | N-Channel |
| Vds (max) | 100V | 55V | 55V |
| Id (max) | 9.2A | 47A | 110A |
| Vgs(th) | 2.0 - 4.0V | 1.0 - 2.0V | 2.0 - 4.0V |
| Rds(on) | 0.27 ohm (at Vgs=10V) | 0.022 ohm (at Vgs=5V) | 0.008 ohm (at Vgs=10V) |
| Logic-level (3.3V)? | No | Yes | No |
| Logic-level (5V)? | Partially | Yes | Partially |
| Package | TO-220 | TO-220 | TO-220 |
| Best for | Light 5V loads only | Most maker projects | High-current with gate driver |
| Price (approx) | 15-25 INR | 30-50 INR | 35-60 INR |
The Logic-Level Problem
This is the single most common mistake beginners make. The IRF520 has a Vgs(th) of 2-4V, which means it starts conducting at 2-4V but does not fully turn on until Vgs reaches 8-10V. If you connect an IRF520 to an ESP32 (3.3V logic), the MOSFET will be barely on — it will have high resistance, generate excessive heat, and not deliver full power to your load. With a 5V Arduino, it works somewhat but still runs warm because Vgs=5V is below its optimal operating point.
The IRLZ44N is specifically designed as a logic-level MOSFET. Its Vgs(th) is 1.0-2.0V, and it achieves very low Rds(on) at Vgs=5V. Even at Vgs=3.3V, it turns on well enough for most applications. This is the go-to MOSFET for Arduino and ESP32 projects.
Bottom line: If you are buying one MOSFET for general use, get the IRLZ44N.
Wiring: N-Channel Low-Side Switching
The standard circuit for controlling a load with an N-channel MOSFET:
+Vmotor (e.g., 12V)
|
[LOAD] (motor, LED strip, fan, etc.)
|
Drain (D)
|
[MOSFET]
|
Source (S)
|
GND ---- (shared with Arduino/ESP32 GND)
Gate (G) <--- 220 ohm resistor <--- GPIO pin
Gate (G) <--- 10K ohm resistor ---> GND (pull-down)
Key points:
- The load goes between the positive supply and the Drain.
- The Source connects to ground.
- The Gate connects to your GPIO pin through a small resistor.
- A 10K pull-down resistor between Gate and Source ensures the MOSFET stays off when the microcontroller is not actively driving the gate (during boot, reset, etc.).
- The Arduino/ESP32 GND must be connected to the same ground as the motor power supply. This is critical — without a common ground, the circuit will not work.
Flyback Diode: Non-Negotiable for Inductive Loads
Motors, solenoids, and relays are inductive loads. When you suddenly turn off current through an inductor, it generates a voltage spike in the opposite direction. This spike can be hundreds of volts — enough to instantly destroy your MOSFET.
The solution is a flyback diode (also called a freewheeling diode) connected across the load:
+Vmotor
|
+------+------+
| |
[MOTOR] [DIODE: 1N4007]
(load) cathode at top (+V side)
| anode at bottom (drain side)
+------+------+
|
Drain (D)
The diode is reverse-biased during normal operation so it does nothing. When the MOSFET turns off and the motor generates a reverse voltage spike, the diode becomes forward-biased and safely absorbs the energy.
Use a 1N4007 (rated for 1A, 1000V) for most small motors, or a 1N5819 Schottky diode for faster switching and PWM applications. For motors drawing over 3A, use a beefier diode like the MBR2045 or SB560.
Never skip the flyback diode. A MOSFET that works perfectly for days will suddenly die without one — the voltage spikes are cumulative and unpredictable.
Gate Resistor: Preventing Oscillation
A small resistor (typically 100-220 ohms) in series between the GPIO pin and the MOSFET gate serves two purposes:
- Limits inrush current — the MOSFET gate has significant capacitance. Without a resistor, the GPIO pin sees a momentary short circuit every time it switches.
- Prevents oscillation — at high PWM frequencies, parasitic inductance in the wires combined with gate capacitance can cause the MOSFET to oscillate, leading to overheating and erratic behavior.
For most hobbyist applications at PWM frequencies under 25 kHz, a 220 ohm gate resistor works well. For higher frequencies, reduce to 100 ohms or even 47 ohms — but keep the wires short.
Code: PWM Motor Speed Control with Arduino
// Arduino PWM Motor Speed Control via MOSFET
// MOSFET gate connected to pin 9 (PWM-capable)
const int MOSFET_PIN = 9;
const int POT_PIN = A0; // Potentiometer for speed control
void setup() {
pinMode(MOSFET_PIN, OUTPUT);
analogWrite(MOSFET_PIN, 0); // Start with motor off
Serial.begin(9600);
}
void loop() {
// Read potentiometer (0 - 1023)
int potValue = analogRead(POT_PIN);
// Map to PWM range (0 - 255)
int pwmValue = map(potValue, 0, 1023, 0, 255);
// Drive MOSFET gate
analogWrite(MOSFET_PIN, pwmValue);
// Print speed percentage
int speedPercent = map(pwmValue, 0, 255, 0, 100);
Serial.print("Motor speed: ");
Serial.print(speedPercent);
Serial.println("%");
delay(50);
}
Arduino's analogWrite() generates a PWM signal at approximately 490 Hz on most pins (or 980 Hz on pins 5 and 6). This is fine for most DC motors but may produce an audible whine. You can adjust the timer registers to change the PWM frequency if needed.
Code: PWM Motor Speed Control with ESP32
The ESP32 uses its dedicated LEDC (LED Control) peripheral for PWM, offering much finer control over frequency and resolution.
// ESP32 PWM Motor Speed Control via MOSFET
// MOSFET gate connected to GPIO 18
const int MOSFET_PIN = 18;
const int POT_PIN = 34; // ADC input for potentiometer
const int PWM_FREQ = 20000; // 20 kHz — above audible range
const int PWM_RESOLUTION = 8; // 8-bit: 0-255
const int PWM_CHANNEL = 0;
void setup() {
// Configure LEDC PWM
ledcAttachPin(MOSFET_PIN, PWM_CHANNEL);
ledcSetup(PWM_CHANNEL, PWM_FREQ, PWM_RESOLUTION);
ledcWrite(PWM_CHANNEL, 0); // Start with motor off
Serial.begin(115200);
}
void loop() {
// Read potentiometer (ESP32 ADC: 0 - 4095)
int potValue = analogRead(POT_PIN);
// Map to PWM range (0 - 255 for 8-bit resolution)
int pwmValue = map(potValue, 0, 4095, 0, 255);
// Drive MOSFET gate
ledcWrite(PWM_CHANNEL, pwmValue);
// Print speed percentage
int speedPercent = map(pwmValue, 0, 255, 0, 100);
Serial.print("Motor speed: ");
Serial.print(speedPercent);
Serial.println("%");
delay(50);
}
Why 20 kHz? PWM frequencies below roughly 18 kHz are within human hearing range and cause an annoying whine from the motor. Setting the frequency to 20 kHz or above eliminates this noise entirely. The ESP32's LEDC peripheral makes this trivial to configure.
Important note for ESP32: Since the ESP32 outputs 3.3V logic, you must use a logic-level MOSFET like the IRLZ44N. A standard IRF520 or IRF3205 will not fully turn on at 3.3V Vgs, resulting in high resistance, heat buildup, and reduced motor power.
Heat Dissipation: When Do You Need a Heatsink?
Every MOSFET dissipates some power as heat when current flows through it. The formula is:
P = I squared x Rds(on)
For example, with an IRLZ44N (Rds(on) = 0.022 ohm) driving a 5A load:
P = 5 x 5 x 0.022 = 0.55W
Half a watt is manageable without a heatsink for the TO-220 package.
Now consider an IRF520 (Rds(on) = 0.27 ohm at Vgs=10V, much worse at lower Vgs) at 5A:
P = 5 x 5 x 0.27 = 6.75W
That will overheat and potentially destroy the MOSFET without a large heatsink and possibly active cooling.
Guidelines:
- Under 1W: No heatsink needed for TO-220 package.
- 1-3W: Attach a small clip-on heatsink (commonly available for 5-10 INR).
- Over 3W: Use a proper finned heatsink and consider active airflow. Better yet, choose a MOSFET with lower Rds(on).
Remember that Rds(on) increases with temperature, creating a thermal runaway risk. Always design with headroom.
H-Bridge: Bidirectional Motor Control
A single low-side MOSFET can only turn a motor on and off in one direction. To reverse a motor's direction, you need an H-bridge — a circuit that uses four switches arranged in an H pattern.
+V ----+----------+---- +V
| |
[Q1 P-ch] [Q3 P-ch]
| |
+--[MOTOR]-+
| |
[Q2 N-ch] [Q4 N-ch]
| |
GND ---+----------+--- GND
- Turn on Q1 + Q4: current flows left-to-right through the motor (forward).
- Turn on Q3 + Q2: current flows right-to-left through the motor (reverse).
- Never turn on Q1 + Q2 or Q3 + Q4 simultaneously — this creates a short circuit from +V to GND and will destroy the MOSFETs instantly.
Building a reliable H-bridge from discrete MOSFETs requires careful gate driving with dead-time protection to prevent shoot-through. For most projects, it is safer and simpler to use a dedicated motor driver IC.
MOSFET vs Relay vs Motor Driver IC
Choosing the right switching method depends on your project requirements:
| Feature | MOSFET (discrete) | Relay | L298N | TB6612FNG |
|---|---|---|---|---|
| Switching speed | Nanoseconds | 5-15 ms | Microseconds | Microseconds |
| PWM capable | Yes (high freq) | No | Yes (up to ~25 kHz) | Yes (up to ~100 kHz) |
| Direction control | One direction (single) | Bidirectional (DPDT) | Bidirectional | Bidirectional |
| Max current | 10-110A (varies) | 10-30A (varies) | 2A per channel | 1.2A per channel (3.2A peak) |
| Voltage drop | ~0.01-0.1V | ~0V (contact) | ~2-4V (bipolar) | ~0.5V |
| Efficiency | Very high | Very high | Poor (heat) | Good |
| Electrical isolation | No | Yes | No | No |
| Size | Small (TO-220) | Large | Large module | Small breakout |
| Complexity | Low (1 direction), High (H-bridge) | Very low | Very low (module) | Low (module) |
| Cost | 30-60 INR per MOSFET | 40-100 INR | 150-250 INR (module) | 200-350 INR (module) |
| Best for | High-current on/off, PWM dimming | AC loads, isolation needed | Beginner motor projects | Efficient small motor control |
When to use each:
- Single MOSFET: Fan speed control, LED strip dimming, pump on/off, solenoid driving — any single-direction DC load where you want PWM and efficiency.
- Relay: Switching AC mains loads (with appropriate safety), situations requiring electrical isolation, or simple on/off without PWM.
- L298N: Quick prototyping of bidirectional motor control. Note: the L298N uses bipolar transistors internally and drops 2-4V, making it inefficient for low-voltage motors.
- TB6612FNG: A modern, efficient MOSFET-based motor driver for smaller motors (under 1.2A continuous). Much better efficiency than the L298N.
Common Mistakes and How to Avoid Them
1. Floating Gate
A MOSFET gate that is not connected to anything (or connected to a high-impedance source during microcontroller boot) will pick up stray electrical noise and randomly turn on and off. Your motor will twitch unpredictably.
Fix: Always use a 10K pull-down resistor from gate to source. This ensures the MOSFET stays off by default.
2. Insufficient Vgs
Using a standard MOSFET (like IRF520 or IRF3205) with a 3.3V microcontroller. The MOSFET operates in its linear region — partially on — acting more like a resistor than a switch. It gets scorching hot and delivers reduced power to the load.
Fix: Use a logic-level MOSFET (IRLZ44N, IRL540N, IRLB8721) rated for full enhancement at your logic voltage. Alternatively, use a gate driver or a simple NPN transistor (like 2N2222) to level-shift from 3.3V to 12V for the gate.
3. No Flyback Diode
The motor works fine until one day the MOSFET fails silently. The inductive voltage spikes from the motor have been gradually degrading the MOSFET until it finally breaks down.
Fix: Always install a flyback diode across inductive loads. A 1N4007 for small motors, a 1N5819 Schottky for PWM applications.
4. Exceeding Current Rating
Running a motor that draws 15A through a MOSFET rated for 9A continuous. Even if the MOSFET does not fail immediately, it will overheat and its Rds(on) will rise, creating more heat in a destructive feedback loop.
Fix: Choose a MOSFET with a maximum drain current rating of at least 2x your expected load current. Account for motor stall current, which can be 5-8x the running current.
5. No Common Ground
The motor power supply and the microcontroller have separate grounds that are not connected. The MOSFET gate voltage is measured relative to the source — without a shared ground reference, Vgs is undefined and the circuit behaves erratically.
Fix: Always connect the grounds of your microcontroller power supply and your motor/load power supply.
6. Excessive Gate Capacitance at High Frequencies
At high PWM frequencies (above 20 kHz), the microcontroller struggles to charge and discharge the MOSFET gate capacitance quickly enough. The MOSFET spends more time transitioning between on and off states, dissipating power and heating up.
Fix: Use a MOSFET with low gate charge (Qg), add a proper gate driver IC (like the TC4427), and keep gate wiring as short as possible.
Practical Projects
Here are real-world applications you can build with MOSFETs:
Fan Speed Controller
Use an IRLZ44N with PWM from an ESP32 to control a 12V DC fan. Add a DHT22 temperature sensor and write firmware that automatically adjusts fan speed based on temperature. Perfect for 3D printer enclosures or electronics cooling.
Components: ESP32, IRLZ44N, 12V DC fan (0.2-0.5A), 1N4007, 220 ohm gate resistor, 10K pull-down, DHT22, 12V power supply.
LED Strip Dimmer
12V LED strips draw significant current (up to 1.2A per meter for a 5050 strip). Use three MOSFETs to independently control the red, green, and blue channels of an RGB strip for full color mixing and dimming.
Components: ESP32 (3 PWM channels), 3x IRLZ44N, 12V RGB LED strip, 3x 220 ohm gate resistors, 3x 10K pull-downs, 12V power supply sized for your strip length.
Solenoid Driver
Solenoids for door locks and valves draw 0.5-2A and are highly inductive. The MOSFET switches the solenoid while the flyback diode is especially critical here due to the strong inductive kick.
Components: Arduino/ESP32, IRLZ44N, 12V solenoid, 1N4007 flyback diode, 220 ohm gate resistor, 10K pull-down, 12V power supply.
Water Pump Controller
Control a 12V submersible pump for hydroponics, aquaponics, or automated plant watering. Combine with a soil moisture sensor or timer-based scheduling.
Components: ESP32 (for Wi-Fi scheduling), IRLZ44N, 12V submersible pump (1-3A), 1N5819 Schottky diode, 220 ohm gate resistor, 10K pull-down, 12V power supply.
High-Power Motor Control
For motors drawing over 10A (electric scooters, robotics), use an IRF3205 with a proper gate driver circuit. The IRF3205's extremely low Rds(on) of 0.008 ohms minimizes heat even at high currents, but it requires 10V Vgs for full enhancement — a gate driver like the TC4427 boosts your microcontroller's 3.3V or 5V signal to the required level.
Components: Microcontroller, TC4427 gate driver, IRF3205, high-current motor, MBR2045 flyback diode, heatsink, appropriately gauged wiring.
Quick Reference: Choosing Your MOSFET
Follow this decision tree:
-
What is your logic voltage?
- 3.3V (ESP32, Raspberry Pi Pico): You must use a logic-level MOSFET (IRLZ44N, IRLB8721).
- 5V (Arduino Uno, Mega, Nano): Logic-level MOSFETs are ideal, but standard MOSFETs will partially work.
- Need a standard MOSFET at low logic voltage? Add a gate driver IC.
-
How much current does your load draw?
- Under 5A: IRLZ44N is perfect.
- 5-20A: IRLZ44N or IRF3205 with heatsink.
- Over 20A: IRF3205 with gate driver, heatsink, and thick wiring.
-
Is the load inductive?
- Yes (motors, solenoids, relays): Add a flyback diode. Non-negotiable.
- No (LEDs, resistive heaters): Flyback diode not required, but does not hurt to include.
-
Do you need bidirectional control?
- No: Single N-channel MOSFET, low-side switching.
- Yes: Use a motor driver module (TB6612FNG for small motors, BTS7960 for large ones) rather than building a discrete H-bridge.
Wrapping Up
MOSFETs are one of the most versatile and essential components in any maker's toolkit. A single IRLZ44N, a flyback diode, and a couple of resistors open up an enormous range of projects that a bare microcontroller simply cannot handle on its own. The key takeaways:
- Use logic-level MOSFETs (IRLZ44N) with Arduino and ESP32.
- Always include a flyback diode on inductive loads.
- Add a gate pull-down resistor (10K) to prevent floating gate problems.
- Add a gate series resistor (100-220 ohm) to limit inrush and prevent oscillation.
- Check your Rds(on) at your actual Vgs — datasheet headline numbers are at ideal conditions.
- Derate generously — choose a MOSFET rated for at least twice your expected current.
Once you are comfortable with single MOSFET switching, you can explore gate drivers for high-power applications, half-bridge and full-bridge configurations, and synchronous rectification for power conversion circuits. The fundamentals covered here will serve you well as you scale up.
Browse our full range of MOSFETs, motor drivers, and DC motors at Wavtron to get started on your next project.



