Arduino Light Sensor Circuit Using LDR
Arduino Light Sensor Circuit Using LDR
ARDUINO (HTTPS://CIRCUITDIGEST.COM/ARDUINO-PROJECTS)
We all want our home appliances to be controlled automatically based on some conditions and that's called Home
automation (https://circuitdigest.com/home-automation-projects). Today we are going to control the light based of
darkness outside, the light turns ON automatically when it is dark outside and turns off when it gets bright. For this, we
need a light sensor to detect the light condition and some circuitry to control the Light sensor. It’s like Dark and light
Detector circuit (https://circuitdigest.com/electronic-circuits/dark-and-light-indicator) but this time we are using Arduino to
get more control over light.
In this circuit, we are making a Light Sensor using LDR with Arduino to control a bulb/CFL as per light condition of the
room or outside area.
Material Required
https://circuitdigest.com/microcontroller-projects/arduino-light-sensor-using-ldr 1/11
03/02/2021 Arduino Light Sensor Circuit using LDR
Arduino UNO
LDR (Light Dependent Resistor)
Resistor (100k-1;330ohm-1)
LED - 1
Relay module - 5v
Bulb/CFL
Connecting wires
Breadboard
Circuit Diagram
(/fullimage?
i=circuitdiagram_mic/Arduino-Light-Sensor-Circuit-diagram-using-LDR_0.png)
LDR
LDR is Light Dependent Resistor. LDRs are made from semiconductor materials to enable them to have their light-sensitive
properties. There are many types but one material is popular and it is cadmium sul de (CdS). These LDRs or PHOTO
RESISTORS works on the principle of “Photo Conductivity”. Now what this principle says is, whenever light falls on the
https://circuitdigest.com/microcontroller-projects/arduino-light-sensor-using-ldr 2/11
03/02/2021 Arduino Light Sensor Circuit using LDR
surface of the LDR (in this case) the conductance of the element increases or in other words, the resistance of the LDR falls
when the light falls on the surface of the LDR. This property of the decrease in resistance for the LDR is achieved because it
is a property of semiconductor material used on the surface.
We previously made many Circuits using LDR (https://circuitdigest.com/tags/ldr), which use LDR to automate the lights
according to requirement.
Working of LDR controlled LED using Arduino
As per the circuit diagram, we have made a voltage divider circuit (https://circuitdigest.com/calculators/voltage-divider-
calculator) using LDR and 100k resistor. The voltage divider output is feed to the analog pin of the Arduino. The analog Pin
senses the voltage and gives some analog value to Arduino. The analog value changes according to the resistance of LDR.
So, as the light falls on the LDR the resistance of it get decreased and hence the voltage value increase.
As per the Arduino code, if the analog value falls below 700 we consider it as dark and the light turns ON. If the value
comes above 700 we consider it as bright and the light turns OFF.
Code Explanation:
Complete Arduino Code and Demonstration Video is given at the end of this project.
Here, we are de ning the Pins for Relay, LED and LDR.
#define relay 10
int LED = 9;
int LDR = A0;
Setting up the LED and Relay as Output pin, and LDR as input pin.
https://circuitdigest.com/microcontroller-projects/arduino-light-sensor-using-ldr 3/11
03/02/2021 Arduino Light Sensor Circuit using LDR
pinMode(LED, OUTPUT);
pinMode(relay, OUTPUT);
pinMode(LDR, INPUT);
Reading the voltage analog value through the A0 pin of the Arduino. This analog Voltage will be increased or decreased
according to the resistance of LDR.
Giving the condition for dark and bright. If the value is less than 700 then it is dark and the LED or Light turns ON. If the
value is greater than 700 then it is bright and the LED or light turns OFF.
if (LDRValue <=700)
{
digitalWrite(LED, HIGH);
digitalWrite(relay, HIGH);
Serial.println("It's Dark Outside; Lights status: ON");
}
else
{
digitalWrite(LED, LOW);
digitalWrite(relay, LOW);
Serial.println("It's Bright Outside; Lights status: OFF");
}
(/fullimage?
i=inlineimages/u/Arduino-Light-Sensor-Circuit-diagram-using-LDR-and-Relay.png.png)
Instead of controlling an LED according to the brightness and darkness, we can control our home lights or any electrical
equipment. All we have to do is connect a relay module and set the parameter to turn ON and OFF the any AC appliance
according to the intensity of the light. If the value falls below 700, which means it Dark, then the relay operates and the
lights turns ON. If the value is greater than 700, which means its day or bright, then the relay will not operate and the lights
remain OFF. Learn more about relay here (https://circuitdigest.com/article/relay-working-types-operation-applications) and
how to connect an AC appliance to relay (https://circuitdigest.com/electronic-circuits/automatic-room-lights-using-pir-
sensor-and-relay).
https://circuitdigest.com/microcontroller-projects/arduino-light-sensor-using-ldr 4/11
03/02/2021 Arduino Light Sensor Circuit using LDR
Also, check:
Automatic Street Light Controller Circuit Using Relay and LDR (https://circuitdigest.com/electronic-
circuits/automatic-street-light-controller-circuit)
Automatic Staircase Light (https://circuitdigest.com/microcontroller-projects/automatic-staircase-lighting-using-
avr-microcontroller)
Raspberry Pi Emergency Light (https://circuitdigest.com/microcontroller-projects/raspberry-pi-emergency-lamp)
Code
#de ne relay 10
int LED = 9;
void setup()
Serial.begin(9600);
pinMode(LED, OUTPUT);
pinMode(relay, OUTPUT);
pinMode(LDR, INPUT);
https://circuitdigest.com/microcontroller-projects/arduino-light-sensor-using-ldr 5/11
03/02/2021 Arduino Light Sensor Circuit using LDR
void loop() {
Serial.print("sensor = ");
Serial.print(LDRValue);
if (LDRValue <=700)
digitalWrite(LED, HIGH);
digitalWrite(relay, HIGH);
else
digitalWrite(LED, LOW);
digitalWrite(relay, LOW);
Video
Email Address *
Name
https://circuitdigest.com/microcontroller-projects/arduino-light-sensor-using-ldr 6/11
03/02/2021 Arduino Light Sensor Circuit using LDR
Country
United States of America
Subscribe
RELATED CONTENT
(/electronic-circuits/simple-motion-detector-circuit-using-555-timer-and-relay-
to-control-ac-loads)
Build a Simple Motion Detector Circuit using 555 Timer to Control AC Loads (/electronic-circuits/simple-motion-
detector-circuit-using-555-timer-and-relay-to-control-ac-loads)
(/case-studies/why-its-important-to-set-date-and-time-in-numerical-relays)
(/case-studies/importance-of-relay-coordination-in-process-industries)
(/case-studies/importance-of-relay-selection-in-grid-connected-industries)
https://circuitdigest.com/microcontroller-projects/arduino-light-sensor-using-ldr 7/11
03/02/2021 Arduino Light Sensor Circuit using LDR
(/microcontroller-projects/automatic-bottle- lling-system-using-arduino)
(/case-studies/dont-use-your-numerical-relay-like-electromagnetic-relay)
(/case-studies/what-could-cause-repeated-relay-failures-in-chemical-plants)
(/electronic-circuits/relay-driver-module-circuit-pcb)
PREVIOUS POST
Arduino Ohm Meter (https://circuitdigest.com/microcontroller-projects/arduino-ohm-meter)
NEXT POST
https://circuitdigest.com/microcontroller-projects/arduino-light-sensor-using-ldr 8/11
03/02/2021 Arduino Light Sensor Circuit using LDR
Blinking LED Sequence with MSP430G2: Using Digital Read/Write Pins (https://circuitdigest.com/microcontroller-
projects/blinking-led-sequence-with-msp430-digital-read-write-pins)
COMMENTS
Pragathi k s
Jul 29, 2018
Good
Log in (/user/login?destination=node/1626%23comment-form) or register (/user/register?
destination=node/1626%23comment-form) to post comments
Easy-To-Use Onion Tau Camera Offers an Affordable Entry Point to LIDAR-Like 3D Mapping (/news/easy-to-use-
onion-tau-camera-offers-affordable-entry-point-to-lidar-3d-mapping)
(/news/easy-
to-use-onion-
tau-camera-
offers-
affordable-
entry-point-to-
lidar-3d-
mapping)
New High-Temperature Snubber less TRIACs can Save Space and Boost Reliability (/news/new-high-temperature-
snubber-less-triacs-can-save-space-and-boost-reliability)
(/news/new-
high-
temperature-
snubber-less-
triacs-can-
save-space-
https://circuitdigest.com/microcontroller-projects/arduino-light-sensor-using-ldr 9/11
03/02/2021 Arduino Light Sensor Circuit using LDR
and-boost-
reliability)
High-Speed Inductive Position Sensor for Easy Customization and High Accuracy in Automotive Applications
(/news/high-speed-inductive-position-sensor-for-easy-customization-high-accuracy-in-automotive-applications)
(/news/high-
speed-
inductive-
position-
sensor-for-
easy-
customization-
high-
accuracy-in-
automotive-
applications)
250 kHz IMC-Hall Current Sensor for High Accuracy and Diagnostics in Inverters/Converters and Battery
Applications (/news/250-khz-imc-hall-current-sensor-for-high-accuracy-and-diagnostics-of-inverters-converters-
and-battery-applications)
(/news/250-
khz-imc-hall-
current-
sensor-for-
high-
accuracy-and-
diagnostics-
of-inverters-
converters-
and-battery-
applications)
New Road Noise Cancellation (RNC) Sensors with A2B Technology to Combat Unwanted Road, Wind, and HVAC
Car Noise (/news/new-road-noise-cancellation-rnc-sensors-with-a2b-technology-to-combat-unwanted-road-wind-
and-hvac-car-noise)
(/news/new-
road-noise-
cancellation-
rnc-sensors-
with-a2b-
technology-
to-combat-
unwanted-
road-wind-
and-hvac-car-
noise)
https://circuitdigest.com/microcontroller-projects/arduino-light-sensor-using-ldr 10/11
03/02/2021 Arduino Light Sensor Circuit using LDR
Connect with us on social media and stay updated with latest news, articles and projects!
(https://www.linkedin.com/company/circ
(https://www.facebook.com/circuitdigest/)
(https://twitter.com/CircuitDigest)
(https://www.youtube.com/channel/UCy3CUAIYgZdAOG9k3IP
(https://www.instagram.com/circuit_digest/)
(https://www.pinterest.com/circuitdigest/)
digest/)
CATEGORIES
Events (https://circuitdigest.com/events)
POPULAR
CALCULATORS (HTTPS://CIRCUITDIGEST.COM/CALCULATORS)
NEWSLETTER
Subscribe
https://circuitdigest.com/microcontroller-projects/arduino-light-sensor-using-ldr 11/11