Relay vs MOSFET: Picking the Right Switch for AC Loads, DC Loads and PWM

Relays and MOSFETs both switch loads, but they solve different problems. A relay gives you cheap galvanic isolation and handles AC or DC up to its contact rating, but it switches in milliseconds, clicks, and its contacts wear out after ~100,000 cycles. A MOSFET switches in nanoseconds, runs silent PWM for years, but needs the right drive voltage and shares ground with your logic. This guide compares them head to head, works the heat dissipation math, and gives you driver circuits for both.

Written by Projectech15 min readPublished
For B.E./B.Tech Electronics and E&TC students selecting switching devices for microcontroller projects Topics: Relay, MOSFET, Optocoupler, Flyback Diode, PWM, SSR
Illustration of an electromagnetic relay module beside a power MOSFET with heatsink on a breadboard, showing the two switching options.
Illustration generated for this guide.
In this guide

Ask ten students how they switch a 230 V AC bulb from an Arduino and nine will wire a relay module — and the tenth will be back a week later with a welded relay or a rebooting Arduino, asking why. Switching looks trivial until the load misbehaves. The choice between a relay and a MOSFET (or, often, why you need both in the same project) is one of the most practical decisions in an electronics build, and getting it wrong costs you in burnt contacts, rebooting controllers, or a dimmer that flickers.

This guide compares electromagnetic relays and MOSFETs on the things that actually matter for a student project: switching speed, isolation, lifespan, heat, drive requirements, and cost. Every recommendation comes with a real part number, a driver circuit you can build, and the math that tells you whether it will survive. The examples assume Arduino/ESP32 logic levels — if you are still choosing your controller, read the ESP32 vs Arduino vs Raspberry Pi comparison first.

The one-paragraph version for people in a hurry

Use a relay when: you are switching mains AC (230 V) loads, you need isolation between the low-voltage logic and the high-voltage side without thinking about it, the load switches rarely (a pump a few times a day, a heater on a thermostat), or the load type is unknown — relays do not care about AC or DC.

Use a MOSFET when: you need fast switching (PWM dimming, motor speed control, switching at all), silent long-life operation (millions of cycles), or low-voltage DC loads with tight efficiency needs (battery projects).

Use both when: the classic home-automation pattern needs it — a relay for the AC appliance and a MOSFET for the DC side, e.g. driving a 12 V solenoid or a DC fan at variable speed inside an AC-powered panel.

The failure this guide prevents most often: driving a 5 V relay coil straight from an Arduino digital pin. A typical SRD-05VDC relay coil draws 70–90 mA at 5 V. An Arduino pin is rated for 20 mA continuous (40 mA absolute maximum). The pin overheats, the board resets, and the student concludes the code is wrong. Always use a transistor driver — circuit below.

What a relay actually is (and why it clicks)

An electromagnetic relay is a mechanical switch pulled closed by an electromagnet. Energise the coil, the contacts snap shut with an audible click; drop the coil, a spring pulls them open. The common small relay in student kits is the SRD-05VDC-SL-C family (the blue cube on most relay modules): coil 5 V at roughly 70 mA, contacts rated 10 A at 250 VAC / 30 VDC on the better variants.

The numbers that matter, from typical datasheets of this class:

  • Switching time: about 10 ms operate, 5 ms release. Two orders of magnitude slower than any semiconductor.
  • Isolation: the coil circuit and the contact circuit share nothing but the plastic package — typically 1,000+ V AC isolation between coil and contacts. This is why a relay is the comfortable choice for mains: a fault on the load side does not walk straight into your 5 V logic.
  • Contact life: datasheet figures are usually quoted as around 100,000 operations at rated resistive load, dropping sharply with inductive loads (motors, solenoids) unless you snub them. At 10 switches per day, 100,000 cycles is 27 years; at 1 switch per second (a PWM job), it is 27 hours.
  • Contact resistance: a few milliohms when new, growing with wear. Passing 10 A through 30 mΩ of contact resistance dissipates I²R = 100 × 0.03 = 3 W — real heat on the contacts.
  • Coil power: a 5 V, 70 mA coil burns 0.35 W continuously while energised. In a battery project, a relay that stays on all day is a small heater you did not budget for.

The 10 A rating deserves a careful read. It is a resistive rating. A motor's inrush current can be 5–8× its running current; a cold incandescent filament is about 10× lower resistance than hot; arcing erodes contacts fast. Derate generously: for inductive AC loads, stay under roughly 40–50% of the resistive rating unless you know the inrush. When in doubt, move up a relay size rather than arguing with the datasheet.

