How to use relay with arduino – Turn on and off 220VAC lamp

miliohm
27 April 2020 11:42
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Relay is switch that can be controlled with electronics controller such as microcontroller or arduino. so if you want to connect or disconnect a circuit you can simply use relay. There are so many types of relay in market. But in this tutorial we will learn how to use SPDT relay, which is enough for home appliances or hobby.

SPDT relay means Single Pole Double Throw, it means we have one common and another two pin that is Normally Open or Normally Closed. Here’s the schematic

relay schematic
relay schematic

At first the common pin will connected to NC (Normally Closed) but after the relay is energized then the coil will switch to NO (Normally Open).

So if you want to use the relay as switch for a lamp. You can connect common to Power Source and the NO to the lamp.

In this tutorial we will use 5V relay module and control it with an arduino UNO.

Arduino And Relay Schematic
Arduino And Relay Schematic

We can use any pin from arduino to trigger the relay, as long as we set it to OUTPUT. In this tutorial we use pin 9 of arduino. and This is the sketch to blink the relay (turn on relay and turn off repeatedly).

const int relay = 9;

void setup() {
  // put your setup code here, to run once:
  pinMode(relay,OUTPUT);
  digitalWrite(relay, HIGH);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(relay, LOW);
  delay(1000);
  digitalWrite(relay, HIGH);
  delay(1000);
}

Upload the program, and now you should hear the relay click every one second. You can connect the load to the relay. But before that i have to warn you that if you use 220VAC it is deadly if you are not carefully. So if this your first time, it is better to ask some supervisor.

The relay common is on the center, and normally open is on the right. So just connect the load like picture above. 

You can see the full tutorial in video here :

How to use relay with an arduino

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •