Skip to main content

Interfacing RELAY with Arduino UNO

 
Interfacing RELAY with Arduino UNO


What is Relay?

Relay is an automatic switch that detects conditions in circuits and causes the contacts to change their positions to close or open the circuit as required. Relays are used in many applications. When the coil of the relay is energized or de-energized, its contacts are ON or Off.         In a relay, we have to consider two important parameters i.e. once is the Trigger Voltage, this is the voltage required to turn on the relay that is to change the contact from Common->NC to Common->NO. Our relay here has a 5V trigger voltage.

 




Let’s understand the interfacing of relay with Arduino


I amusing online simulation software (Tinker cad). Tinker cad helps to interface, code, and simulate online. All the components I have used are present in the software. You can also build your own circuit. All the components have been labeled in the above Figure.
The push-button is connected to pin2 which is a digital pin and the relay is connected to pin4. The pin is used as the input pin whereas pin 4 is the output pin. When we press the push button a digital high signal is given to the Arduino. As the Arduino gets HIGH signal from pin2, it provides a Digital HIGH signal to pin4(Relay). The relay is been closed and the Bulb glows.

Fig1: Image when Push Button is not pressed

Fig2: Image when Push Button is pressed

CODE:

/*
Harshal Sawant
05/02/2021
*/
void setup()
{
  pinMode(4, OUTPUT); // pin4 defined as output pin
  pinMode(2, INPUT);  // pin2 defined as input pin
}

void loop()
{
  if(digitalRead(2)== HIGH) //checking if there is high slg on pin2
  {
    digitalWrite(4, HIGH); //Digital Write high if pin 2 is high
  }
  else
  {
    digitalWrite(4, LOW); //Digital Write low if pin 2 is low
  }
  delay(100);
}
 
If  you are interested to see the working go to the link below



Comments