Driving a Relay with an Arduino

Crazy Couple DIY
52 followers
163 Video Views·Sep 22, 2026
Hello everyone, welcome back to my channel. This is my 4th tutorial on how to drive a RELAY (not a relay module) with an Arduino.
There are hundreds of tutorial available on how to use a "relay module" but I could not find a good one that shows how to use a Relay and not a Relay module.
So, here we are to discuss how a relay works and how we can hook it up to an Arduino.
Note: If you do any work with "mains power" such as 120v or 240v AC power wiring, you should always use proper equipments and safety gears and determine whether you have adequate skill and experience or consult a Licensed Electrician. This projects is not intended for use by children.
For more amazing projects like this please visit: https://diyfactory007.blogspot.com.au/
AI Generated·May contain errors
Hello everyone, welcome back to my channel. This is my fourth tutorial on how to drive a relay
and not a relay module with an Arduino. There are hundreds of tutorials available on how to use a
relay module but I could not find a good one that shows how to use a relay and not a relay module.
So here we are to discuss how a relay works and how we can hook it up to an Arduino.
A relay is a large mechanical switch which is toggled on or off by energizing a coil.
Depending on the operating principle and structural feature relays are of different types
such as electromagnetic relays, solid state relays, thermal relays, power varied relays,
read relays, hybrid relays, multi-dimensional relays and so on with varied rating sizes and
applications. However in this tutorial we'll only be discussing about the electromagnetic relays.
The relay I'm looking at is a SRD 5 volt DC SLC. It is a very popular relay amongst Arduino and
DIY electronic hobbyists. This relay has five pins, two for the coil, middle one is called common
and the rest of the two are called normally open and normally closed. When current flows
through the coil of the relay a magnetic field is created that causes the ferrous armature to move
either making or breaking the electric connections. When the electromagnet is energized the normally
open is the one which is on and the normally closed is the one which is off. When the coil is
de-energized the electromagnetic force disappears and the armature moves back to the original
position turning on the normally closed contact. The closing and releasing of the contact results
in powering on and off the circuit. Now if you look at the top of the relay the first thing that
we see is songu. It is the name of the manufacturer. Then we see the current and voltage rating.
It is the maximum current and or voltage that can be passed through the switch. It starts from 10
ampere at 250 volt AC and goes down till 10 ampere 28 volt DC. Finally the bottom bit says SRD 5 volt
DC SLC. SRD is the model of the relay. 05 volt DC also known as nominal coil voltage or relay
activation voltage. It is the voltage necessary for the coil to activate the relay. S stands for
sealed type structure. L is the coil sensitivity which is 0.36 watt. C tells us about the contact
form. Let's start by determining the relay coil pins. You can do it either by connecting a
multimeter to the resistance measuring mode with a scale of 1000 ohm since the coil resistance
normally ranges between 50 ohm and 1000 ohm or by using a battery. This relay has no polarity
marked on it since the internal suppression diode is not present in it. Hence the positive output of
the DC power supply can be connected to any one of the coil pins. If we connect our battery to the
right pins you can actually hear a clicking noise when it's magnetized. If you ever get confused in
figuring out which one is normally open and which one is normally closed pin, follow the steps below
to easily find it out. Set the multimeter to resistance measuring mode. Turn the relay upside
down to see the pins located at the bottom part. Now connect one of the multimeter's probe to the
pin in between the coils. Then connect the other probe one by one to the remaining two pins. Only
one of the pins will complete the circuit and will show the activity on the multimeter.
The question is why to use a relay with an Arduino? A microcontroller's GPIO pins cannot
handle higher power devices. A LED isn't easy enough but a large power item such as a light
bulb, motor, pump or a fan requires more sneaky circuitry. You can use a 5 volt relay to switch
the 120 or 220 volt device and use an Arduino to control the relay. A relay basically allows a
relatively low voltage to easily control higher power circuits. A relay accomplishes this by using
5 volt outputted from an Arduino pin to energize the electromagnet which in turn closes an internal
physical switch to turn on or off a high power circuit. The switching contacts of a relay are
completely isolated from the coil and hence from the Arduino. The only link is by the magnetic field.
This process is called electrical isolation. For this tutorial we need a breadboard, a Arduino
Nano Uno whatever is handy, a relay, a 1k resistor, a 1N4007 high voltage high current rated diode
to protect the microcontroller from voltage spikes, a 2N2222 general purpose NPN transistor,
a LED and a 220 ohm current limiting resistor to test the connectivity, few connecting cables,
a USB cable to upload the code to the Arduino and some general soldering equipments.
Let's start by connecting the VIN and ground pin of the Arduino to the positive and the negative
rail of the breadboard. Then connect one of the coil pin to the positive 5 volt rail of the
breadboard. Next we need to connect a diode across the magnetic coil. The diode across the magnetic
coil conducts in the reverse direction when the transistor is turned off to protect against a
voltage spike or a backward flow of current. Then connect the collector of the NPN transistor to
the second pin of the coil. The emitter connects to the negative rail of the breadboard. Finally
using a 1k resistor connect the base of the transistor to the D2 pin of the Arduino. That's
it our circuit is complete. Now we can upload our code to the Arduino to turn on or off the relay.
Basically when positive 5 volt flow through the 1k resistor to the base of the transistor,
a current of about 500 microamp flow and turns on the transistor. Then a current of about 0.07
amp start flowing through the junction turning on the electromagnet. The electromagnet then pulls
the switching contact and moves it to connect the common terminal to the normally open terminal.
Once the normally open terminal is connected, a lamp or any other load can be turned on.
In this example, I'm just turning on and off a LED. The code is very simple. Just start by
defining the digital pin number 2 of the Arduino as the relay pin. Then define the pin mode as
output in the setup section of the code. Finally in the loop section we are going to turn on and
off the relay after every 500 CPU cycles by setting the relay pin to high or low respectively.
Remember it is very important to place a diode across the coil of the relay because a spike of
voltage which is inductive kickback from the coil is generated when the current is removed from the
coil due to the collapse of the magnetic field. The voltage spike can damage the sensitive
electronic component controlling the circuit. Most important same as capacitors we always
underrate the relay to mitigate the risk of relay failures. Let's say you need to work at 10 ampere
at 120 volt AC. Don't use a relay rated for 10 ampere 120 volt AC. Instead use a bigger one such
as 30 ampere at 120 volt AC. Remember power is equal to current into voltage. So a 30 ampere
at 220 volt relay can handle up to 6000 watt device. If you just replace the LED with any
other electrical device like fan, bulb, fridge etc you should be able to turn that appliance
into a smart device. A relay can also be used to turn on or off two circuits. One when the
electromagnet is on and the second one when the electromagnet is off. A relay helps in electrical
isolation. The switching contacts of a relay are completely isolated from the coil and hence from
Arduino. The only link is by the magnetic field. Thanks again for watching this video. I hope it
helps you. If you want to support me you can subscribe to my channel and watch my other videos.
Thanks. See you again in my next video. Bye now.