What a MOSFET actually is (and why the gate matters)

A MOSFET is a voltage-controlled switch with no moving parts. For low-side switching (the overwhelmingly common student case) you use an N-channel MOSFET: drain to the load, source to ground, gate driven by your logic. Apply gate voltage above the threshold, the channel opens, current flows.

The numbers that matter:

  • Switching speed: tens of nanoseconds with a proper driver. Fast enough for PWM at any frequency a microcontroller generates — which is exactly what relays cannot do.
  • No wear: no contacts, no arcing, no mechanical cycle limit. A MOSFET in a PWM dimmer will switch billions of times without degrading, as long as heat is managed.
  • On-resistance (Rds(on)): the key datasheet figure. A good logic-level MOSFET like the IRLZ44N specifies Rds(on) around 22 mΩ at Vgs = 5 V; the AO3400 (SOT-23, handy on small modules) is roughly 30–40 mΩ. Dissipation is I² × Rds(on): 10 A through 22 mΩ = 2.2 W. At 1 A it is 22 mW — cold to the touch.
  • Gate threshold vs Rds(on) gate voltage: the classic trap. A MOSFET's Vgs(th) (1–2 V on the IRLZ44N) is where it starts to turn on, not where it is fully on. The Rds(on) figure is specified at a given Vgs (5 V or 10 V). A non-logic-level MOSFET like the IRF540N needs about 10 V on the gate for its rated Rds(on) — driving it from a 3.3 V ESP32 pin leaves it half-on, hot, and eventually dead. Always check which Vgs the Rds(on) line specifies, and match it to your logic voltage.
  • No inherent isolation: the gate driver and the load share a ground. If you need the load side electrically separated from your controller, add an optocoupler in front of the MOSFET — circuit below.

High-side vs low-side: the one decision people skip

Low-side switching (MOSFET between load and ground) is simple and works with any N-channel logic-level MOSFET. High-side switching (MOSFET between supply and load) is needed when the load's ground must stay grounded — automotive circuits, some motor drivers, shared-chassis designs. High-side with an N-channel device requires the gate to be driven above the supply rail (bootstrap or charge pump); with a P-channel device the logic inverts. For student projects, default to low-side N-channel switching unless a specific wiring constraint forces high-side — it is simpler, cheaper, and the failure modes are easier to debug.

Head-to-head comparison

Factor Relay (SRD-05 class) MOSFET (IRLZ44N class)
AC loads Yes — natural fit, isolated No (needs more circuitry); use a relay or SSR
DC loads Yes, within contact rating Yes — ideal use case
PWM / fast switching No — ~10 ms, contacts wear Yes — nanoseconds, unlimited cycles
Isolation logic to load Built-in (1 kV+) None by itself; add optocoupler
Lifespan ~100k cycles at rated load, less with inductive Effectively unlimited with proper heat
Silent operation No — audible click Yes
Coil/drive power ~0.35 W while on (5 V/70 mA) Gate draws ~nothing in steady state
Heat at 5 A Contacts: I²R, typically 0.5–1 W I²Rds(on): 25 × 0.022 ≈ 0.55 W
Cost (module) ₹80–150 per channel ₹60–120 per channel (module)
Failure mode Welded contacts, chatter Short circuit (often fails closed)

Note the heat row: at moderate currents a relay and a MOSFET dissipate similar power — the difference is where (contacts vs silicon) and how predictable. MOSFET heat is calculable from the datasheet; relay contact heat grows as contacts age.

The heat math (do this before you buy a heatsink)

MOSFET dissipation has two parts. Conduction loss dominates at the currents students use:

P_cond = I² × Rds(on)

Switching loss matters at high PWM frequencies:

P_sw ≈ ½ × V × I × (t_rise + t_fall) × f_pwm

Worked example: IRLZ44N switching a 12 V, 4 A DC motor at 20 kHz PWM, Rds(on) = 22 mΩ, rise+fall ≈ 100 ns total.

  • P_cond = 16 × 0.022 = 0.35 W
  • P_sw = 0.5 × 12 × 4 × 100e-9 × 20,000 = 0.048 W
  • Total ≈ 0.4 W — a bare TO-220 package handles this without a heatsink (its junction-to-ambient thermal resistance is about 62 °C/W, so 0.4 W raises the junction roughly 25 °C above ambient — fine).

