The photoresistor forms a voltage divider with a fixed resistor, and the board reads the midpoint on its analog pin. Below a threshold you pick, the relay closes and a lamp comes on. Note the relay module is low-level trigger, so the output pin must go LOW to switch it — a detail that catches people out. Add a delay before switching so a passing shadow does not flick the lamp on and off.
Every item is in the kit — nothing extra to buy.
All 24 parts in one box, with this project and 15 more to build from them.
One of each part. Packs (resistor assortment, jumper wires) already hold more than a single build needs. Backorder parts ship once they arrive — the kit above has every part boxed today. Delivery is free on orders AED 150.00+.
Written for the board in the kit. Copy it into the Arduino IDE; change the pin numbers if you wire it differently.
/*
03 — Light-triggered night light
Board: NodeMCU V3 ESP8266 development board. Parts: photoresistor, relay module, 10 kΩ resistor.
Wiring:
Photoresistor: one leg -> 3V3, other leg -> A0 AND -> 10 kΩ -> GND
(a voltage divider: more light = higher reading)
Relay module: VCC -> VIN (5 V), GND -> GND, IN -> D1
Low-level trigger: the pin must go LOW to switch the relay ON.
Lamp: through the relay's COM and NO contacts. Low-voltage lamps only
on the bench; anything mains needs an electrician-grade enclosure.
The delay before switching stops a passing shadow flicking the lamp.
*/
const int LDR_PIN = A0;
const int RELAY_PIN = D1;
const int DARK_BELOW = 300; // pick by watching the Serial Monitor in your room
const int LIGHT_ABOVE = 450; // higher than DARK_BELOW = hysteresis, no chatter
const unsigned long HOLD_MS = 3000; // must stay dark/light this long before switching
bool lampOn = false;
unsigned long since = 0;
bool pendingDark = false;
void setup() {
Serial.begin(115200);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, HIGH); // HIGH = relay OFF on a low-level-trigger module
}
void loop() {
int light = analogRead(LDR_PIN); // 0..1023 on the ESP8266
bool wantOn = lampOn ? (light < LIGHT_ABOVE) : (light < DARK_BELOW);
if (wantOn != pendingDark) { pendingDark = wantOn; since = millis(); }
if (wantOn != lampOn && millis() - since > HOLD_MS) {
lampOn = wantOn;
digitalWrite(RELAY_PIN, lampOn ? LOW : HIGH);
Serial.println(lampOn ? "Lamp ON" : "Lamp OFF");
}
Serial.print("light="); Serial.print(light);
Serial.println(lampOn ? " lamp on" : " lamp off");
delay(200);
}
Mount the sensor above a container and measure the air gap to the surface — less gap means more contents. Invert the reading into a percentage, alert when it hits full o…
Both boards carry an onboard LED, so your first sketch needs no wiring at all — blink it, change the timing, watch it obey. Then add a tactile switch to a GPIO pin with…
The DHT11 sends both temperature and humidity down a single data wire using its own timing protocol, so a library does the decoding for you. Wire three pins, install the…