In this tutorial we are going to make an automatic light ON and OFF during night and day respectively using LDR sensor that gets activated or it's resistance gets reduced when light falls on it. We have also connected a manual switch ON and OFF for the bulb whenever we are out of home for weekends.
Let's get started,
Components Required:
- Arduino UNO X 1
- LDR light sensor X 1
- 5V RelayModule X 1
- Resistor (100k) X 1
- AC Bulb (25 or 100) Watt X 1
Circuit Design:
(Note: First upload the program to the Arduino IDE then only do the below given wirings in order to avoid short circuit from previously uploaded code in the Arduino.)
It is the sensor with resistance as it's main property. When light falls upon it then it's resistance decreases and allows electric current to flow through it. And when it is dark then it offers high resistance to the circuit and blocks current to flow through it.
Let's see it graphically,
In the above diagram, as light intensity increases, resistance decreases and when light intensity decreases then resistance of LDR increases.
(Note: About relay and other module we have already discussed in other tutorials that you can see in the same website.)
Coding:
int ldr=A0; // taking input from LDR in pin A0 i.e anolog pin
int led=1; // declaring output pin for bulb
int ldrStatus;
void setup()
{
pinMode(ldr,INPUT);
pinMode(led,OUTPUT);
pinMode(led,LOW);
Serial.begin(9600);
}
void loop()
{
ldrStatus=analogRead(ldr);
Serial.println(ldrStatus); //check sensor value in light and dark condition
if (ldrStatus<=1000) // checks if it is day then led remains OFF
{
digitalWrite(led,LOW);
}
else
{
digitalWrite(led,HIGH); // during night led becomes ON
}
}
In this way you can make your own automated light system using Arduino, Relay, and LDR sensor. Also by removing relay and placing the 5 volt bulb to the digital pin 1 with 0.5 K or 220 omh resistor, you can directly make your DC 5 volt bulb operate from Arduino as shown in below given figure with your mini project done.(Upload the same code)
Applications:
- Make your own home automation using LDR sensor
- You can also make automated traffic light system that will ON during night and OFF during day
2 Comments
How can I do this with an LDR digital sensor instead
ReplyDeletepowerup the module and connect analog output pin of sensor to A0 pin of arduino and use the same code
DeleteIf you have any doubts, Please let us know.
Also you can visit my newly made freelancing account to make your project done at low price.
https://www.freelancer.com/get/jpmandal2?f=give