09 / 20
Light up in the dark
Use an LDR divider and a threshold to switch a desk lamp.
Run this experiment →Why it’s here
Lower the light reading across the threshold and watch the lamp turn on.
How it works
Use an LDR divider and a threshold to switch a desk lamp. Only for the divider orientation used here. Reversing the divider reverses the direction. This guided model targets the original ESP32 and Arduino-ESP32 3.x; radio, acoustics, loads and mechanics are simplified.
Try it
- Open this experiment
- Lower the light reading across the threshold and watch the lamp turn on.
Connections
- GPIO 34 — LDR + 10kΩ divider, 3V3/GND
- GPIO 2 — Lamp LED through resistor
Example sketch
void setup() {
pinMode(2, OUTPUT);
Serial.begin(115200);
analogReadResolution(12);
}
void loop() {
int light = analogRead(34);
digitalWrite(2, light < 1000);
Serial.println(light);
delay(50);
}Check your understanding
Does a lower reading always mean darker?
Show the answer
Only for the divider orientation used here. Reversing the divider reverses the direction.