ESP32 S3 - 4-Channel Relay Module

Learn how to control multiple high-voltage devices using an ESP32 S3 and a 4-channel relay module. This beginner-friendly tutorial walks you through wiring, programming, and safely operating four independent relay channels to control pumps, fans, lights, and other appliances.

What you'll build:

  1. A working circuit connecting an ESP32 S3 to a 4-channel relay module
  2. A program that turns all four relays ON and OFF in sequence
  3. Serial Monitor output confirming each relay state change
  4. A foundation for home automation and IoT control projects

https://newbiely.com/images/cover/esp32-s3-4-channel-relay-module.jpg

Hardware Preparation

1×ESP32 S3 WROOM N16R8
1×Alternatively, ESP32 S3 SuperMini Dev Module
1×Alternatively, ESP32 S3 Uno-form Board
1×Alternatively, ESP32 S3 Camera Board
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×4-Channel Relay Module
1×Breadboard
1×Jumper Wires
1×Optionally, 5V Power Adapter for ESP32 S3
1×Recommended: Screw Terminal Expansion Board for ESP32 S3
1×Recommended: Breakout Expansion Board for ESP32 S3
1×Recommended: Power Splitter for ESP32 S3

Or you can buy the following kits:

1×DIYables ESP32 S3 Starter Kit (ESP32 S3 included)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of 4-Channel Relay Module

A 4-channel relay module is a control board that contains four independent relays, each capable of switching high-voltage devices such as lights, pumps, and fans under microcontroller command. The module includes onboard optocoupler isolation that protects the ESP32 S3 from high-voltage spikes, and LED indicators that show the state of each relay at a glance.

Key Specifications

  • Controls up to four separate high-voltage devices (AC or DC)
  • Each relay handles loads up to 10A at 250VAC or 30VDC (typical)
  • Operates with 5V logic signals from microcontrollers
  • Onboard LED indicators show relay status
  • Optocoupler isolation protects your ESP32 S3
  • Configurable trigger modes (high/low) via onboard jumpers
  • Cost-effective solution for multi-device control in home automation and IoT projects

The 4-Channel Relay Module Pinout

The diagram below identifies every connection point on the 4-channel relay module.

4-Channel Relay Module pinout

Power Pins:

  1. DC+: Connect to 5V power supply (external adapter recommended)
  2. DC-: Connect to GND of power supply and ESP32 S3 GND

Signal Pins (Control):

  1. IN1: Control signal from ESP32 S3 for relay 1
  2. IN2: Control signal from ESP32 S3 for relay 2
  3. IN3: Control signal from ESP32 S3 for relay 3
  4. IN4: Control signal from ESP32 S3 for relay 4

Output Pins (High-Voltage Connections):

  1. NC1, NO1, COM1: Relay 1 output (Normally Closed, Normally Open, Common)
  2. NC2, NO2, COM2: Relay 2 output (Normally Closed, Normally Open, Common)
  3. NC3, NO3, COM3: Relay 3 output (Normally Closed, Normally Open, Common)
  4. NC4, NO4, COM4: Relay 4 output (Normally Closed, Normally Open, Common)

To learn about connecting a relay to high-voltage devices and understanding the distinctions between normally closed and normally open, check out the ESP32 S3 - Relay tutorial.

Additionally, the tutorial covers the 4 jumpers available on the relay module, which enable you to individually select between low trigger and high trigger settings for each relay.

Wiring Diagram

Connect your ESP32 S3 to the 4-channel relay module using the wiring guide below, keeping all high-voltage connections away from the low-voltage control side. Always verify every connection before applying power to avoid damaging your components.

Safety Notes

Never power the 4-channel relay module directly from the ESP32 S3 5V pin — the relay module draws more current than the pin can safely supply. Use a dedicated external 5V power adapter for the relay module, a separate 5V source for the ESP32 S3, and an appropriate high-voltage supply for the controlled devices. Keep high-voltage wiring physically separated from low-voltage control wiring at all times.

Power Supply Configuration:

You'll need multiple power sources for this project:

  • 5V power adapter for the ESP32 S3 (via USB or power jack)
  • 5V power adapter for the 4-channel relay module
  • High-voltage power source (12VDC, 24VDC, 120VAC, 220VAC, etc.) for the controlled devices

Wiring Diagram (Three Power Sources):

The wiring diagram between ESP32 S3 4-channel relay module

This image is created using Fritzing. Click to enlarge image

4-Channel Relay Module ESP32 S3
DC+ External 5V Power Supply (+)
DC- External 5V Power Supply (-) AND ESP32 GND
IN1 GPIO7
IN2 GPIO6
IN3 GPIO5
IN4 GPIO4

Jumper wires are good for a quick test, but not for a final build. The ESP32 S3 fits a Screw Terminal Block for ESP32 S3, which turns every pin into a screw terminal. Each wire goes to the screw terminal of the same pin, as in the image below.

The wiring diagram between ESP32 S3 4-channel relay module Screw Terminal

This image is created using Fritzing. Click to enlarge image

A GPIO Breakout Board for ESP32 S3 works too. Besides one S, 3.3V and GND pin for each GPIO, it has extra 3.3V and 5V pins:

The wiring diagram between ESP32 S3 4-channel relay module GPIO Breakout Board

This image is created using Fritzing. Click to enlarge image

Simplified Wiring (Two Power Sources):

You can reduce the number of adapters by using one 5V power source for both the ESP32 S3 and the 4-channel relay module:

The wiring diagram between ESP32 S3 4-channel relay module  two power source

This image is created using Fritzing. Click to enlarge image

※ NOTE THAT:

If the four devices that are managed by a 4-channel relay module have the same voltage, then one high-voltage power adapter can be used for all of them. However, if the voltage is different for each device, then separate high-voltage power adapters must be used.

How To Program For 4-Channel Relay Module

Programming the ESP32 S3 to control a 4-channel relay module uses straightforward digital output commands available in the Arduino IDE. The following code configures four GPIO pins as outputs, then cycles all four relays ON and OFF in sequence while printing status messages to the Serial Monitor for easy debugging.

The code performs these tasks:

  • Configures ESP32 S3 pins as digital outputs for relay control
  • Turns all four relays ON and OFF in sequence
  • Provides serial feedback for monitoring relay states
  • Creates a 2-second delay between state changes

Set pins to output mode:

pinMode(PIN_RELAY_1, OUTPUT); pinMode(PIN_RELAY_2, OUTPUT); pinMode(PIN_RELAY_3, OUTPUT); pinMode(PIN_RELAY_4, OUTPUT);

Control relay states:

digitalWrite(PIN_RELAY_1, HIGH); digitalWrite(PIN_RELAY_2, HIGH); digitalWrite(PIN_RELAY_3, HIGH); digitalWrite(PIN_RELAY_4, HIGH);

ESP32 S3 Code

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-4-channel-relay-module */ /* * This ESP32-S3 code is created by esp32io.com * * This ESP32-S3 code is released in the public domain * * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-s3-4-channel-relay-module */ #define PIN_RELAY_1 7 // The ESP32-S3 pin GPIO7 connected to the IN1 pin of relay module #define PIN_RELAY_2 6 // The ESP32-S3 pin GPIO6 connected to the IN2 pin of relay module #define PIN_RELAY_3 5 // The ESP32-S3 pin GPIO5 connected to the IN3 pin of relay module #define PIN_RELAY_4 4 // The ESP32-S3 pin GPIO4 connected to the IN4 pin of relay module // the setup function runs once when you press reset or power the board void setup() { Serial.begin(9600); // initialize digital pin as an output. pinMode(PIN_RELAY_1, OUTPUT); pinMode(PIN_RELAY_2, OUTPUT); pinMode(PIN_RELAY_3, OUTPUT); pinMode(PIN_RELAY_4, OUTPUT); } // the loop function runs over and over again forever void loop() { Serial.println("Turn on all"); digitalWrite(PIN_RELAY_1, HIGH); digitalWrite(PIN_RELAY_2, HIGH); digitalWrite(PIN_RELAY_3, HIGH); digitalWrite(PIN_RELAY_4, HIGH); delay(1000); Serial.println("Turn off all"); digitalWrite(PIN_RELAY_1, LOW); digitalWrite(PIN_RELAY_2, LOW); digitalWrite(PIN_RELAY_3, LOW); digitalWrite(PIN_RELAY_4, LOW); delay(1000); }

Detailed Instructions

  1. New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
  2. Wire the Components: Connect the ESP32 S3 and 4-channel relay module according to the wiring diagram above.
  3. Connect ESP32 S3: Plug the ESP32 S3 into your computer using a USB Type-C cable.
  4. Open Arduino IDE: Launch the Arduino IDE software on your computer.
  5. Select Board and Port: Choose ESP32 S3 as the board and select the correct COM port.
  6. Copy the Code: Copy the provided code and paste it into Arduino IDE.
  7. Upload the Code: Click the Upload button to transfer the code to your ESP32 S3.
  8. Listen for Clicks: You should hear the relays clicking as they switch ON and OFF.
  9. Check Serial Monitor: Open the Serial Monitor (baud rate 115200) to view the relay status messages.
  10. Pro Tip: Label each relay channel and its connected device to avoid confusion as your project grows in complexity.

Serial Monitor Output

∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
[2026-01-15 09:00:00] Turn on all [2026-01-15 09:00:02] Turn off all [2026-01-15 09:00:04] Turn on all [2026-01-15 09:00:06] Turn off all [2026-01-15 09:00:08] Turn on all [2026-01-15 09:00:10] Turn off all [2026-01-15 09:00:12] Turn on all [2026-01-15 09:00:14] Turn off all
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

Applications and Project Ideas

The ESP32 S3 paired with a 4-channel relay module opens the door to a wide range of automation and IoT projects where multiple high-voltage devices need independent control.

  1. Home Automation System: Control lights, fans, heaters, and appliances remotely via Wi-Fi.
  2. Greenhouse Controller: Automate irrigation pumps, grow lights, ventilation fans, and heating systems on a schedule.
  3. Aquarium Manager: Control filter pumps, air pumps, lights, and heaters with programmable timers.
  4. Smart Garage: Operate a door opener, lighting, ventilation fan, and security system from one board.
  5. Tutorial Automation: Control power tools, dust collection, lighting, and equipment with a single controller.
  6. Energy Management: Schedule high-power devices to run during off-peak hours to reduce electricity costs.

Video Tutorial

Watch the step-by-step video walkthrough for this ESP32 S3 project below.

Challenge Yourself

Now that you have four relay channels under ESP32 S3 control, push your skills further with these practical challenges that range from simple timing tweaks to full smart-home integration.

  1. Beginner: Modify the code to control each relay independently with different timing patterns.
  2. Beginner: Add button inputs to manually toggle each relay channel on demand.
  3. Intermediate: Create a web interface to control all four relays from your smartphone browser.
  4. Intermediate: Implement scheduled automation that turns relays ON and OFF at specific times of day.
  5. Advanced: Build a voice-controlled system using MQTT and Alexa or Google Home integration.
  6. Advanced: Add current sensors to each relay output to monitor the power consumption of every controlled device.

Function References

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!