Now the same part at 15 A: P_cond = 225 × 0.022 = 4.95 W. At 62 °C/W that is a ~300 °C rise — the MOSFET dies. You need a heatsink bringing total thermal resistance under ~20 °C/W, or a lower-Rds(on) part. This is a two-minute calculation that prevents most student MOSFET funerals.

Datasheet trap: Rds(on) rises with temperature — typically ~1.5–1.7× at 100 °C junction. Always compute with the hot value if the dissipation is significant. And if the MOSFET is too hot to hold your finger on for 3 seconds, it is above roughly 60 °C case temperature and you should fix the drive or the heatsink, not the code.

Driver circuits you can actually build

Circuit 1: Arduino to NPN transistor to 5 V relay (with flyback diode)

The relay coil is an inductor. When you switch it off, the collapsing magnetic field generates a voltage spike (back-EMF) that can reach tens of volts and kill your transistor or reset the MCU. The flyback diode across the coil clamps it. This circuit is non-negotiable for relay coils:

5V ----+----[relay coil]----+---- collector (2N2222)
       |                    |
      [1N4148 diode,       |
       cathode to 5V]      |
       |                    |
GND ---+--------------------+---- emitter (2N2222)
                                        |
Arduino D8 ---[1k]--- base (2N2222)

Rules: diode cathode toward the positive rail (it must be reverse-biased in normal operation); the 1 kΩ base resistor limits Arduino pin current to about 4 mA; a 2N2222 handles the ~70 mA coil comfortably. Relay modules sold in kits already include the transistor, diode, and usually an optocoupler — which is why modules are the recommended purchase for beginners, not bare relays.

Circuit 2: Arduino to logic-level N-channel MOSFET to DC load (low-side)

Load (e.g. 12V LED strip +)
        |
        +---- drain (IRLZ44N)
        |
Arduino D9 ---[220]--- gate (IRLZ44N) ---[10k]--- GND
        |
       source (IRLZ44N) ---- GND (common with 12V supply GND)

The 220 Ω gate resistor limits the inrush current into the gate capacitance (an Arduino pin sees a brief capacitive load); the 10 kΩ pulldown keeps the MOSFET off during MCU reset when the pin floats — without it the load can flicker on at power-up. For PWM, drive the gate from a hardware PWM pin (D3, D5, D6, D9, D10, D11 on an Uno).

Circuit 3: Optocoupler isolation in front of either switch

When the load side must be electrically separate from the controller — mains switching near sensitive analog sensors, or a noisy motor supply — put a PC817 optocoupler between the MCU and the switch:

Arduino D8 ---[220]---|>|--- GND        (LED side, pins 1-2 of PC817)
                        (PC817)
5V_iso ---[1k]--- collector (pin 4)      (transistor side, pins 3-4)
                    |
                    +--- to relay driver base / MOSFET gate
                    emitter (pin 3) --- GND_iso

