Relays and MOSFETs can both be used to switch electrical loads on and off, but they do it in completely different ways.
A relay is an electromechanical switch. A coil energizes a magnetic mechanism that physically opens or closes contacts.
A MOSFET is a semiconductor switch. A voltage applied to its gate controls current flow electronically with no moving parts.
For many modern electronics projects, MOSFETs are the better choice. However, relays still have important advantages in certain situations.
How a Relay Works
A relay contains:
- A coil that creates a magnetic field when energized.
- Movable contacts that open or close a circuit.
- Electrical isolation between the control circuit and the switched circuit.
When the coil is powered, the contacts physically move.
Relay advantages
- Can switch AC or DC.
- Provides galvanic isolation.
- Handles high voltages and high currents.
- Works with resistive, inductive, and mixed loads.
- Easy to understand and troubleshoot.
Relay disadvantages
- Mechanical wear over time.
- Slower switching speed.
- Audible clicking.
- Higher power consumption for the coil.
- Contact arcing with inductive loads.
- Larger physical size.
How a MOSFET Works
A MOSFET uses an electric field to control current flow.
In a typical N-channel MOSFET low-side switch:
- The source connects to ground.
- The drain connects to the load.
- The gate receives a control voltage from a microcontroller or driver.
When the gate voltage is high enough, the MOSFET turns on and conducts current with very low resistance.
MOSFET advantages
- No moving parts.
- Extremely fast switching.
- Silent operation.
- Very low control power.
- Compact size.
- Ideal for PWM and high-frequency switching.
- Long operational life.
MOSFET disadvantages
- Typically does not provide isolation by itself.
- Requires careful gate-drive design.
- More sensitive to voltage spikes and ESD.
- AC mains switching is more complex than with a relay.
- Heat dissipation must be considered at high current.
Use a MOSFET Instead of a Relay When…
1. You need fast switching
MOSFETs can switch in nanoseconds or microseconds. Relays typically take milliseconds.
Examples:
- Motor speed control with PWM
- LED dimming
- Switching power supplies
- Class-D audio amplifiers
- Battery management systems
2. You need PWM control
Relays are not suitable for rapid on/off modulation. MOSFETs excel at it.
Common uses:
- LED brightness control
- DC motor speed control
- Heater power regulation
- Solenoid current control
3. You want silent operation
Relays click. MOSFETs do not.
Important in:
- Consumer products
- Home automation
- Audio equipment
- Medical devices
4. Power efficiency matters
A relay coil continuously consumes power while energized. A MOSFET gate draws almost no steady-state current.
This is valuable for:
- Battery-powered systems
- Solar projects
- IoT devices
- Portable electronics
5. Space is limited
MOSFETs can be extremely small compared with relays.
Modern surface-mount MOSFETs are widely used in:
- Phones
- Laptops
- Power banks
- Compact embedded devices
Use a Relay Instead of a MOSFET When…
1. You need electrical isolation
A relay naturally isolates the control circuit from the switched circuit.
This is important when switching:
- Mains voltage
- Industrial equipment
- Different ground domains
- Unknown external circuits
2. You need to switch AC mains simply
A relay can switch AC with a simple contact arrangement.
Using MOSFETs for AC mains requires:
- Back-to-back MOSFETs
- Triacs
- SSRs
- Specialized drivers
For many hobby projects, a relay is simpler and safer.
3. You need complete off-state isolation
A relay physically opens the circuit.
A MOSFET usually still has:
- Leakage current
- Body diode behavior
- Semiconductor conduction paths
For some applications, physical disconnection is preferred.
4. The load type is unpredictable
Relays are often more forgiving when switching mixed AC/DC loads, especially in repair, industrial, or prototype environments.
Typical Decision Guide
| Application | Preferred Device |
|---|---|
| LED dimming | MOSFET |
| DC motor speed control | MOSFET |
| Battery-powered IoT device | MOSFET |
| Switching a 5 V heater with PWM | MOSFET |
| Switching a lamp on/off occasionally | Relay or MOSFET |
| Controlling 230 V AC mains | Relay (or SSR) |
| Need galvanic isolation | Relay |
| Emergency power disconnect | Relay/contactor |
| High-frequency switching | MOSFET |
| Silent operation required | MOSFET |
Important
Watch the MOSFET gate voltage
One common beginner mistake is using a standard MOSFET with a 3.3 V microcontroller.
Many MOSFETs require a much higher gate voltage for low resistance.
For ESP32, RP2040, STM32, and similar systems, choose a logic-level MOSFET that is specified for full enhancement at 3.3 V or 4.5 V gate drive.
Otherwise the MOSFET may run hot or fail to switch properly.
Real-World Example: ESP32 Controlling an LED Strip
Suppose you want to control a 12 V LED strip from an ESP32.
A relay would only allow on/off control.
A MOSFET allows:
- On/off control
- Brightness adjustment via PWM
- Silent operation
- Low power consumption
- High reliability
In this case, a MOSFET is clearly the better choice.
Real-World Example: Controlling a Mains Appliance
If you want a microcontroller to switch a 230 V AC heater or lamp, a relay module provides:
- Electrical isolation
- Simple wiring
- Clear separation between low-voltage control and mains voltage
For many hobby and industrial applications, this simplicity is valuable.
A Useful Rule of Thumb
If the load is low-voltage DC and you want speed, efficiency, PWM, or silent operation, use a MOSFET.
If the load is mains AC, requires isolation, or is switched infrequently, a relay is often the simpler and safer choice.
Many modern designs actually use both technologies: MOSFETs for fast electronic control and relays for isolation or safety-critical disconnection.
The key is understanding the strengths and limitations of each device and choosing the one that matches the electrical and safety requirements of the application.
For most ESP32, Raspberry Pi Pico, and STM32 projects:
- Choose a logic-level N-channel MOSFET.
- Add a flyback diode across inductive loads such as motors, relays, and solenoids.
- Use a relay when switching mains voltage or when isolation is required.
- Use a MOSFET for PWM, dimming, motor speed control, and battery-powered designs.
That simple guideline covers the majority of practical electronics projects.
