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

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.

Step 1: Things You Need

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


Step 2: Some Basics of LDR

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.

Step 3: Circuit

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.

Step 4: Coding Part

Please copy the below code and upload it to Arduino Uno :

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

Step 5: Working Demo

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.