ArrowtronElectronics Store
Free shipping over ₹999
100% genuine components
Dispatch in 1–2 days
Secure payments · UPI, Cards

Automatic Night Lamp with LDR: Lights On at Dusk

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.

Beginner~30 minutes6 components

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

ComponentQtyPrice
Arduino Nano ATmega328P Compatible Board1₹149
LDR 5mm1₹89
10K Ohm 1/4W1₹249
5V Single Channel Relay Module for Arduino1₹49
400 Point Breadboard1₹299
Jumper Wires MM1₹299
Total₹1,134

Step-by-step guide

  1. Build the divider: 5V → LDR → A0, and from A0 a 10K resistor to GND.
  2. Wire the relay module: VCC to 5V, GND to GND, IN to D7.
  3. 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).
  4. Upload the sketch and watch the Serial Monitor: cover the LDR and note the “dark” value, then the normal room value.
  5. 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
Scroll to Top