Arduino Light Sensor
A Light Sensor is a device that detects light. It generates an output signal that is proportional to the intensity of light.
Supplies
Hardware Components
Arduino Uno
LDR
Register 100k ohm
Relay Module
Red LED
Connecting wires
Software
Arduino IDE
About This Project
We all want our home devices to be controlled automatically depends on some conditions and that's called Smart Home automation.
This project is about the light turns ON automatically when it is dark outside and turns off when it gets bright. For this, we require a light sensor to recognize the light condition and some circuitry to manage the light sensor. In this circuit, we are making a Light Sensor using LDR with Arduino to manage a bulb as per the light condition of the room or outside area.
Learn more about IoT Devices with the help of the IoT Course.
LDR (Light Dependent Resistor) :
LDRs are composed of semiconductor materials 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 operates on the principle of “Photo Conductivity”. Now what this principle says is, whenever light falls on the surface of the LDR the conductance of the element improves or in other words, the resistance of the LDR falls when the light falls on the surface of the LDR.
Working of LDR controlled LED using Arduino:
As per the circuit diagram, we have designed a voltage divider circuit using LDR and 100k resistor. The voltage divider output is supplied to the analog pin of the Arduino. The analog pin senses the voltage and gives some analog value to Arduino.
The analog value modifies according to the resistance of LDR. So, as the light falls on the LDR the resistance of it gets minimized and hence the voltage value improves. The intensity of light ↓ - Resistance↑ - Voltage at the analog pin↓ - Light turns ON As per the Arduino code, if the analog value drops below 700 we recognize it as dark and the light turns ON. If the value comes above 700 we recognize it as bright and the light turns OFF.
Run a 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");
}
}