ESPBoards Learn – Early Access!
Back to Blog
Complete guide to ESP32 relay modules. Compare 1-channel, 4-channel, and solid state relays. Learn safe wiring for AC loads, common mistakes, and which relay to buy.

ESP32 Relay Guide - Choosing the Right Module for Home Automation

Complete guide to ESP32 relay modules. Compare 1-channel, 4-channel, and solid state relays. Learn safe wiring for AC loads, common mistakes, and which relay to buy.

Reviews & Comparisons

TL;DR - Quick Picks

Single device: 1-Channel Relay
Multiple devices: 4-Channel Module
Heaters/motors: Solid State Relay
No wiring: Shelly / Sonoff

Why You Need a Relay #

ESP32 GPIO pins output 3.3V at a maximum of around 12mA. That's enough to blink an LED, not enough to switch a lamp, fan, or anything connected to mains power.

A relay bridges the gap. Your ESP32 sends a small signal to the relay, and the relay switches a much larger load - up to 10A, 20A, or more depending on the relay.

ESP32 GPIO

3.3V, ~12mA max. Can control LEDs, transistors, relay coils (with driver).

Relay Output

Switches 120V/240V AC or high-current DC. 10A typical, some rated 30A+.

Safety First #

AC Voltage Warning

Mains voltage (120V/240V) can kill. If you're not comfortable working with AC wiring, use pre-built solutions like Shelly or Sonoff. Seriously - no project is worth it.

  • Always disconnect power before wiring
  • Use proper enclosures rated for mains voltage
  • Check local electrical codes
  • When in doubt, hire an electrician

Relay Types Compared #

Type How It Works Best For Downsides
Mechanical Relay Electromagnet moves physical contacts General switching, most projects Clicks, wears out (100K cycles), slower
Solid State Relay (SSR) Semiconductor switching, no moving parts Heaters, motors, frequent switching Costs more, needs heatsink at high loads
Optocoupler Module Relay + optical isolation on one board ESP32 projects (isolation included) Most modules are this type already

Quick Decision Guide #

Controlling This? Get This Why
Single lamp or fan 1-channel relay Simple, cheap
LED strip (12V/24V DC) MOSFET module No relay needed, PWM dimming
Multiple outlets 4-channel relay One board, less wiring
Heater or motor SSR (25A+) Handles inductive loads, no arcing
Whole room / many devices 8-channel board Centralized control
Don't want to wire AC Shelly or Sonoff Pre-built, safe, works with ESP

Relay Module Options #

1-Channel Relay Module #

MOST COMMON 10A @ 250VAC $2-4

The simplest option. One relay, one device. Most modules include an optocoupler for isolation, so the relay coil doesn't share ground with your ESP32.

✓ Pros

  • Cheap. Under $3 shipped.
  • Simple wiring. VCC, GND, IN - done.
  • Optocoupler included. Most modules have isolation.

✗ Cons

  • 5V trigger common. Some won't trigger reliably at 3.3V.
  • Audible click. Mechanical = noise.
  • One device only. Need more? Buy more modules.

3.3V vs 5V Trigger

Many relay modules expect 5V trigger signal. ESP32 outputs 3.3V. Look for modules specifically marked "3.3V compatible" or use a level shifter. Some modules work anyway - but test before installing.

1-Channel 5V Relay Module (Optocoupler)

Standard single relay module with optocoupler isolation. Works with most ESP32 projects. Check trigger voltage compatibility.

Where to Buy:

Prices may vary. Click to check current pricing:

4-Channel Relay Module #

BEST VALUE 4x 10A @ 250VAC $5-8

Four relays on one board. Control lights, fans, pumps - whatever you need. The go-to for home automation projects.

Pro tip: These modules often have a jumper to separate relay VCC from signal VCC. Use separate 5V supply for the relay coils if your ESP32's regulator can't handle the current draw.

4-Channel 5V Relay Module

Four relays with optocoupler isolation. Ideal for controlling multiple devices from one ESP32. Popular choice for home automation.

Where to Buy:

Prices may vary. Click to check current pricing:

8-Channel Relay Module #

8x 10A @ 250VAC $10-15

For serious automation. Eight relays, one board. Watch your power supply - all coils on draws significant current.

8-Channel 5V Relay Module

Eight relays for large automation projects. Definitely use separate power supply for the relay coils.

Where to Buy:

Prices may vary. Click to check current pricing:

Solid State Relay (SSR) #

BEST FOR HEATERS 25A-40A typical $8-15

No moving parts. Semiconductor does the switching. Silent, fast, no contact wear.

✓ Pros

  • Silent operation. No clicking.
  • No contact wear. Millions of cycles.
  • Fast switching. Good for PWM-style control.
  • Handles inductive loads. Motors, solenoids.

✗ Cons

  • Needs heatsink. At high currents, gets hot.
  • Voltage drop. ~1.5V across SSR = heat.
  • More expensive. $8-15 vs $2-3 for mechanical.
  • Small leakage current. May not fully "off" LEDs.

