In-Depth: Interface Two Channel Relay Module With Arduino

Got an Arduino project that needs to control something running on mains voltage? A lamp? A motor? Here’s the catch—your Arduino operates at just 5 volts, while most household devices run on much higher voltages. So, how do you bridge that gap safely?

This is where relay modules come in. These compact, affordable modules act as electrically controlled switches, allowing your low-power Arduino to control high-voltage appliances without breaking a sweat (or anything else).

In this tutorial, we’ll show you how to hook up a two-channel relay module to your Arduino and use it to turn on and off devices like a lamp or fan. But before we dive into wiring and code, let’s take a quick look at how a relay works.

How Do Relays Work?

A relay is essentially an electrically operated switch. It uses a small electrical current to control a much larger electrical current. This allows one circuit to turn another circuit on or off, even if they’re at completely different voltage levels.

Relay Basics

Here’s a small animation showing how a relay links two circuits together.

relay working animation

Inside a relay, you’ll find a coil of wire wrapped around a core. This coil acts as an electromagnet. When a small current flows through the coil, it generates a magnetic field. This field attracts a small metal arm called the armature.

When the armature is pulled by the magnetic field, it physically moves. This action connects the larger, higher-power circuit you want to control.

When the small current stops flowing through the coil, the magnetic field disappears, and the armature returns to its original position, breaking the circuit.

So, by turning the small current on or off, you’re able to control a high-power circuit without handling it directly.

Relay Operation

A typical relay has five pins that stick out from the bottom.

relay pinout

Three of these pins are used for connecting the device you want to control. These three are called NC (Normally Closed), NO (Normally Open), and COM (Common).

The remaining two pins (coil1 and coil2) connect to the electromagnet coil inside the relay. Applying a voltage across these pins energizes the coil.

The device you’re controlling—like a lamp or motor—is connected between the COM pin and either the NC or NO pin. If you want the device to stay on by default, you connect it between COM and NC. Or, if you want it to stay off until you activate the relay, you connect it between COM and NO.

relay working animation2

When the relay is inactive (no current going through the coil), the COM pin is connected to the NC pin. That means electricity can flow through this path, powering any device connected to NC.

However, when an electric current flows through the coil, it generates a magnetic field. This magnetic field attracts the armature, causing it to move. This movement breaks the connection between COM and NC, and instead makes a new connection between COM and NO. This changes the path of the electricity, powering any device connected to NO.

Once the current stops flowing through the coil, the magnetic field disappears, and the armature returns to its original position. The COM pin reconnects to the NC pin, and the NO pin opens again, returning the relay to its normal state.

Circuit Diagram

Before we proceed, let’s take a look at the circuit diagram of the module. This diagram will help you understand how all the parts are connected and how it works.

two channel relay module circuit diagram

Two-Channel Relay Module Hardware Overview

A two-channel relay module features two independent relays, allowing you to control two high-powered electrical devices, such as lamps or motors. Each relay on the module can handle up to 10 amps of current at either 250 volts AC or 30 volts DC.

Two Channel Relay Module Relays

There are also relay modules available with one, four, or even eight relays, so you can choose one depending on how many devices you want to control.

Output Terminal Blocks

On one side of the module, you’ll find screw terminals for each relay. These terminals are labeled NC (Normally Closed), NO (Normally Open), and COM (Common). You connect your device across these terminals based on how you want it to behave—either turned on by default or off until activated.

two channel relay module output terminal blocks

Module Control

The other side of the module has two input pins, IN1 and IN2, which are used to control each relay. One important thing to remember is that the inputs are active low. That means the relay turns on when the input is set to LOW (0 volts), and it turns off when the input is HIGH (5 volts).

two channel relay module control pins

Each relay has an LED indicator that lights up when the relay is active, so you can see what’s happening at a glance.

Built-in Optocouplers

One of the great features of this module is that it includes optocouplers.

Two Channel Relay Module Optocouplers

These components provide electrical isolation between your Arduino and the relay, protecting your Arduino from potential back EMF (electromagnetic interference) from the coils.

Power Supply Selection Jumper

The module includes a small jumper between two pins labeled JD-VCC and VCC. This jumper controls how the relay receives power.

two channel relay module power supply selection jumper
  • With the jumper in place: Your Arduino powers the relays directly, and everything runs off one power source. This setup is simple but means your Arduino and the relay are not electrically isolated.
  • With the jumper removed: The Arduino and the relay are fully isolated, which is safer, but you’ll need to connect a separate 5V power supply to the JD-VCC and GND pins to power the relays.
relay module power selection jumper setting

Warning:

Remember, if you remove the jumper, leave the VCC pin disconnected, or you could damage the circuit.

Module Power

The module runs on 5 volts, and when both relays are turned on, it uses around 140 mA of current (about 70 mA for each relay).

Two Channel Relay Module Flyback Diodes

The module includes flyback diodes connected in parallel with the relay coils. When a relay coil is de-energized, it can create a sudden voltage spike called back EMF (electromotive force) that could damage the driving electronics. The flyback diodes provide a path for this current, adding an extra layer of protection for your Arduino.

Two-Channel Relay Module Pinout

Let’s take a look at the pinout.

relay module pinout

Control Pins:

VCC is the power supply pin. You connect this to the 5V pin on your Arduino.

GND is the common ground connection.

