Arduino Light Sensor Circuit Using LDR
Arduino Light Sensor Circuit Using LDR
Material Required
Arduino UNO
LDR (Light Dependent Resistor)
Resistor (100k-1;330ohm-1)
LED - 1
Relay module - 5v
Bulb/CFL
Connecting wires
Breadboard
Circuit Diagram
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 sulfide (CdS). These
LDRs or PHOTO RESISTORS works on the principle of
“Photo Conductivity”. Now what this principle says is,
whenever light falls on the 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, which use
LDR to automate the lights according to requirement.
Code Explanation:
Complete Arduino Code and Demonstration Video is
given at the end of this project.
Here, we are defining the Pins for Relay, LED and LDR.
#define relay 10
int LED = 9;
pinMode(relay, OUTPUT);
pinMode(LDR, INPUT);
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);
else
digitalWrite(LED, LOW);
digitalWrite(relay, LOW);
Also, check:
Automatic Street Light Controller Circuit Using Relay
and LDR
Automatic Staircase Light
Code
#define relay 10
int LED = 9;
int LDR = A0;
void setup()
{
Serial.begin(9600);
pinMode(LED, OUTPUT);
pinMode(relay, OUTPUT);
pinMode(LDR, INPUT);
}
void loop() {
int LDRValue = analogRead(LDR);
Serial.print("sensor = ");
Serial.print(LDRValue);
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");
}
}