INTRODUCTION
In this tutorial, we are going to learn how to interface a Single Channel Relay Module to an Arduino UNO. And we will also learn briefly about its working principles.
THEORY
Basically, Relay is an electromechanical switch. It works like an electric switch. It uses an electric current to open or close the contact of the switch.
(1 CHANNEL RELAY MODULE)
It can control large loads and devices such as DC Motors, AC Motors, & other AC DC devices. Here we have taken a single channel Relay module that’s why we can only operate one device through a microcontroller/processor.
Inside a relay, there are 3 pins
i)NO(Normally Open)
ii)NC(Normally Closed)
iii)COM(Common)
Supply voltage of Relay 3.75V to 6V. Having maximum contact voltage is 250VAC or 30VDC. It having a maximum current of 10Amp.
The relay has 3 pins.
i)VCC
ii)GND
iii)Data Pin
REQUIREMENTS
Parts | Quantity |
Arduino UNO | 1 |
A-B cable | 1 |
1-Channel Relay Module | 1 |
9V Battery | 1 |
Battery Cap | 1 |
LED | 1 |
Bread Board | 1 |
Connecting Wires | As per required |
CIRCUIT DIAGRAM
NOTE: Here in the circuit diagram I have connected the LED to Relay through a power source(Battery).
PROGRAM
For programming this concept we need to understand some basic syntax of Arduino IDE. The first thing is we need to install Arduino . After that, we need to know how to interface led to Arduino.
To control a Relay we need to declare Relay as an output.
pinMode(PIN Number, Device TYPE);
PIN Number– The pin, to which we have connected the device. In this case, I have attached Relay’s data pin to 7 no pin of Arduino UNO.
Device Type– What is the device type. Like, For output devices we need to declare the type as OUTPUT and for input devices, we need to declare it as INPUT. In this case, we have connected Single Channel Relay Module, So we have to declare this as output.
pinMode(RELAY,OUTPUT);
After all declaration, we have to go for the digitalWrite() function.
digitalWrite(PIN Number, Status);
PIN Number– in which pin we have connected the device. In this case, I have attached 7 no pin of UNO.
Status– Status means we need to turn the Relay on/off. For turning Relay on we can write LOW or 0 and for turning off led we can write HIGH or 1.
NOTE: In the case of a switch it is opposite to a normal device that was used like in sensors, led, etc. for on we have to write HIGH but in Relay and switches we have to write LOW for ON it.
Code
/*
Tested by robogenesis. in
*/
#define RELAY 7 //defined that RELAY is connected to 7 no pin
void setup()
{
pinMode(RELAY,OUTPUT); // RELAY is a output device
}
void loop()
{
digitalWrite(RELAY,LOW); // ON Relay
delay(5000); // 5s delay
digitalWrite(RELAY,HIGH); // OFF Relay
}
Comments