IN1 & IN2 pins are the control inputs for the relays. IN1 controls the first relay, and IN2 controls the second. One important thing to know is that these inputs are active-LOW. This means when you set the pin to LOW (0V), it turns the relay ON. When you set it to HIGH (5V), it turns the relay OFF.

Power Supply Selection Pins:

JD-VCC This pin supplies power specifically to the relay coils (the electromagnets that physically switch the contacts). A jumper is usually pre-installed between VCC and JD-VCC.

  • With the jumper in place, JD-VCC connects to VCC. This makes wiring simpler because everything gets power from your Arduino’s 5V supply. The downside is that your Arduino and the relay coils share the same power source so they are not electrically isolated.
  • When you remove the jumper, you separate the relay coil power from your Arduino’s 5V supply. This is important when you want to protect your Arduino from potential back EMF from the coils. If you remove the jumper, you must connect a separate 5V power supply to JD-VCC and GND to power the coils.

VCC connects to JD-VCC, when the jumper is in place. If you remove the jumper, leave this VCC pin disconnected. It’s only used for the shared power configuration.

GND is the common ground pin.

Output Terminals:

COM is the common terminal. Connect one side of the device you want to control to this pin.

NC (Normally Closed) is connected to COM, when the relay is deactivated. Use this connection if you want your device to be ON by default and turn OFF when the relay activates. The connection between NC and COM is broken when the relay is turned on.

NO (Normally Open) is disconnected from COM, when the relay is deactivated. Use this connection if you want your device to be OFF by default and turn ON only when the relay activates. The connection between COM and NO is created when the relay is turned on.

Wiring a Two-Channel Relay Module to an Arduino

Now that we understand how the relay module works, it’s time to put it to use! Let’s connect it to an Arduino and use it to control a lamp.

Important Safety Warning: This project involves working with HIGH AC voltage (mains electricity). Improper handling can lead to serious injury or death.

This project is intended only for individuals who thoroughly understand and have experience with high-voltage AC circuits. If you are not comfortable or experienced with mains voltage, do not attempt this project. Safety should always be your top priority when working with electricity, especially at household voltage levels.

Basic Connections

First, let’s connect the relay module to the Arduino:

  • Connect the relay module’s VCC pin to the 5V pin on your Arduino
  • Connect the GND pin to the Arduino’s GND pin
  • Since we’re only using one relay for this example, connect digital pin 6 from the Arduino to the IN1 pin on the relay module.

Connecting the Lamp

Now we’ll connect the relay module to the AC-powered lamp. Before you start, make absolutely sure the lamp is unplugged and the power source is switched off! This is extremely important for your safety.

Follow these steps:

  1. Carefully cut the live wire of the lamp’s power cord
  2. Take the end of the wire coming from the wall outlet and connect it to the COM (Common) terminal on the relay
  3. Connect the other end of the cut wire (the one going to the lamp) to one of these terminals:
    • NO (Normally Open) terminal: Lamp will be OFF by default and turn ON when the relay is activated
    • NC (Normally Closed) terminal: Lamp will be ON by default and turn OFF when the relay is activated

For this project, we want the lamp to be off until we turn it on, so we’ll connect one wire to COM and the other to NO.

The first diagram shows the basic setup with the jumper left in place on the relay module. In this setup, the Arduino’s 5V pin directly powers the relay’s coil. While this wiring is simple to set up, it doesn’t provide electrical isolation between the Arduino and the relay, which could potentially be dangerous if something goes wrong.

wiring relay module with arduino

Safer Alternative Setup

For better safety and to protect your Arduino, you can keep your Arduino and the relay electrically isolated. To do this, remove the jumper connecting JD-VCC and VCC on the relay module. Then connect a separate 5V power supply to the JD-VCC and GND pins on the relay module. The Arduino’s VCC and GND remain connected as before to power the control circuit, and the AC side connections stay the same.

wiring relay module with arduino and external supply

Arduino Example Code

Now that we’ve got the relay module wired up, let’s move on to controlling it with an Arduino. This part is actually pretty simple—controlling a relay is a lot like turning an LED on and off. We’re going to write a short program that turns the relay on for 3 seconds, then off for 3 seconds, and keeps repeating that pattern over and over.

int RelayPin = 6; void setup() { // Set RelayPin as an output pin pinMode(RelayPin, OUTPUT); } void loop() { // Let's turn on the relay... digitalWrite(RelayPin, LOW); delay(3000); // Let's turn off the relay... digitalWrite(RelayPin, HIGH); delay(3000); }

Once you upload this code, you should see the lamp turn on and off every three seconds, along with a soft clicking sound from the relay as it switches.

Code Explanation:

In our code, the first thing we do is tell the Arduino which pin we’ve connected the relay to. In this case, we’re using pin 6. So we create a variable called RelayPin and set it to 6.

int RelayPin = 6;

In the setup() function, we tell the Arduino to treat RelayPin as an output, since we’re sending signals from the Arduino to the relay.

pinMode(RelayPin, OUTPUT);

In the loop() function, we first turn the relay on by setting the pin to LOW, as relay modules are “active low” (they turn on when the pin is set to LOW). After turning it on, we wait for 3 seconds to keep the relay activated. Then, we turn the relay off by setting the pin to HIGH and wait for another 3 seconds. This loop repeats endlessly, turning the relay on and off every few seconds.

digitalWrite(RelayPin, LOW); delay(3000); digitalWrite(RelayPin, HIGH); delay(3000);

Tag » Arduino 5v Relay Wiring