When to use SSR: Heaters, heating elements, motors, any load that switches frequently, or anywhere you need silent operation.

Fotek SSR-25DA Solid State Relay

25A SSR, 3-32V DC input, 24-380V AC output. Popular choice for heater control. Use with heatsink at higher loads.

Where to Buy:

Prices may vary. Click to check current pricing:

SSR-40DA 40A Solid State Relay

Higher current SSR for demanding loads. Definitely needs heatsink. Good for 3D printer heated beds, large heaters.

Where to Buy:

Prices may vary. Click to check current pricing:

Pre-Built Smart Relays #

Don't want to wire mains voltage? These devices have relays built-in, proper enclosures, and certifications. Flash with Tasmota or ESPHome for ESP32-style control.

Shelly 1 #

RECOMMENDED 16A $15-20

Tiny WiFi relay that fits behind a light switch. Has an ESP chip inside. Works standalone or flash with Tasmota/ESPHome.

Shelly 1 WiFi Relay

Compact WiFi relay, fits behind switches. 16A rating. Can be flashed with open-source firmware. My top pick for safe, simple smart switches.

Where to Buy:

Prices may vary. Click to check current pricing:

Sonoff Basic #

BUDGET PICK 10A $8-12

Inline smart switch. Plug it between your device and the outlet. Easy to flash with Tasmota.

Sonoff Basic R3 WiFi Smart Switch

Budget-friendly inline relay. 10A. Easy to flash with Tasmota or ESPHome. Good for lamps, fans, simple loads.

Where to Buy:

Prices may vary. Click to check current pricing:

Shelly 2.5 #

Two relays in one device. Control two lights, or use for roller shutters/blinds (up/down).

Shelly 2.5 Dual WiFi Relay

Two 10A relays in one compact unit. Perfect for two-gang switches or motorized blinds. Power monitoring included.

Where to Buy:

Prices may vary. Click to check current pricing:

Wiring Basics #

Understanding relay wiring is simpler than it looks. There are two completely separate circuits:

Control Side (Safe)
3.3V / 5V DC
Load Side (Danger)
120V / 240V AC

ESP32
5V (or VIN)
GND
GPIO 5

Relay Module (Input)
VCC
GND
IN

Relay Module (Output)
COM
← Live in
NO
→ To load
NC not used

Your Load
Lamp, fan, heater...

Understanding COM, NO, NC
COM = Common. Your power source connects here.
NO = Normally Open. Connects to COM when relay is ON.
NC = Normally Closed. Connected until relay turns ON.

Most projects use COM + NO: power flows to your device only when the ESP32 activates the relay.

Active-Low vs Active-High

Many relay modules are "active-low" – the relay turns ON when you write LOW to the pin. This seems backwards, but it's how most modules work. Just test yours.

Quick Reference #

Connection From To
Power ESP32 5V (or VIN) Relay VCC
Ground ESP32 GND Relay GND
Signal ESP32 GPIO 5 Relay IN
AC Live Wall outlet Relay COM
To Load Relay NO Your device

Basic Code Example #

#define RELAY_PIN 5

void setup() {
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, HIGH); // Start with relay OFF (active-low module)
}

void loop() {
digitalWrite(RELAY_PIN, LOW); // Relay ON
delay(5000);
digitalWrite(RELAY_PIN, HIGH); // Relay OFF
delay(5000);
}

For web control, timers, or Home Assistant integration, check out ESPHome - it handles all of that with simple YAML config.

Common Mistakes #

Using 5V relay module with 3.3V ESP32 without checking. Some work, some don't trigger reliably. Test first or buy 3.3V-compatible modules.

Powering relay coils from ESP32's 3.3V regulator. The regulator can't supply enough current. Use VIN (5V USB) or separate supply for relay VCC.

No flyback diode. When a relay coil switches off, it creates a voltage spike. Most modules have this built-in, but bare relays need one.

Undersizing the relay for the load. A "10A" relay shouldn't run at 10A continuously. Derate by 50% for reliability. Use 20A relay for 10A load.

Forgetting about inrush current. Motors and some lights draw 5-10x more current at startup. A lamp that draws 1A steady might draw 10A for a split second.

Mixing low-voltage and mains wiring. Keep them separate. Use proper enclosures. Don't run 3.3V signal wires next to 240V mains.

Relay Module Comparison #

Type Channels Current Trigger Price Best For
Mechanical 1 10A 5V (some 3.3V) $2-4 Single device
Mechanical 4 4x 10A 5V $5-8 Multiple devices
Mechanical 8 8x 10A 5V $10-15 Full automation
SSR 1 25-40A 3-32V DC $8-15 Heaters, motors
Shelly 1 1 16A WiFi $15-20 Safe, no wiring
Sonoff Basic 1 10A WiFi $8-12 Budget smart switch