Arduino Nano - 4-Channel Relay Module | Arduino Nano Tutorial (2024)

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:

  • Its wiring is simpler.

  • It takes up less space.

  • It is more cost-effective.

  • The programming remains the same.

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 kits:

1×DIYables Sensor Kit (30 sensors/displays)
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. We appreciate your support.

Overview of 4-Channel Relay Module

The 4-Channel Relay Module Pinout

Arduino Nano - 4-Channel Relay Module | Arduino Nano Tutorial (1)

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:

Arduino Nano - 4-Channel Relay Module | Arduino Nano Tutorial (2)

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.

Arduino Nano - 4-Channel Relay Module | Arduino Nano Tutorial (3)

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-upvoid 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 indefinitelyvoid 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 allTurn off allTurn on allTurn off allTurn on allTurn off allTurn on allTurn off all

AutoscrollShow timestamp

Clear output

9600 baud

Newline

Video Tutorial

Learn More

  • Arduino Nano - Relay

  • Arduino Nano - 2-Channel Relay Module

  • Arduino Nano - Fan

  • Arduino Nano - Heating Element

  • Arduino Nano - Button - Relay

  • Arduino Nano - Potentiometer Relay

  • Arduino Nano - Light Sensor Relay

  • Arduino Nano - Ultrasonic Sensor - Relay

  • Arduino Nano - Motion Sensor - Relay

  • Arduino Nano - Keypad - Relay

  • Arduino Nano - Cooling System using DHT Sensor

  • Arduino Nano - Cooling System using DS18B20 Temperature Sensor

  • Arduino Nano - Heating System

  • Arduino Nano - Touch Sensor - Relay

  • Arduino Nano - Door Sensor - Relay

  • Arduino Nano - RFID - Relay

  • Arduino Nano - Pump

  • Arduino Nano - Button - Pump

  • Arduino Nano - Rain Sensor

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

PREVIOUS

NEXT

DISCLOSURE

newbiely.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com, Amazon.it, Amazon.fr, Amazon.co.uk, Amazon.ca, Amazon.de, Amazon.es, Amazon.nl, Amazon.pl and Amazon.se

Copyright © 2024 newbiely.com. All rights reserved.
Terms and Conditions | Privacy Policy

Email: newbiely.com@gmail.com

Arduino Nano - 4-Channel Relay Module | Arduino Nano Tutorial (2024)
Top Articles
Latest Posts
Article information

Author: Roderick King

Last Updated:

Views: 5981

Rating: 4 / 5 (51 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Roderick King

Birthday: 1997-10-09

Address: 3782 Madge Knoll, East Dudley, MA 63913

Phone: +2521695290067

Job: Customer Sales Coordinator

Hobby: Gunsmithing, Embroidery, Parkour, Kitesurfing, Rock climbing, Sand art, Beekeeping

Introduction: My name is Roderick King, I am a cute, splendid, excited, perfect, gentle, funny, vivacious person who loves writing and wants to share my knowledge and understanding with you.