This project shows you how to automatically turn ON and OFF a Light using an Arduino with LDR or Light Dependent Resistor.
Dark is not really cool. Do you want to eliminate the darkness automatically? With this simple project, you can eliminate the darkness. You can also use this as an automatic on-off street light and an emergency lighting system.
Components Required for the Arduino with LDR Project
Arduino Uno | × 1 | Amazon |
LDR | × 1 | Amazon |
LED and Resistor Kit | × 1 | Amazon |
5V Relay Module | × 1 | Amazon |
Breadboard | × 1 | Amazon |
Jumper wires | × 2 | Amazon |
USB cable type A/B | × 1 | Amazon |
Disclosure: These are affiliate links. As an Amazon Associate, I earn from qualifying purchases.
Software
LDR
LDRs are light-dependent instruments, whose resistance decreases when light falls on them and increases in darkness. When a light dependent resistor is kept dark, it has very high resistance. It can be as high as 4.5 Ω. If the device can absorb light, its resistance is dramatically reduced. The current increases when a constant voltage is applied and the light intensity increased. The following figure shows the resistance vs. illumination curve for a particular LDR.
Feature
- Wide spectral response
- Wide ambient temperature range
- Low cost
LDR Specifications
Voltage | 100V AC or DC |
Current | 15mA |
Operating temperature range | -25°C +75°C |
Min. resistance @ 10lux | 1.8kΩ |
Max. resistance @ 10lux | 4.5kΩ |
Dark resistance after 1 sec | 0.03MΩ |
Dark resistance after 5 sec | 0.25MΩ |
Cost | Check Price |
Analog Application of LDR
- Modulated light source Automated gain control
- Colorimetric Test Equipment
- Densitometric measurement
- Dual cell electronic scales
- Rear view automatic mirror
- Automatic Gain Control – modulated light source
- Exposure Control Camera
- Dual cell Auto-Slide Focus
- Photocopy Machines – toner density
Digital Applications of LDR
- Night Light Control
- Street Light Control
- Automatic Headlight Dimmer
- Oil Burner Flame Out
For more information, you can check out the LDR Datasheet below:
Arduino with LDR Project Using LED Schematics

LDR connected to analog pin A0. In series with 10K resistor another end of the resistor will go to GND. LED connected from digital pin 2 to ground through a 220ohm resistor.
Arduino with LDR Project Using Relay Schematics

A bulb connects with a 5V relay module’s NO pin and NC pin.
Waring
This board interfaces with a high-voltage AC supply. Improper or incorrect use may result in serious injury or death. As a result, it is intended for people who are familiar with and knowledgeable about HIGH AC voltage.
Arduino with LDR Project Code
By clicking the button in the top right corner of the code field, you can copy the code. Copy and paste it into Arduino IDE.
int LDRInput=A0; //Set Analog Input A0 for LDR. int LED=2; void setup() { Serial.begin(9600); pinMode(LDRInput,INPUT); pinMode(LED,OUTPUT); } void loop() { int value=analogRead(LDRInput);//Reads the Value of LDR(light). Serial.println("LDR value is :");//Prints the value of LDR to Serial Monitor. Serial.println(value); if(value<300) { digitalWrite(LED,HIGH);//The LED turns ON in Dark. } else { digitalWrite(LED,LOW);//The LED turns OFF in Light. } }
Result
You should see your LED turn ON in dark, and OFF in light. If you cannot see the desired output, ensure the circuit has been properly assembled, and verified and uploaded the code to your board.
- Make automated Street Light system that will ON during night and OFF during day.
- You can make your own home automation using LDR sensor.