An LED that turns on automatically when the room goes dark — your first taste of analog sensing and automation.
An LDR (Light Dependent Resistor) changes its resistance based on light levels. In the dark, resistance goes high; in bright light, resistance drops. Arduino reads this as an analog voltage.
What you'll learn: analogRead(), voltage dividers, threshold comparison, and automatic control logic.
Estimated time: 25–35 minutes. Difficulty: ⭐ Beginner-friendly.
| Component | Specification | Qty | Notes |
|---|---|---|---|
| Arduino Uno R3 | 5V | 1 | |
| LDR (Photoresistor) | GL5516 or similar | 1 | |
| Resistor | 10kΩ | 1 | Voltage divider partner |
| LED | 5mm | 1 | Output indicator |
| Resistor | 220Ω | 1 | For LED |
| Breadboard + Wires | Half-size | 1 |
threshold variable to match your room.// Night Lamp — Volt X
const int ldrPin = A0;
const int ledPin = 9;
int threshold = 500; // Adjust for your lighting
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int ldrValue = analogRead(ldrPin);
Serial.println(ldrValue);
if (ldrValue < threshold) {
digitalWrite(ledPin, HIGH); // Dark — turn on
} else {
digitalWrite(ledPin, LOW); // Bright — turn off
}
delay(100);
}Sign in to leave a review
No reviews yet. Be the first to share your experience!