Arduino Nano ESP32 - 2-Channel Relay Module
This tutorial provides step-by-step instructions on utilizing an Arduino Nano ESP32 to control a 2-channel relay module. It covers the following aspects in detail:
- Understanding the pinout configuration of a 2-channel relay module
- Establishing the connections between an Arduino Nano ESP32 and the 2-channel relay module
- Programming the Arduino Nano ESP32 to effectively control the 2-channel relay module
When we need to control two high-voltage devices like pumps, fans, or actuators, we have two options. We can either use multiple relay modules or go for a more straightforward solution. The easier way is to use a 2-channel relay module, which is a single board with two relays built-in. This makes the setup simpler and more convenient for controlling both devices.
|Arduino Nano ESP32
|USB Cable Type-C
|2-channel Relay Module
|(Optional) 5V Power Adapter for Arduino Nano ESP32
|(Recommended) Screw Terminal Adapter for Arduino Nano
Or you can buy the following sensor kit:
|DIYables Sensor Kit 30 types, 69 units
Overview of 2-Channel Relay Module
A 2-channel relay module has the following pins:
- Power pins for relay boards
- DC+: connect this pin to 5V pin of power supply
- DC-: connect this pin to the GND pin of the power supply and also to the GND pin of the Arduino Nano ESP32
- Signal pins:
- IN1: this pin receives the control signal from Arduino Nano ESP32 to control relay 1 on the module
- IN2: this pin receives the control signal from Arduino Nano ESP32 to control relay 2 on the module
- Output pins: NCx (normally closed pin), NOx (normally open pin), COMx (common pin),
- NC1, NO1, COM1: These pins connect to a high-voltage device that is controlled by relay 1
- NC2, NO2, COM2: These pins connect to a high-voltage device that is controlled by relay 2
- Connecting relays to high-voltage devices
- Explaining the concepts of normally closed and normally open
- Describing the differences between low-level trigger and high-level trigger
- Demonstrating how to effectively control relays using Arduino Nano ESP32
Moreover, the 2-channel relay module features two jumpers that grant you the flexibility to select either a low-level trigger or high-level trigger for each relay independently.
If you're keen on understanding the basics of relays, I highly recommend checking out the Arduino Nano ESP32 - Relay tutorial. This tutorial offers comprehensive insights into:
This image is created using Fritzing. Click to enlarge image
※ NOTE THAT:
If the two devices controlled by a 2-channel relay module operate at the same voltage, we can utilize a single high-voltage power adapter to supply power to both devices. However, if the devices require different voltages, we can independently use separate high-voltage power adapters for each device.
How To Program For 2-Channel Relay Module
- Initializes the Arduino Nano ESP32 pin to the digital output mode by using pinMode() function.
- Control the relay's state by using digitalWrite() function.
Arduino Nano ESP32 Code
- Copy the above code and open with Arduino IDE
- Click Upload button on Arduino IDE to upload code to Arduino Nano ESP32
- Listen the click sound on relays.
- Check out the result on the Serial Monitor.