Arduino UNO R4 - 4-Channel Relay Module

This Arduino UNO R4 4-channel relay module guide shows you how to switch four high-voltage devices, such as pumps, fans, lamps or actuators, from one board. You get the module pinout, the wiring with a safe external power supply, and simple code for the Arduino IDE that turns all four relays on and off.

In this tutorial, you will:

Arduino UNO R4 4-channel relay module

You could use four single relay modules to control four devices. But one 4-channel relay module is often the better choice:

Overview of 4-Channel Relay Module

Before you wire anything, it helps to know what each pin is for. A 4-channel relay module has three groups of pins: power, signal and output. Once you know them, the wiring is easy.

Pinout

4-Channel Relay Module Pinout

Power pins

These pins power the relay coils on the board.

  • DC+: connect it to the 5V pin of the power supply.
  • DC-: connect it to the GND pin of the power supply. Also connect it to a GND pin of the Arduino UNO R4, so both share the same ground.

Signal pins

The Arduino UNO R4 sends its control signals to these pins.

  • IN1: controls relay 1.
  • IN2: controls relay 2.
  • IN3: controls relay 3.
  • IN4: controls relay 4.

Output pins

Each relay has three output pins: NCx (normally closed), NOx (normally open) and COMx (common). You connect your high-voltage device to them.

  • NC1, NO1, COM1: connect the device that relay 1 controls.
  • NC2, NO2, COM2: connect the device that relay 2 controls.
  • NC3, NO3, COM3: connect the device that relay 3 controls.
  • NC4, NO4, COM4: connect the device that relay 4 controls.

Trigger jumpers

The module also has 4 jumpers. With them, you choose low-level trigger or high-level trigger for each relay.

New to relays? Read the Arduino UNO R4 - Relay tutorial first. It explains how to connect a relay to a high-voltage device, and how normally closed and normally open differ.

Wiring Diagram

Four relay coils draw a lot of current. So do NOT power the module from the 5V pin of the Arduino UNO R4. Use an external 5V power supply for the module instead.

In this setup you use three power sources:

  • A 5V power adapter for the Arduino UNO R4.
  • A 5V power adapter for the 4-channel relay module.
  • A higher-voltage power adapter (12VDC, 24VDC, 48VDC, 220VAC...) for the devices that the relays switch.

The Arduino UNO R4 can get its power from the USB Type-C cable or from the power jack. This power source is not shown in the image. The table below lists the signal and power connections.

Relay Module Pin Connect To
DC+ 5V of the relay power adapter
DC- GND of the relay power adapter and GND of the Arduino UNO R4
IN1 D2 of the Arduino UNO R4
IN2 D3 of the Arduino UNO R4
IN3 D4 of the Arduino UNO R4
IN4 D5 of the Arduino UNO R4
The wiring diagram between Arduino UNO R4 4-channel relay module

This image is created using Fritzing. Click to enlarge image

See The best way to supply power to the Arduino Uno R4 and other components.

※ NOTE THAT:

If all four devices need the same voltage, one high-voltage power adapter can power all of them. If they need different voltages, use a separate high-voltage power adapter for each device.

How To Program For 4-Channel Relay Module

Controlling a relay is just like turning an LED on or off. You only need two functions. Here is how they work for four relays.

  • Set each relay pin of the Arduino UNO R4 as a digital output with the pinMode() function.
pinMode(PIN_RELAY_1, OUTPUT); pinMode(PIN_RELAY_2, OUTPUT); pinMode(PIN_RELAY_3, OUTPUT); pinMode(PIN_RELAY_4, OUTPUT);
digitalWrite(PIN_RELAY_1, HIGH); digitalWrite(PIN_RELAY_2, HIGH); digitalWrite(PIN_RELAY_3, HIGH); digitalWrite(PIN_RELAY_4, HIGH);

Arduino UNO R4 Code

