Arduino Relay Control Tutorial

Published  December 28, 2017   7
S Saddam
Author
Arduino Relay Control Tutorial

LED Blinking is a very common and almost first program for every embedded learner or beginner. In which we blink an LED with having some delay. So today we are here with the same project but here we will use an AC bulb instead of normal LED and will blink an AC bulb.

Whenever we need to connect any AC Appliance in our embedded circuits, we use a Relay. So in this arduino relay control tutorial we will simply learn How to interface a Relay with Arduino. Here we are not using any Relay Driver IC like ULN2003 and will only use an NPN transistor to control relay.

 

Components Required:

  1. Arduino
  2. 5v or 6v relay
  3. AC appliance or Bulb
  4. BC547 transistor
  5. 1k resistor
  6. Breadboard or PCB
  7. Connecting jumper wire
  8. Power supply
  9. 1n4007 diode
  10. Screw terminal or terminal block

 

Relay:

Relay is an electromagnetic switch, which is controlled by small current, and used to switch ON and OFF relatively much larger current. Means by applying small current we can switch ON the relay which allows much larger current to flow. A relay is a good example of controlling the AC (alternate current) devices, using a much smaller DC current.  Commonly used Relay is Single Pole Double Throw (SPDT) Relay, it has five terminals as below:

SPDT Relay Working

When there is no voltage applied to the coil, COM (common) is connected to NC (normally closed contact). When there is some voltage applied to the coil, the electromagnetic field produced, which attracts the Armature (lever connected to spring), and COM and NO (normally open contact) gets connected, which allow a larger current to flow. Relays are available in many ratings, here we used 6V operating voltage relay, which allows 7A-250VAC current to flow.

 

The relay is always configured by using a small Driver circuit which consists a Transistor, Diode and a resistor. Transistor is used to amplify the current so that full current (from the DC source – 9v battery) can flow through a coil to fully energies it. The resistor is used to provide biasing to the transistor. And Diode is used to prevent reverse current flow, when the transistor is switched OFF. Every Inductor coil produces equal and opposite EMF when switched OFF suddenly, this may cause permanent damage to components, so Diode must be used to prevent reverse current. A Relay module is easily available in the market with all its Driver circuit on the board or you can create it on perf board or PCB like below. Here we have used 6V Relay module.

Relay driver circuit module

Here to turn on the Relay with Arduino we just need to make that Arduino Pin High (A0 in our case) where Relay module is connected. Below given is Relay Driver Circuit to build your own Relay module:

5v relay driver circuit module circuit diagram

 

Circuit Diagram and Working:

Arduino Relay Control Circuit Diagram

In this Arduino  Relay Control Circuit we have used Arduino to control the relay via a BC547 transistor. We have connected transistor base to Arduino pin A0 through a 1k resistor. An AC bulb is used for demonstration. The 12v adaptor is used for powering the circuit.

Controlling Relay using Arduino working

 

Working is simple, we need to make the RELAY Pin (PIN A0) high to make the Relay module ON and make the RELAY pin low to turn off the Relay Module. The AC light will also turn on and off according to Relay.

We just programmed the Arduino to make the Relay Pin (A0) High and Low with a delay of 1 second:

void loop()
{
   digitalWrite(relay, HIGH);
   delay(interval);
   digitalWrite(relay, LOW);
   delay(interval);
}

Demonstration Video and complete code for Arduino Relay Control is given below.

Code
// Arduino Relay Control Code
 
#define relay A0
#define interval 1000
void setup() {
  pinMode(relay, OUTPUT);
}
void loop()
{
   digitalWrite(relay, HIGH);
   delay(interval);
   digitalWrite(relay, LOW);
   delay(interval);
}
Video

Have any question realated to this Article?

Ask Our Community Members

Comments

Submitted by yashik on Fri, 12/29/2017 - 20:48

Permalink

Hi,
in aurduino can we used python language to code?
if possible can u send me the tutorial, to code and how to mention the pin numbers??
please do reply..
thankyou

Submitted by Why Me on Mon, 03/05/2018 - 18:24

Permalink

Hi,
In arduino we use language indonesian
I Dont Understand
Please replay Again
Thanks You

Submitted by Aman Sharma on Thu, 04/12/2018 - 16:46

Permalink

hi i want to light up a 12 volt LED strip and need to use a uln 2003 a and a 6volt relay and a capacitive sensor to control the light. i.e. when i once touch it it switches on, and when i touch it again it switches off. along with arduino uno. Now i am getting confused as in how shall i used= it. could you be able to help me with this. as i need to add several more componenets in future in order to learn more.

Submitted by Karan Kamboj on Sun, 04/22/2018 - 02:27

Permalink

make a circuit diagram Using six switches, three relays, three lights. the lights are energized when the circuit is at rest. activating any of the relays turns all three lights off.