Arduino is a microcontroller based prototyping board that runs on small DC power. A Relay is a device that helps microcontrollers (or microcontroller based boards) like Arduino to switch on or off different household appliances like motors, lights, water heaters, television and fans etc.

In this project, we will see a simple circuit where an Arduino UNO will control a 5V relay.

Note:
We have used Arduino UNO in this project as it is more popular than other Arduino boards and beginners in electronics can easily use it. If you have any other board like Arduino Nano or Arduino Mega, you can use it.

Caution: 
We are going to connect 240V Mains supply to the 5V relay module to turn on a lamp. You should be very careful and cautious when using mains supply.

Table of Contents

1. Circuit Diagram
2. Circuit Description
3. Components Required
4. Working
5. Source Code
6. Output

Circuit Diagram



Circuit Description

We are using a 5V relay in this project. The circuit diagram explains the details connections "we didn't need to make all the connections".In the load part, the lamp, the wire from the main supply is connected to one terminal of the lamp, other terminal of the lamp is conected to normally open contact of the 5V relay, finally the neutral wire from main is connected to common contact of the relay. A light sensor in the form of LDR(Light Dependent Resistor) is used to switch on and off the light automatically, the output of LDR is given to analog input pin A0.

Components Required

1. Arduino UNO (or any other Arduino board)  
2. 5V Relay  
3. 1N4007 Diode  
4. BC547 – NPN Transistor  
5. Red LED (can be used as a Power ON LED)  
6. Green LED (can be used as a Relay ON LED)  
7. 2 x 1K Ohm Resistors (1/4 W – for Red and Green LEDs)  Lamp  
8. Wires for connecting DC Voltage components  
9. Wires for connecting AC Mains and lamp  

Working

UNO controls a 5V relay is explained here, the working of the project is based on the functioning of the Relay and the ability of Arduino to control the relay. We intend to operate an AC load like lamp (Instead of using it directly). The application where an LDR is used to detect the light intensity and automatically turn on or off the relay. Under normal lighting conditions, the output from the LDR will be in the range of 80 – 90 (range is 0 – 255). When the lighting conditions go dark (can be done by covering the LDR with hand), the output from the LDR will jump to 130 – 140. This condition can be used to trigger the 5V Relay and turn on the light.

Source Code

const int relay=8;

const int Ainput=A0;

int ldrValue = 0;  
     
int range = 0; 
      
void setup() 

{

pinMode(relay,OUTPUT);

digitalWrite(relay,HIGH); // My Relay is an active LOW Relay.

Serial.begin(9600);

}

void loop() 

{

  ldrValue = analogRead(Ainput);

  range = map(ldrValue, 0, 1023, 0, 255);
  
  Serial.println(range);

  if(range>125)

  digitalWrite(relay,LOW);

  else

  digitalWrite(relay,HIGH);

}


OUTPUT:


BY 
      REGU RAM SV.

3 Comments

  1. How to upload the code into Arduino board bro.

    ReplyDelete
    Replies
    1. Click on upload icon in the top.

      Delete
  2. Super bro, give more project ideas.

    ReplyDelete

Post a Comment

Previous Post Next Post