ESP32 S3 UNO - 2-Channel Relay Module

This ESP32 S3 Uno 2-channel relay module tutorial shows you how to switch two high-voltage loads from one ESP32 S3 Uno form board. You will see the two-channel relay pinout, a safe wiring and power setup, and a short Arduino IDE sketch. When you are done, both relays click on and off under the control of your code.

In this tutorial, you will:

  1. Learn the pinout of a two-channel relay module
  2. Wire the relay module to the board with a safe power setup
  3. Write Arduino code that turns two relays on and off with digitalWrite()
  4. Check the relay states in the Serial Monitor
ESP32 S3 Uno 2-channel relay module

Imagine you want to control two loads at once, such as a pump and a fan, or two actuators. Two single relay modules would work. A 2-channel relay module is the neater choice, though. It needs fewer wires, takes less space and costs less. The code stays the same as for two single relays, so you lose nothing.

Hardware Preparation

1×ESP32 S3 Uno-form 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×2-channel Relay Module
1×Optionally, 5V Power Adapter
1×Jumper Wires
1×Recommended: Screw Terminal Block Shield for ESP32 S3 Uno
1×Recommended: Sensors/Servo Expansion Shield for ESP32 S3 Uno
1×Recommended: Breadboard Shield for ESP32 S3 Uno
1×Recommended: Enclosure for ESP32 S3 Uno
1×Recommended: Power Splitter for ESP32 S3 Uno
1×Recommended: Prototyping Base Plate & Breadboard Kit for ESP32 S3 Uno

Or you can buy the following kits:

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 2-Channel Relay Module

Knowing each pin of the module saves you from wiring mistakes. The pins fall into three groups: power, signal and output. The sections below walk through each group.

Pinout

2-channel Relay Module Pinout

Power pins

The DC+ pin takes 5V from a power supply. The DC- pin goes to the GND of that supply, and it must also connect to a GND pin of the ESP32 S3 Uno so both sides share the same ground.

Signal pins

The IN1 pin receives the control signal for relay 1 from the ESP32 S3 Uno. The IN2 pin does the same job for relay 2.

Output pins

Every relay has three output pins: NCx (normally closed), NOx (normally open) and COMx (common). Your first high-voltage device goes on NC1, NO1 and COM1, which relay 1 switches. Your second device goes on NC2, NO2 and COM2, which relay 2 switches.

Trigger jumpers

You will also find 2 jumpers on the board. Each one sets its relay to a low-level trigger or a high-level trigger. Because each relay has its own jumper, the two relays can use different trigger modes.

If relays are new to you, read the ESP32 S3 Uno - Relay tutorial first. It covers how to connect a relay to a high-voltage device, what normally closed and normally open mean, what low-level trigger and high-level trigger mean, and how the ESP32 S3 Uno controls a relay.

ESP32 S3 Uno Pinout

The image below shows the pinout diagram of the ESP32 S3 Uno form board. Use it to find the D2 and D3 headers and their GPIO numbers when you wire the relay module.

ESP32 S3 Uno pinout diagram

Wiring Diagram

Careful wiring keeps your project safe and stable. The two signal wires are easy: IN1 goes to D2 (GPIO18) and IN2 goes to D3 (GPIO17). For a quick test, the module takes its power from the 5V pin of the board.

Relay Module Pin ESP32 S3 Uno Pin
DC+ 5V
DC- GND
IN1 D2 (GPIO18)
IN2 D3 (GPIO17)
The wiring diagram between ESP32 S3 Uno 2-channel relay module

This image is created using Fritzing. Click to enlarge image

※ NOTE THAT:

Most 2-channel relay modules have 5V coils, so DC+ needs 5V. The IN1 and IN2 pins only receive the 3.3V signal from the ESP32 S3 Uno, and most modules with an optocoupler or transistor input switch fine with it. Never send a 5V signal back into an ESP32 S3 Uno pin, because the ESP32 S3 Uno pins are NOT 5V tolerant.

When the board's 5V pin also feeds other parts, the relay module may not get enough current. Two relay coils switching together can pull the voltage down. In that case, power the module from its own 5V adapter, and join its GND to the GND of the ESP32 S3 Uno.

※ NOTE THAT:

When both loads use the same voltage, a single high-voltage power adapter can supply them both. When they need different voltages, give each load its own high-voltage power adapter.

How To Program For 2-Channel Relay Module

Two relays need very little code. You use two functions, and you call each one once for every relay.

  1. Make each relay pin a digital output with the pinMode() function:
pinMode(PIN_RELAY_1, OUTPUT); pinMode(PIN_RELAY_2, OUTPUT);
  1. Switch each relay with the digitalWrite() function. On the ESP32 S3 Uno, HIGH means 3.3V:
digitalWrite(PIN_RELAY_1, HIGH); digitalWrite(PIN_RELAY_2, HIGH);

ESP32 S3 Uno Code

This sketch switches both relays on, waits 2 seconds, switches them off, and waits another 2 seconds, forever. PIN_RELAY_1 is GPIO18 (D2) and PIN_RELAY_2 is GPIO17 (D3). After every change, it prints a line to the Serial Monitor so you can follow what happens.

/* * This ESP32 S3 Uno code was developed by newbiely.com * * This ESP32 S3 Uno code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3-uno/esp32-s3-uno-2-channel-relay-module */ #define PIN_RELAY_1 18 // The ESP32 S3 Uno pin (D2 = GPIO18) connected to the IN1 pin of relay module #define PIN_RELAY_2 17 // The ESP32 S3 Uno pin (D3 = GPIO17) connected to the IN2 pin of relay module // The setup function runs once on reset or power-up void setup() { Serial.begin(9600); // initialize digital pin as an output. pinMode(PIN_RELAY_1, OUTPUT); pinMode(PIN_RELAY_2, OUTPUT); } // The loop function repeats indefinitely void loop() { Serial.println("Turned on both relays"); digitalWrite(PIN_RELAY_1, HIGH); digitalWrite(PIN_RELAY_2, HIGH); delay(2000); Serial.println("Turned off both relays"); digitalWrite(PIN_RELAY_1, LOW); digitalWrite(PIN_RELAY_2, LOW); delay(2000); }

