Light Sensor With Arduino | Making a Light Sensor Using LDR | Light Glowing in Dark Using Arduino | Light Dependent Resistor Tutorial With Arduino

by Utsource in Circuits > Arduino

2507 Views, 2 Favorites, 0 Comments

Light Sensor With Arduino | Making a Light Sensor Using LDR | Light Glowing in Dark Using Arduino | Light Dependent Resistor Tutorial With Arduino

Screenshot_20190918-193557__01.jpg

Having a Light sensor is always very amazing thing so in this project we will be making a light sensor using LDR and LDR is basically a light dependent resistor which can be used as a light sensor because its resistance depends how much light is falling on it and depends upon how much intensity of light is there it varies its resistance.

So basically if LRD will not get light it will sense it as dark and vice versa bright. So if it is dark the LED will be turned ON and if it is not dark (bright) the LED will remain OFF.

Things You Need

Km5Zu-2RIncAUweU7uG7IhyWPySZ0SqIgAI0-vk9w7767_IkthCPCcsirj2GGmXF4IdQDg8UVpHVLVM6CXnzFsG1hnAdSkK7BIhIOtEldXoZiDsvzsPo-6o0rD6Mda7UyOE=w456-h323-nc.png
images(35).jpg
images(36).jpg
images(37).jpg

For this instructables we will need following things :

Arduino UNO

LDR (Light Dependent Resistor)

Resistor (100k-1;330ohm-1) (instead of 330 ohm you can go any value from 330ohm to 1000ohm)

LED - 1

Connecting wires

Breadboard

Some Basics of LDR

images(35).jpg
An LDR is a component that has a (variable) resistance that changes with the light intensity that falls upon it. This allows them to be used in light sensing circuits.

The most common type of LDR has a resistance that falls with an increase in the light intensity falling upon the device. The resistance of an LDR may typically have the following resistances:

Daylight = 700Ω
Dark = 100kΩ ( these values were for my LDR , your LDR resistance could be different.

Circuit

Arduino-Light-Sensor-Circuit-diagram-using-LDR_0(1).png
As per the circuit diagram, we have made a voltage divider circuit 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.
Intensity of light ↓ - Resistance↑ - Voltage at analog pin↓ - Light turns ON
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.

Coding Part

Screenshot_20190918-192953__01.jpg
Please copy the below code and upload it to Arduino Uno :



int LED = 9;
int LDR = A0;
void setup()
{
Serial.begin(9600);
pinMode(LED, OUTPUT);
pinMode(LDR, INPUT);
}
void loop() {
int LDRValue = analogRead(LDR);
Serial.print("sensor = ");
Serial.print(LDRValue);
if (LDRValue <=700)
{
digitalWrite(LED, HIGH);
Serial.println("It's Dark Outside; Lights status: ON");
}
else
{
digitalWrite(LED, LOW);
Serial.println("It's Bright Outside; Lights status: OFF");
}
}

Working Demo

Screenshot_20190918-194215__01.jpg
Screenshot_20190918-194227__01.jpg
So after uploading the code, we can see if make the sensor go dark ( we can cover it or we can put it in dark) its resistance will increase and that will be read by arduino and according to if condition LED will turn ON when its is dark because the resistance is increasing of LDR & Arduino is reading that value and that value is triggering a if condition which is turning ON the LEDA and vice versa for LED turning OFF.