Simple Darkness Detector Smart Switch
Posted on June 17, 2025 (Last modified on June 22, 2025) • 3 min read • 532 wordsDISCLAIMER: This device may turn on the light when you’re near it, since it might sense the darkness in your future.
They say necessity is the mother of invention. In my case, it was laziness and the sheer refusal to get up and switch off the room light manually.
So I built this: a light-detecting Arduino switch that automatically turns on/off a room bulb based on ambient darkness. The soul of this setup? A Light Dependent Resistor (LDR), a servo, and some classic jugaad.
The logic is simple:
LDR detects darkness → Arduino sends signal → Servo physically toggles the bulb switch.
Yup. No fancy relays or Bluetooth modules — the servo’s wing literally presses the physical switch like a tiny robot butler with no salary and zero rights (uhm).
Here’s the basic sketch I used:
#include <Servo.h>
Servo s;
#define ldrpin A0
#define spin 9
void setup() {
pinMode(ldrpin, INPUT);
s.attach(spin);
s.write(0); // Servo at rest
Serial.begin(9600);
}
void loop() {
delay(100);
int x = analogRead(ldrpin);
Serial.println(x); // Used for calibration
if (x >= 980) { // It’s dark enough
s.write(100);
delay(500);
s.write(0);
delay(400);
}
}Key Insight: The darkness threshold is 980 (out of 1023). Tweak it depending on your room’s lighting.
There’s a reason engineers love duct tape. I went a step further — double-sided tape.
And… all set, you think? Nope. Picture abhi baaki hai, mere dost!
Initially, everything worked smoothly — the servo clicked, the light responded, and I felt like Tony Stark (minus the billions and Pepper Potts).
But after a few minutes:
Panic? A bit. But then I did what every engineer does — blamed the hardware.
Spoiler: the board wasn’t dead.
The servo was pulling too much current, and the Arduino’s onboard 5V regulator was basically screaming silently. It couldn’t keep up with the spikes.
What fixed it?
Moral: Don’t throw more power at the problem. Throw better logic.
I didn’t build a smart home system.
I didn’t write an app.
I just made a cheap Arduino servo physically press a light switch when the room gets dark.
And that’s exactly why it’s awesome.
If you liked this project, feel free to recreate it, tweak it, or judge it silently.
If you didn’t like it — go build something better. That’s the whole point.
Until then, this was me vs the light switch.
Conclusion: I won.