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

Ads by ArduinoGetStarted.com

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

When we want to control 4 high-voltage devices such as pumps, fans, actuators... We can use multiple relay modules. However, there is a simpler way is to use a 4-channel relay module. A 4-channel relay module is a combination of 4 relays on a single board.

A 4-channel relay module vs 4 x 1-channel relay modules:

  • A 4-channel relay module has simpler wiring.

  • A 4-channel relay module uses less space.

  • A 4-channel relay module is cheaper.

  • The programming is the same.

Hardware Required

1×Arduino UNO or Genuino UNO
1×USB 2.0 cable type A/B
1×4-channel Relay Module
1×Jumper Wires
1×(Optional) 9V Power Adapter for Arduino
1×(Recommended) Screw Terminal Block Shield for Arduino Uno
1×(Optional) Transparent Acrylic Enclosure For Arduino Uno

Or you can buy the following sensor kit:

1×DIYables Sensor Kit 30 types, 69 units

Please note: These are Amazon affiliate links. If you buy the components through these links, We will get a commission at no extra cost to you. We appreciate it.

About 4-Channel Relay Module

Pinout

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

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

  • Signal pins:

    • IN1: this pin receives the control signal from Arduino to control relay 1 on the module

    • IN2: this pin receives the control signal from Arduino to control relay 2 on the module

    • IN3: this pin receives the control signal from Arduino to control relay 3 on the module

    • IN4: this pin receives the control signal from Arduino 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 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

    • NC3, NO3, COM3: These pins connect to a high-voltage device that is controlled by relay 3

    • NC4, NO4, COM4: These pins connect to a high-voltage device that is controlled by relay 4

    For detail of how to connect relay to high-voltage, what are differences between normally closed and normally open, see Arduino - Relay tutorial

    It also has 4 jumpers to select between the low trigger and the high trigger for each relay individually.

Wiring Diagram

4-channel relay module consumes considerable power. Therefore, we should NOT power the module directly from the 5V pin of Arduino. We need to use external 5V power for the module instead.

So, we need to use three power sources:

  • A 5V power adapter for Arduino

  • A 5V power adapter for the 4-channel relay module

  • A higher-voltage power adapter (12VDC, 24VDC, 48VDC, 220AC...) for things that are controlled by the 4-channel relay module

  • Wiring diagram with three power sources. Power supply for Arduino (not included in the image) can be via either USB cable or power jack.

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

This image is created using Fritzing. Click to enlarge image

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

This image is created using Fritzing. Click to enlarge image

※ NOTE THAT:

If 4 devices that are controlled by a 4-channel relay module use the same voltage, we can use a single high-voltage power adapter for all. However, if they use different voltages, we can use different high-voltage power adapters independently.

How To Program For 4-Channel Relay Module

  • Initializes the Arduino pin to the digital output mode by using pinMode() function.

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

  • Control the relay's state by using digitalWrite() function.

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

Arduino Code

/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-4-channel-relay-module */#define PIN_RELAY_1 2 // the Arduino pin, which connects to the IN1 pin of relay module#define PIN_RELAY_2 3 // the Arduino pin, which connects to the IN2 pin of relay module#define PIN_RELAY_3 4 // the Arduino pin, which connects to the IN3 pin of relay module#define PIN_RELAY_4 5 // the Arduino pin, which connects to the IN4 pin of relay module// the setup function runs once when you press reset or power the boardvoid 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 forevervoid 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);}

Quick Steps

  • Copy the above code and open with Arduino IDE

  • Click Upload button on Arduino IDE to upload code to Arduino

  • Listen the click sound on relays.

  • See the result on Serial Monitor.

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

We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.

Function References

The Best Arduino Starter Kit

  • See the best Arduino kit for beginner

See Also

  • Arduino - Relay

  • Arduino - Relay Shield

  • Arduino - 2-Channel Relay Module

  • Arduino - Controls Fan

  • Arduino - Controls Heating Element

  • Arduino - Button - Relay

  • Arduino - Button Toggle Relay

  • Arduino - Potentiometer Triggers Relay

  • Arduino - Light Sensor Triggers Relay

  • Arduino - Ultrasonic Sensor - Relay

  • Arduino - Motion Sensor - Relay

  • Arduino - Keypad - Relay

  • Arduino - Temperature Sensor - Relay

  • Arduino - Control Temperature

  • Arduino - Cooling System using DHT Sensor

  • Arduino - Cooling System using DS18B20 Temperature Sensor

  • Arduino - Heating System

  • Arduino - DHT11 - Relay

  • Arduino - DHT22 - Relay

  • Arduino - Touch Sensor - Relay

  • Arduino - Touch Sensor Toggle Relay

  • Arduino - Door Sensor - Relay

  • Arduino - Door Sensor Toggle Relay

  • Arduino - RFID/NFC - Relay

  • Arduino - Controls Pump

  • Arduino - Button - Pump

  • Arduino - Rain Sensor - Relay

  • Arduino - Sound Sensor - Relay

  • Arduino - Gas Sensor - Relay

  • Arduino Uno R4 WiFi controls Relay via Web

※ OUR MESSAGES

  • We are AVAILABLE for HIRE. See how to hire us to build your project

  • If this tutorial is useful for you, please give us motivation to make more tutorials.

  • You can share the link of this tutorial anywhere. Howerver, please do not copy the content to share on other websites. We took a lot of time and effort to create the content of this tutorial, please respect our work!

PREVIOUS

NEXT

DISCLOSURE

ArduinoGetStarted.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 © 2018 - 2024 ArduinoGetStarted.com. All rights reserved.
Terms and Conditions | Privacy Policy

Email: ArduinoGetStarted@gmail.com

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

Author: Otha Schamberger

Last Updated:

Views: 5873

Rating: 4.4 / 5 (75 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Otha Schamberger

Birthday: 1999-08-15

Address: Suite 490 606 Hammes Ferry, Carterhaven, IL 62290

Phone: +8557035444877

Job: Forward IT Agent

Hobby: Fishing, Flying, Jewelry making, Digital arts, Sand art, Parkour, tabletop games

Introduction: My name is Otha Schamberger, I am a vast, good, healthy, cheerful, energetic, gorgeous, magnificent person who loves writing and wants to share my knowledge and understanding with you.