Arduino Nano - 4-Channel Relay Module

When we need to control 4 high-voltage devices such as pumps, fans, actuators... We have the option of using multiple relay modules. Alternatively, there is a simpler solution: a 4-channel relay module. This is a single board that contains 4 relays.

A 4-channel relay module compared to 4 x 1-channel relay modules:

Hardware Preparation

1×Arduino Nano
1×USB A to Mini-B USB cable
1×4-channel Relay Module
1×Jumper Wires
1×(Optional) 9V Power Adapter for Arduino Nano
1×(Recommended) Screw Terminal Adapter for Arduino Nano

Or you can buy the following sensor kit:

1×DIYables Sensor Kit 30 types, 69 units
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. We appreciate your support.

Overview of 4-Channel Relay Module

The 4-Channel Relay Module Pinout

4-Channel Relay Module pinout

A 4-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
  • Signal pins:
    • IN1: this pin receives the control signal from Arduino Nano to control relay 1 on the module
    • IN2: this pin receives the control signal from Arduino Nano to control relay 2 on the module
    • IN3: this pin receives the control signal from Arduino Nano to control relay 3 on the module
    • IN4: this pin receives the control signal from Arduino Nano to control relay 4 on the module
  • Output pins: NCx (normally closed pin), NOx (normally open pin), COMx (common pin),
    • NC1, NO1, COM1: These pins link to a high-voltage device that is controlled by relay 1
    • NC2, NO2, COM2: These pins link to a high-voltage device that is controlled by relay 2
    • NC3, NO3, COM3: These pins link to a high-voltage device that is controlled by relay 3
    • NC4, NO4, COM4: These pins link to a high-voltage device that is controlled by relay 4

    For information on connecting a relay to high-voltage, as well as the differences between a normally closed and a normally open relay, please refer to Arduino Nano - Relay tutorial.

    It also has 4 jumpers, which can be used to choose between the low trigger and the high trigger for each relay.

Wiring Diagram

The 4-channel relay module requires a significant amount of energy, so it should NOT be powered directly from the 5V pin of the Arduino Nano. An external 5V power source must be used instead.

Therefore, we must use three power sources:

  • A 5V power adapter for the Arduino Nano
  • A 5V power adapter for the 4-channel relay module
  • A higher-voltage power adapter (12VDC, 24VDC, 48VDC, 220AC...) for items that are managed by the 4-channel relay module
  • A wiring diagram with the three power sources. The Arduino Nano can be powered either through a USB cable or a power jack, which is not shown in the image.
The wiring diagram between Arduino Nano and 4-channel relay module

This image is created using Fritzing. Click to enlarge image

  • We can lessen the amount of power adapters by utilizing a single 5V power source for both the Arduino Nano and the 4-channel relay module.
The wiring diagram between Arduino Nano and 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 operated by a 4-channel relay module have the same voltage requirement, then we can use a single high-voltage power adapter to provide power to all of them. However, if the voltage requirements of these devices differ, then we will need to use different high-voltage power adapters for each device.

How To Program For 4-Channel Relay Module

  • Sets the Arduino Nano pin to digital output mode by utilizing the pinMode() function.
pinMode(PIN_RELAY_1, OUTPUT); pinMode(PIN_RELAY_2, OUTPUT); pinMode(PIN_RELAY_3, OUTPUT); pinMode(PIN_RELAY_4, OUTPUT);
  • Manage the relay's condition by utilizing the digitalWrite() function.
digitalWrite(PIN_RELAY_1, HIGH); digitalWrite(PIN_RELAY_2, HIGH); digitalWrite(PIN_RELAY_3, HIGH); digitalWrite(PIN_RELAY_4, HIGH);

Arduino Nano Code

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-4-channel-relay-module */ #define PIN_RELAY_1 2 // The Arduino Nano pin connected to the IN1 pin of relay module #define PIN_RELAY_2 3 // The Arduino Nano pin connected to the IN2 pin of relay module #define PIN_RELAY_3 4 // The Arduino Nano pin connected to the IN3 pin of relay module #define PIN_RELAY_4 5 // The Arduino Nano pin connected to the IN4 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); pinMode(PIN_RELAY_3, OUTPUT); pinMode(PIN_RELAY_4, OUTPUT); } // The loop function repeats indefinitely 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

  • Copy the code and open it with the Arduino IDE.
  • Click the Upload button on the Arduino IDE to compile and upload the code to the Arduino Nano.
  • Listen for the click sound of the relays.
  • Check the Serial Monitor for the result.
COM6
Send
Turn on all Turn off all Turn on all Turn off all Turn on all Turn off all Turn on all Turn off all
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Video Tutorial

Function References