A lamp that switches itself on when the room gets dark and off again at dawn — the humble LDR makes it a 30-minute build.
What you’ll build
The LDR’s resistance rises in darkness. Wired as a voltage divider with a 10K resistor, it feeds an analog value to the Nano, which flips a relay when the light level crosses your threshold — with hysteresis so the lamp never flickers at twilight.
Components you’ll need
| Component | Qty | Price |
|---|---|---|
| Arduino Nano ATmega328P Compatible Board | 1 | ₹149 |
| LDR 5mm | 1 | ₹89 |
| 10K Ohm 1/4W | 1 | ₹249 |
| 5V Single Channel Relay Module for Arduino | 1 | ₹49 |
| 400 Point Breadboard | 1 | ₹299 |
| Jumper Wires MM | 1 | ₹299 |
| Total | ₹1,134 |
Step-by-step guide
- Build the divider: 5V → LDR → A0, and from A0 a 10K resistor to GND.
- Wire the relay module: VCC to 5V, GND to GND, IN to D7.
- Connect your lamp through the relay’s COM and NO terminals (a 5V LED strip is the safe way to start; leave mains lamps to qualified hands).
- Upload the sketch and watch the Serial Monitor: cover the LDR and note the “dark” value, then the normal room value.
- Set DARK_ON and LIGHT_OFF between those numbers and re-upload.
The code
Two thresholds (on at dark, off only when clearly bright) give clean switching with no twilight chatter.
const int ldr=A0, relay=7;
const int DARK_ON=300, LIGHT_OFF=450; // calibrate for your room
bool lampOn=false;
void setup(){ pinMode(relay,OUTPUT); digitalWrite(relay,HIGH); Serial.begin(9600); }
void loop(){
int light = analogRead(ldr);
Serial.println(light);
if(!lampOn && light < DARK_ON){ lampOn=true; digitalWrite(relay,LOW); }
if( lampOn && light > LIGHT_OFF){ lampOn=false; digitalWrite(relay,HIGH); }
delay(500);
}Build this project
Add all 6 required components to your cart in one click — total ₹1,134.
Add all components to cart