Detailed Instructions

  1. New to the ESP32 S3 Uno? Follow ESP32 S3 Uno - Getting Started first.
  2. Wire it up as shown in the diagram.
  3. Connect the board to your computer with a USB Type-C cable.
  4. Open Arduino IDE, choose the ESP32S3 Dev Module board and the correct COM port.
  5. Copy the code above and paste it into the Arduino IDE.
  6. Upload the code by clicking the Upload button.
  7. Listen for both relays to click every 2 seconds.
  8. Open the Serial Monitor, set it to 9600 baud, and check the 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
Turned on both relays Turned off both relays Turned on both relays Turned off both relays Turned on both relays Turned off both relays Turned on both relays Turned off both relays
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2
  1. Tip: Test the relays without any high-voltage load first. Once the clicks and messages look right, switch off all power, and only then connect your loads.

Video Tutorial

Watch the video below to see this ESP32 S3 Uno project step by step.

Function References

Application Examples

With two relays working, you are one step away from a real project. You can switch the two loads by a sensor, by a button or by time.

Plant watering system

Add a soil moisture sensor. Let the ESP32 S3 Uno run a pump on relay 1 when the soil is dry, and turn on a grow light with relay 2 at night.

Fan and heater controller

Read a DHT22 temperature sensor. Switch a fan with one relay when it is hot, and a heater with the other relay when it is cold.

Two-gang switch

Add two push buttons, one for each relay. The ESP32 S3 Uno reads each button and toggles its own relay, like a two-gang light switch.

Phone control

The ESP32 S3 Uno has built-in WiFi. Run a small web server on it and switch each relay from a web page on your phone.

Simple timer

Use millis() to run relay 1 for 10 minutes every hour, and relay 2 on a different schedule.

FAQ

Can the ESP32 S3 Uno control each relay on its own?

Yes. Each relay has its own pin, so you can call digitalWrite() on PIN_RELAY_1 and PIN_RELAY_2 at different times. For example, relay 1 can be on while relay 2 stays off.

Can a 3.3V ESP32 S3 Uno pin drive a 5V 2-channel relay module?

In most cases, yes. Power DC+ from 5V and connect IN1 and IN2 to D2 (GPIO18) and D3 (GPIO17). A 3.3V HIGH is enough for most modules with an optocoupler or transistor input. If the relay LED lights but the relay does not click, use a 3V relay module.

Why does my relay turn ON when the code says LOW?

Your module is set to low-level trigger. In that mode, LOW turns the relay on and HIGH turns it off. Move the trigger jumper to the high-level position, or swap HIGH and LOW in your code.

Why does the code use 18 and 17 instead of 2 and 3 like on the UNO R4?

On the ESP32 S3 Uno, the header label and the GPIO number are different. D2 is GPIO18 and D3 is GPIO17, and the code must use the GPIO number. If you write 2 or 3, the code drives the wrong pins and the relays stay silent.

What if my project needs more relays than the Uno headers give?

The ESP32 S3 Uno has two extra rows of holes with more GPIOs. GPIO15 and GPIO16 are I/O, PWM and analog. GPIO45 and GPIO35 to GPIO42 are I/O and PWM. GPIO47 and GPIO48 are output only, with PWM. Solder pin headers to use them and write the GPIO number in code. For extra relays, GPIO35 to GPIO42 are a good choice. Watch out for two things. First, GPIO47 and GPIO48 may run at 1.8V instead of 3.3V on some modules (especially ones with "V" in the name, like R8V or R16V), so 3.3V devices can be damaged or act strangely. Second, GPIO0, GPIO3 (D6), GPIO45 and GPIO46 (D9) are boot strapping pins, and a wrong connection can stop the board from booting or uploading code. Use the other extra pins first.

Do I need a separate power supply for the relay module?

It is the safer choice. Two relay coils together draw more current than a small project should take from the board's 5V pin. A separate 5V supply stops the ESP32 S3 Uno from resetting when the relays switch.

Troubleshooting

Problem Possible Cause Solution
No COM port shows up in the Arduino IDE USB driver is missing, the cable is charge-only, or the board is not in upload mode Install the CP210x or CH340 driver, try a USB Type-C data cable, or hold BOOT while pressing RESET
Relays do not click at all DC+ and DC- are not powered or the GND is not shared Check the 5V supply to the module and connect DC- to a GND pin of the ESP32 S3 Uno
Relay LED lights but the relay does not click The 3.3V signal is too weak for this module Use a 3V relay module or one with a transistor or optocoupler input
Relays stay silent after upload The code uses header numbers instead of GPIO numbers Use 18 for D2 and 17 for D3
Relay works in the opposite way The trigger jumper is set to low-level trigger Move the jumper to high-level trigger or swap HIGH and LOW in the code
Only one relay switches The IN wire for the other relay is loose or on the wrong pin Make sure IN1 goes to D2 (GPIO18) and IN2 goes to D3 (GPIO17)
The board resets when the relays switch The relay coils draw too much current from the board Power the relay module from a separate 5V supply
The relay clicks but the load does not turn on The load is wired to NC instead of NO or COM is not connected Wire the load through COM and NO and check the load power supply
Serial Monitor shows nothing or strange text Wrong baud rate or wrong COM port Set the baud rate to 9600 and choose the COM port of the ESP32 S3 Uno

※ 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!