The LED side and transistor side share no copper — isolation is by light. Relay modules with a jumper marked JD-VCC let you power the relay coils from a separate supply while the optocoupler LED runs from the Arduino rail: this is the configuration to use when switching mains, and it is the single most effective fix for "Arduino resets when the relay clicks" (the click's EMI couples through a shared supply).

The loads students actually switch, and what to pick

  • 230 V AC bulb / tube light / fan (on-off): relay module. The isolation is worth more than any cleverness. See Bluetooth home automation with HC-05 for the standard relay-module wiring pattern.
  • AC appliance + manual override panel: relay + proper enclosure and fusing — the smart home automation panel shows the panel layout.
  • LED strip dimming / DC motor speed control: MOSFET + PWM. A relay physically cannot dim; asking it to chatter at 500 Hz destroys the contacts in hours.
  • Capacitive-touch AC dimmer: this is a different device class (TRIAC/leading-edge dimming), covered in the capacitive touch dimmer panel — do not try to PWM an AC load with a DC MOSFET.
  • Solenoid lock / water pump (DC): MOSFET for the DC side, but size for the stall/inrush current and add a flyback diode across any inductive DC load — the same back-EMF physics as the relay coil applies.
  • Battery-powered switching: MOSFET, always. A relay's 0.35 W holding current is a continuous leak your battery budget did not include; a MOSFET's gate draws essentially zero in steady state.

Inductive loads: the flyback diode and the snubber

Any coil — relay, solenoid, DC motor, contactor — stores energy in its magnetic field (E = ½LI²). Interrupting the current forces that energy somewhere, producing a voltage spike V = L × di/dt that can be tens to hundreds of volts. The fixes:

  • DC coils: a flyback diode across the coil (cathode to positive), as in Circuit 1. A 1N4148 suffices for small relay coils; use a 1N4007 or a Schottky for larger solenoids and motors.
  • AC coils / relay contacts switching AC inductive loads: a diode does not work on AC. Use an RC snubber (typically 100 Ω + 100 nF in series) across the contacts, or a bidirectional TVS / MOV rated above the peak line voltage. This is what separates a relay that lasts years switching a fan from one that welds in a month.
  • MOSFET switching inductive DC loads: the flyback diode goes across the load, and many power MOSFETs include an intrinsic body diode — but the body diode is slow and lossy; an external Schottky across the motor is the reliable choice. For bidirectional motor drive, use an H-bridge module rather than discrete MOSFETs.

Solid-state relays: the third option

A solid-state relay (SSR) is a semiconductor switch packaged like a relay, with opto-isolation built in. The common Fotek-style SSR-25DA switches 24–380 VAC at up to 25 A with a 3–32 VDC control input — drive it straight from an Arduino pin through a current-limiting resistor. SSRs switch at zero-crossing (clean, no EMI burst), are silent, and last indefinitely.

The tradeoffs: an SSR drops roughly 1–1.6 V across its output, so at 10 A it dissipates 10–16 W and needs its heatsink — a relay's contacts dissipate a fraction of that. SSRs also leak a small current when "off" (enough to make some LED bulbs glow faintly) and cost more. Rule of thumb: SSR for frequent AC switching (heater control, AC motor duty with many cycles); electromechanical relay for infrequent on-off AC where the voltage drop and leakage matter.

Troubleshooting table: read the symptom

Symptom Likely cause Fix
Arduino resets when relay switches Coil inrush / EMI through shared 5 V rail; missing flyback diode Separate relay supply via JD-VCC jumper; confirm diode on module; add 470 µF bulk cap on Arduino rail
Relay chatters (rapid clicking) Supply voltage sagging under coil current; weak adapter Power relay coils from a dedicated 5 V / 1 A+ supply, not USB
MOSFET gets hot at modest current Gate driven at 3.3 V but Rds(on) specified at 10 V (wrong part); or no heatsink where math says needed Use logic-level MOSFET (IRLZ44N); do the I²R calculation with hot Rds(on)
Load flickers at MCU power-up Floating gate before pin initialises 10 kΩ gate-to-source pulldown (Circuit 2)
MOSFET dead, shorted drain-source Back-EMF from inductive load; or gate overvoltage spike Flyback Schottky across load; 12–15 V Zener gate-to-source for protection
LED bulb glows faintly with SSR "off" SSR off-state leakage current Normal for SSRs — use electromechanical relay if it matters
Contacts welded after weeks on a motor Inrush + arcing, no snubber, rating used at 100% Derate to ~40–50% for inductive loads; RC snubber across contacts; upsize relay
PWM dimmer flickers visibly PWM frequency too low (default ~490 Hz on some Arduino pins) Move to 1 kHz or higher (up to ~20 kHz to stay above hearing); MOSFET handles any of these

Selection checklist

  • AC or DC load? AC → relay or SSR. DC → MOSFET (or relay if slow on-off and isolation wanted).
  • PWM or speed control needed? → MOSFET, no contest.
  • Load current measured or from the nameplate — with inrush estimated (motors 5–8×, cold filaments ~10×).
  • Relay: derated to ≤50% of resistive rating for inductive loads; snubber planned for AC inductive.
  • MOSFET: Rds(on) specified at your logic voltage (5 V or 3.3 V); I²R heat computed with the hot value; heatsink if the math says so.
  • Inductive load → flyback diode (DC) or snubber (AC) fitted before first power-up, not after the first failure.
  • Mains anywhere in the build → relay module with optocoupler, separate coil supply, fused, in an enclosure. No exposed 230 V on a breadboard, ever.
  • Gate pulldown (MOSFET) / base resistor (transistor driver) present so the power-up state is defined.

Putting it together

For the overwhelmingly common student build — an Arduino or ESP32 switching a mix of AC appliances and DC actuators — the standard architecture is: relay modules for the 230 V AC side, logic-level N-channel MOSFETs for the DC side, an optocoupler wherever the two sides must not share ground, and a flyback diode on every coil. Size each switch with two minutes of datasheet math (contact derating or I²R), and the switching stage stops being the part of the project that fails the night before the demo. If the rest of the build needs a systematic once-over, the project testing and debugging guide covers the full pre-submission checklist, and the water level monitoring project shows relay-driven pump control in a complete system.

More project guides

More in Electronics / E&TC