Light detection circuit using LDR

Published Apr 25, 2021
 1 hours to build
 Beginner

Wouldn't it be amazing if the lights in your house would automatically off when there is sufficient light . And on when there is darkness in the house . We can do this with the help of LDR sensor . So let's start !!!

display image

Components Used

Arduino Nano
Arduino Nano
1
Breadboard
Breadboard
7
LDR -Photocell Photoresistor
LDR -Photocell, Photoresistor
2
Connecting Wire Jumper Wires
Connecting Wire Breadboard wires
6
LED 5mm
LED 5mm
5
Resistor 220 Ohms
Metal Film Resistors - Through Hole 220 OHM 1/4W 1%
4
Resistor 10 kOhms
Metal Film Resistors - Through Hole 10 kOhms 250 mW 1% 100 PPM / C
3
Description

Let's make the circuit  -

 Connections 

 Light-emitting diode [ LED ]

 Negative of led to Resistor 

 Resistor to Gnd of Arduino

 Positive of led to pin no 13 of Arduino

 

Led Connections 

Note -  Actually I am using the LDR sensor module but I will show connections for both. 

Connections 

 Light sensor module 

A0 pin to A0 pin, Gnd to resistor 

Resistor to Gnd of Arduino 

VCC to 3.3v

No connections for pin D0

 

LDR Connections 

 

Note: These connections are if you have a single LDR sensor like shown here : 

 

Invento 5PCS Photoresistor LDR CDS 5mm Light-Dependent Resistor Sensor  GL5516 DIY: Amazon.in: Industrial & Scientific
LDR sensor

 

Connect one end of this sensor to one leg of the resistor 

And another resistor to Gnd 

Connect another leg of this sensor to Pin A0

 

Code

Here is the code : 

const int ledPin = 13;
const int ldrPin = A0;
  void setup() {
  Serial.begin(9600);  
  pinMode(ledPin, OUTPUT);
  pinMode(ldrPin, INPUT);
}
void loop() {  
    int ldrStatus = analogRead(ldrPin);
    if (ldrStatus <= 800)
 {
   digitalWrite(ledPin, HIGH);   
  Serial.print("Its Dark, Turn on the LED:");  
  Serial.println(ldrStatus);  
}  
else  {
   digitalWrite(ledPin, LOW);   
  Serial.print("Its Bright, Turn off the LED:");  
  Serial.println(ldrStatus);
  }
}

 

 

When there is sufficient light the led will remain off.

And when there is darkness the led will remain on. 

The threshold given in the code is 800.

Finally, the project is completed !!!

Comments
Ad