< img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=5580415518647572&ev=PageView&noscript=1" />
Close this search box.

How to Use a Relay Module with Arduino

Using a 4 channel 5V relay module with Arduino
Using a 4 channel 5V relay module with Arduino

Using a relay module with Arduino microcontrollers is a simple and easy way to control a variety of devices and components. In this relay module Arduino tutorial, you’ll learn, in a step-by-step process, how to use a relay module with this type of microcontroller. But first, about the module and what it means to use it with an Arduino.

What Is Relay Module Arduino?

A relay module is an electronic device that uses electromagnetism to mechanically operate a switch. It’s basically an electromagnetic switch that can be activated by an electrical current. In other words, it’s a way to control one circuit by using another circuit.

A relay module Arduino circuit involves pairing an Arduino microcontroller with a relay. The microcontroller activates the relay, which in turn can be used to activate or deactivate a device or component.

The Arduino connects to and supplies the relay module input voltage, enabling it to turn a higher voltage load on and off. This makes it useful for controlling devices that require higher voltages, such as lamps and motors.

Using relay module with Arduino
Using relay module with Arduino

Using Relay Module with Arduino

Using a relay module with Arduino offers many benefits. First, it allows Arduinos to control devices that require a higher voltage or current than what the microcontroller can provide. Second, it protects the Arduino from damage by the device or component being controlled.

An Arduino also cannot produce enough power to directly control a motor or high-voltage load. By using a relay module, Arduino microcontrollers can operate these devices indirectly.

Additionally, a relay module can be used to control multiple devices or components with just one Arduino board. That allows users to manage an array of devices with ease and from a single location.

4 relay module Arduino connection
4 relay module Arduino connection

How to Use a Relay Module with Arduino

Using relay module with Arduino microcontrollers is a straightforward process. It also only requires a few components that are usually readily available. In this section, we’ll go over the steps needed to set up and use a relay module with Arduino microcontrollers.

Before we get started, you’ll need to gather a few supplies. In addition to an Arduino microcontroller, you’ll need a relay module, some jumper wires, and a device or component to control such as light.

  • In our Arduino and relay module project, we will use the one-channel configuration. Note that multiple relay configurations are also possible.
  • Other option includes using a 4-relay module Arduino, 8-relay module Arduino and even up to 16 relays.
Relay module Arduino schematic diagram
Relay module Arduino schematic diagram

Relay Module Arduino Connection

Caution! If using mains electricity or any other high-voltage source, take appropriate precautions. The high voltage can be dangerous, even fatal.

1. Begin by connecting the ground (GND) pin on the Arduino to the ground pin on the module. Then, connect the power (5V) pin on the Arduino to the VCC pin on the module.

2. Next, connect the signal (S) pin on the Arduino to the IN1 pin on the module. You can use a different input pin on the module if you’d like, but for this example, we’ll be using IN1.

3. Finally, connect the device or component you wish to control using the Arduino with relay module. In our example, we’ll be controlling a light, so we’ll connect one end to the COM terminal and the other to the NO (Normally Open) or NC (Normally closed) terminal.

Use the NO terminal if you want the light to only turn on when the relay is activated. Use the NC terminal if you want the light to turn off when the relay is activated.

Relay Module Arduino Code

Now that your hardware is all set up, it’s time to write the code that will tell the Arduino what to do, or the relay module Arduino code.

The Arduino code for relay module operation contains the basic functions to control a relay. In our case, we’ll want the light to turn on for 2 seconds and turn off for another 2 seconds.

1. First, we need to establish the variables that will be used in our code. In our example, we’ll be using two variables: one for the light and one for the delay.

2. After that, we need to set up our void setup (){} function. This is where we’ll tell the Arduino what pins are being used and what state they should start in.

3. For our example, we’ll be using pin 13 for the light and we’ll set it to be an OUTPUT. Here is a sample code.

int Relay = 3;

void setup()


pinMode(13, OUTPUT); //Set Pin13 as output

digitalWrite(13, HIGH); //Set Pin13 High

pinMode(Relay, OUTPUT); //Set Pin3 as output


void loop()


digitalWrite(Relay, HIGH); //Turn on relay


digitalWrite(Relay, LOW); //Turn off relay



And that’s it! When you upload this code to your Arduino and power it on, the light should turn on and then turn off every 2 seconds, over and over again.

Arduino Relay Projects

Now that you know how to use a relay module for Arduino, you can begin incorporating them into your own projects. These may include turning on and off lights, motors, fans, or other devices. You can also use the setup to control more than one device at a time; by using multiple relays.

As you can see, using a relay module with Arduino microcontrollers is a relatively simple process and can be used to create all sorts of automated devices.

With a few simple components, you can create all sorts of automated devices and control them remotely. Give it a try and see what you come up with!


Using a relay module with Arduino microcontrollers is a simple and efficient way to control high-voltage devices or components. With just a few connections and some basic code, you can create all sorts of automated systems. When used in combination with other components, the possibilities of Arduino relay module control systems are endless.

Picture of William

I am William, Electrical Engineering Author. Dedicated to writing technical articles on Timer Relay, Monitoring Relay, Surge Protection Device and other electrical devices. With 7 years of writing experience, I am committed to providing accurate and in-depth expertise to my readers.


    Amei o seu projeto e como o torna fácil.

    chiedo aiuto su un circuito arduino abbinato a due relè, dove ognuno comanda uno scambio elettrico del trenino a 12v. Nei contatti del relè distribuisco il negativo del 12 V cc alle due bobine dello scambio. Questo per settare la posizione dello scambio diritto o deviato.
    I relè alimentati da arduino uno funzionano correttamente senza carico in uscita e con le spie rosse dei led dei relè controllo il regolare funzionamento. Quando collego il negativo, che va alle bobine degi scambi (uscite del relè NC – NO – Comune) il relè si disattiva e anche arduino si resetta senza motivo. Cioè senza carico a vuoto funziona correttamente ma con il carico si resetta e non funziona. Ho controllato con un un amperometro la corrente che circola ma è sempre molto bassa. Non capisco il motivo dell’anomalia. Mi può aiutare? Se serve giro schema.

    This probably isn’t the place, but to your knowledge, do I err assuming that with a 4 channel relay module, without over simplifying , one could control a 12v dc motor fwd and rev with 2 relays, thus controlling 2 12v dc motors fwd & rev with 4 channel relay module with arduino. Furthermore, beyond that it should so also be possible to use any sort of signal/condition input to trigger the on/off state of 2 dc motors both fwd/rev… therefore it’s not impractical to utilize a pwm signal from an rc receiver once mapped or however it’s decided / that once a certain parameter is achieved, whether based on a range in microseconds of the pulsewidth… or irregardless of how you determine. It should be possible to turn a relay off or on remotely with an rc receiver and transmitter… I keep reading all over the place that it can’t be done. And being no professional want to call bs. Is the something I’m not taking into account because I’m finding it difficult to to see how it’s not a simplistic and very achievable feat..

    Para hacer eso que tu dices de controlar un motor ya sea hacia adelante o hacia atras, podrias optar mejor por utilizar un modulo puente en H

Leave a Reply

Table of Contents
Contact Us
Contact Us
Contact Us

Shopping cart


No products in the cart.

Continue Shopping
Contact Us