This sketch sets pins D2, D3, D4 and D5 as outputs. In the loop, it turns all four relays on for one second and then off for one second. It also prints each step to the Serial Monitor.

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-4-channel-relay-module */ #define PIN_RELAY_1 2 // The Arduino UNO R4 pin connected to the IN1 pin of relay module #define PIN_RELAY_2 3 // The Arduino UNO R4 pin connected to the IN2 pin of relay module #define PIN_RELAY_3 4 // The Arduino UNO R4 pin connected to the IN3 pin of relay module #define PIN_RELAY_4 5 // The Arduino UNO R4 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

  • Wire it up as shown in the diagram.
  • Connect the board to your computer with a USB Type-C cable.
  • Open Arduino IDE, choose the correct Arduino UNO R4 board (for example, Arduino UNO R4 WiFi) and the correct COM port.
  • Copy the code above and paste it into the Arduino IDE.
  • Upload the code by clicking the Upload button.
  • Listen for the click of the relays. They should switch every second.
  • Open the Serial Monitor at 9600 baud to see the messages.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno R4 WiFi' on 'COM15')
New Line
9600 baud
Turn on all Turn off all Turn on all Turn off all Turn on all Turn off all Turn on all Turn off all
Ln 11, Col 1
Arduino Uno R4 WiFi on COM15
2

Tip: Test the relays with no high-voltage load first. When you hear all four relays click and see the LEDs on the module change, you know the wiring and the code are correct.

Video Tutorial

Function References

FAQ

Can I power the 4-channel relay module from the 5V pin of the Arduino UNO R4?

It is not a good idea. Four relay coils together draw much more current than the board should supply. Use an external 5V supply for the module, and connect its GND to the GND of the Arduino UNO R4.

Can I control each relay on its own?

Yes. Each relay has its own IN pin and its own Arduino UNO R4 pin. Call digitalWrite() on one pin only, and only that relay changes.

My relays turn ON when the code says LOW. Why?

Your module is set to low-level trigger. Move the trigger jumpers to high-level trigger, or swap HIGH and LOW in the digitalWrite() lines.

Does this code work on both the Arduino UNO R4 WiFi and the Arduino UNO R4 Minima?

Yes. Both boards have the same pins and the same 5V logic. Just select the right board in the Arduino IDE before you upload.

Can I use code from the classic Arduino UNO?

Yes, mostly. The pins are the same, and standard functions like pinMode(), digitalWrite() and delay() work the same way. Only code that uses AVR registers directly needs to be changed.

Troubleshooting

Problem Possible Cause Solution
No COM port appears in the Arduino IDE Charge-only USB cable or board not in bootloader mode Try another USB Type-C data cable, then double-press RESET to enter bootloader mode
No relay clicks The module has no power or the grounds are not shared Connect DC+ to the external 5V supply and join DC- with the GND of the Arduino UNO R4
Only some relays work An IN wire is loose or on the wrong pin Check that IN1 to IN4 go to D2, D3, D4 and D5
Relays work in reverse The trigger jumpers are set to low-level trigger Move the jumpers to high-level trigger or swap HIGH and LOW in the code
Board resets when the relays switch The relay coils take power from the board Power the module from an external 5V supply, not from the 5V pin
Relay clicks but the device does not turn on The device is wired to the wrong output pin Use COM and NO for a device that should be off by default, and check its own power adapter
Serial Monitor shows strange characters Wrong baud rate Set the Serial Monitor to 9600 baud

Application Examples

With four relays, the Arduino UNO R4 can control four separate devices. Here are some ideas to grow this project.

  • Build a four-zone garden watering system. Connect one water pump or valve to each relay, and use soil moisture sensors on the analog pins to decide which zone needs water.
  • Make a smart room controller. Wire a lamp, a fan, a heater and a night light to the four relays, and add four buttons so each one toggles its own relay.
  • Add a temperature control. Read a DS18B20 or DHT22 sensor, and let the Arduino UNO R4 turn on a fan relay when it is hot and a heater relay when it is cold.
  • Control the relays from your phone. On the Arduino UNO R4 WiFi, run a small web server and switch each relay from a web page.
  • Run devices on a schedule. Add a real-time clock module so the Arduino UNO R4 switches each relay at set times of the day.

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