A Beginner’s Guide to Using Relay Modules in Arduino Projects

- Categories : Products

Are you planning to use a relay module in your upcoming Arduino project but don’t know how to go about it? No worries! This blog post will take you through the process of using a relay module in Arduino projects, step-by-step, so that you don’t need to depend on anyone else when working with relays.  

Relays are often used in electrical and electronic circuits because they play a major role in switching and protection circuits. Let’s take a look at the internal structure of a relay and its working principle, along with the different types of relays available in the market.

What Is a Relay?

A relay is an electromagnetic switch that uses a small current to drive a larger circuitry. Basically, a signal is applied at the input which switches on another circuit connected at the output, without the need of human supervision.

Relays work on the principle of electromagnetic induction, which implies that if current passes through a coil that is wound around a piece of metal, then a magnetic field will be produced by the current, turning the metal core into an electromagnet.

If you look inside a relay, you will find an electromagnet which has an armature attached to contacts that connect the input and output terminal when electric current passes through the coil. The outer packaging of a relay has five pins, two of which connect to either sides of the coil and applying a voltage on these pins energizes the coil. The remaining three pins are – Normally Open (NO), Normally Closed (NC) and Common (COM).

Originally, the armature is connecting the COM and NC contacts but when current passes through the electromagnet and charges the coil, it creates a magnetic field which attracts the armature and hence, the armature shifts from the normally closed position to the normally open position, driving the larger circuit connected on the NO pin. This is the basic working principle of a relay. Now let’s understand what a relay module is.

A relay module is a small board embedded with either one or two relays and a combination of resistors, diodes, transistors and screw terminals. You can connect the input and output circuitry via screw terminals and supply power using the pins present on the module. The special feature of a relay module is that it is compatible with Arduino because it operates on 5 Volts that an Arduino board can support.    

What Are the Types of Relays

There are many different types of relays used in electrical systems which are differentiated based either on their poles and throws or their working principle.

Types of Relays Based on Poles and Throws

The number of poles and number of throws in a relay can vary as follows:


SPST stands for Single Pole Single Throw relay which means there is only one contact besides COM, hence only one circuit can be connected to this relay and it can have only two positions – closed or open. SPST relay is similar to a switch which has two states – ON and OFF.


Single Pole Double Throw (SPDT) relays have been described in the previous section. They can control one circuit because of a single pole but the relay can have two positions – Normally Open (NO) or Normally Closed (NC).


DPST stands for Double Pole Single Throw. Double pole indicates that this relay can control two separate circuits, each having a single throw. If you need to control two circuits simultaneously by switching them on and off then DPST is your best choice.


The Double Pole Double Throw (DPDT) relay is more like two SPDT relays packed inside one relay where you can switch the two SPDT relays simultaneously to control two isolated circuits. DPDT consists of two poles having double throws each. 

Types of Relays Based on working Principle

Not all relays work on the principle of electromagnetic induction. There are other principles as well which control relays. Here are the types of relays based on their working principle:

Electromechanical Relays

Electromechanical relays use an electromagnet to control a mechanical switch, as explained in the previous section. When the coil energizes, it attracts the armature and changes the state of the relay from normally closed to normally open. These relays are used for both AC and DC applications.

Solid State Relays

Unlike the previous relay, these relays do not have mechanical parts such as an armature and electromagnet. These relays are made of semiconductor material and an optocoupler is used to isolate the high current circuit from the low current voltage.

When a current is detected at the input, it lights up an LED. Light travels from the LED to the photosensitive detector at the other end which turns on the circuit at the output. These relays are much faster because they use infrared light as the medium of travel.

Hybrid Relays

As the name suggests, these relays are made using both electromechanical and solid-state relay principles. It uses the advantages of both types of relays to perform better. These relays have an optocoupler present at the input side and an electromagnet at the output. It reduces power loss and eliminates excessive heating.

Electrothermal Relays

The working principle of these relays is like thermostats. It consists of a strip made up of two different metals with different thermal properties, called a bimetallic strip, which is placed near a heating coil through which current passes. When the coil heats up, it transfers heat to the bimetallic strip and because the metals have different thermal expansion properties, they expand at different rates, causing the strip to bend. When the strip bends, it switches the relay on. These relays are most commonly used in protection circuitry for motors.

How to Choose a Relay Module?

Choosing a relay module depends on the type of project you are planning to implement. There are certain factors that you need to keep in mind while making this decision.

Voltage and Current Requirements

When choosing a relay module, you must know the current and voltage requirements of your project. If you choose a relay that does not support the power requirements of your project, then you might end up ruining the relay and possibly your project circuitry as well.

No. Of Circuits to Control

Since there are four options of relays available with respect to number of poles and throws, you must know how many circuits you need to control in your project so that you can make a choice between these four types of relays. For instance, if you wish to control two circuits simultaneously with a NO and NC configuration, then you must opt for a DPDT relay.


If speed is something that you are worried about in your project, then you should opt for a solid-state relay because it uses an optocoupler which performs faster than the electromechanical relay. However, solid-state relays are not good in terms of heat losses.

How to Connect and Program Your Relay?

Now that you know how a relay works and what are the different types of relays, let’s move on to learning how to connect and program a relay with an Arduino.

We will consider the example of a very simple project – switching on an AC bulb using a relay. For this, you will need a relay module, an Arduino (we are using an UNO board here), an AC bulb and a power cord with a 2-pin plug. First, take the power cord and separate the live and neutral wires present inside it. Connect the live (red) wire with the bulb and connect the neutral (black or blue) wire to the normally open (NO) connector on the relay module. Then, connect the second wire of the bulb to the COM connector on the relay module. This is how you connect a relay with an AC bulb for switching purposes.

Now, we need to supply power to the relay module and supply it with a signal from the Arduino that tells the relay to switch the bulb on and off. For this, you need to connect the pin with a minus (-) sign on the relay module to the ground (GND) on Arduino and the positive (+) pin of the relay module to the 5V supply on your Arduino board. The third pin left on the relay module is the command pin, which must be connected to an I/O pin on Arduino. We are considering pin 7 for this purpose. You can choose any digital I/O pin that you like, but make sure to program your Arduino accordingly. 

After connecting the hardware as described, you need to write a simple code that establishes pin 7 as an output pin and sends a signal to switch the bulb on and off via the relay module. Here is how you can write the code for the circuit shown in the picture above.

void setup() {

  // initialize the digital pin as an output.

  pinMode(7, OUTPUT);


void loop() {

  digitalWrite(7, HIGH);   // turn the BULB on (HIGH is the voltage level)

  delay(1000);               // wait for a second

  digitalWrite(7, LOW);    // turn the BULB off by making the voltage LOW

  delay(1000);               // wait for a second


After uploading the code in your Arduino board and connecting the circuit as shown above, you will notice that the relay automatically switches the bulb on and off after every second, as it receives the command from Arduino.

This is a very simple approach just to give you an idea of how a relay module works. You can incorporate a relay module in your Arduino project using this idea as the baseline and improvise it as per your requirements.

Share this content