Make your home smart with Arduino…..Do yourself.

How to operate Relay via Arduino-Easy Explanation.

We know Arduino is the complete solution to operate almost every device with the help of programming skill and also cost effective. But Arduino operates on the very small voltage range like 5V and 3.3V but sometimes we want to handle bigger devices like Fan, Heater and Water pump using it. But Arduino not able to handle this device and here we required a device which can isolate Arduino from the high power and we require RELAY.
Relay :
The relay is an electromechanical switch which operates on the principle of electromagnet. When you give power to this switch, it changes its states. We can better understand it via a diagram.
Normally switch is used between the power source and Gadget and we manually switch it on and off but using relay we can do this with the help of computer or microcontroller, in this case, we are going to use Arduino to do so.
normal switch
As shown in the diagram normally relay have 5 terminal and they are NC(Normally connected), NO(Normally open), Vcc and GND and one terminal to connect the load(gadget) and we use NC and NO terminal as per our application. If you want to switch something ON after giving signal then connect your gadget with NO(Normally open) and if you want to stop something after giving signal then connect your gadget to NC(Normally connected). Here we used the diode IN4007 to avoid the chattering of the relay.
relay switch
How to do this :
Component Required :
1.Arduino Uno Board
2.Relay 5v
3.Battery/power source
Be careful while connecting AC power supply and DC power supply. Don't mix them, it may fry your computer or Logic Board.
Program :
int microbutton=A0;
int ac_lamp=2;
void setup()
 pinMode(microbutton,INPUT); //Set the pin A0 for input
 pinMode(ac_lamp,OUTPUT);//Set the pin 2 for output

analogWrite(mirobutton,LOW); //Initialize the pin A0 to low
digitalWrite(ac_lamp,LOW); //Initialize the pin A0 to low

void loop()
if (analogRead(microbutton)>0) //if button press it gives some value to A0
digitalWrite(ac_lamp,HIGH); // set pin 2 to high
Serial.println("lamp on"); // print the value on serial monitor for cheking
delay(5000); //take delay of 5 second
digitalWrite(ac_lamp,LOW); //switch off the lamp after 5 second
Serial.println("lamp off");

In this project we switch the lamp with the help of micro switch but you can use LDR or Temp sensor as per your application and switch the fan or lamp on and off. For more details ask the question in comment can find even more details on