This project is for smart LDR Light Sensor Circuit with Arduino.
It can feel light like human eye.
When dark come, it turn ON lamp by itself.
When light come, it turn OFF lamp automatic.
No need to press any switch.
It is small, simple and very low cost system.
Circuit Coding:
int LDR = A0;
int relay = 8;
int value = 0;
void setup() {
pinMode(relay, OUTPUT);
Serial.begin(9600);
}
void loop() {
value = analogRead(LDR);
Serial.println(value);
if (value < 300) {
digitalWrite(relay, HIGH);
} else {
digitalWrite(relay, LOW);
}
delay(500);
}
Coding Explanation:
- LDR analog pin is A0.
- Relay pin is 8.
- Arduino read analog value from A0.
- In dark it value is low.
- If value is below 300 then relay turns ON.
- Relay ON will turn ON the lamp.
- If value above 300 then relay turns OFF.
- Relay OFF will turn OFF the lamp.
Circuit Working:
Parts List:
Component | Specification | Quantity |
---|---|---|
Resistors | 100k 1/4 watt | 1 |
330Ω 1/4 watt | 1 | |
LDR standard type | 1 | |
Semiconductors | Arduino UNO Board | 1 |
Transistor BC547 | 1 | |
Relay 5V | 1 | |
Diode 1N4007 | 1 | |
LED Bulb 230V AC | 1 |
LDR and resistor make voltage divider.
LDR change resistance with light.
In dark, LDR resistance go high.
Voltage is at A0 go low.
Arduino read low voltage.
It send HIGH to transistor base.
Transistor turn ON like switch.
Big current go to relay coil.
Relay turn ON and give power to lamp.
Lamp glow.
In light, LDR resistance go low.
Voltage at A0 go high.
Arduino read high voltage.
It send LOW to transistor base.
Transistor turn OFF.
No current go to relay coil.
Relay turn OFF and cut lamp power.
Lamp goes OFF.
This is how it work automatic with light and dark.
Formula with Calculation:
LDR and resistor form a voltage divider.
Vout = (R1 / (R1 + RLDR)) * 5V
In dark, RLDR is high so Vout is low.
In light, RLDR is low so Vout is high.
Example:
Dark: RLDR = 1M = Vout = 0.45V
Light: RLDR = 10k = Vout = 4.54V
How to Build:
To build a LDR Light Sensor Circuit with Arduino follow the below steps:
- Take all parts from circuit.
- Connect LDR to 5V and GND with 100k resistor.
- Connect middle point to A0 pin.
- Connect relay to pin 8 using transistor.
- Connect other coil side to 5V.
- Connect relay common to AC supply.
- Connect relay NO to lamp.
- Join Arduino GND and relay GND.
- Connect transistor base to pin 8 through 330 ohm.
- Connect transistor emitter to GND.
- Connect transistor collector to relay coil.