Submit

09 / 20

Light up in the dark

Use an LDR divider and a threshold to switch a desk lamp.

Run this experiment →
ESP32 teaching illustration with module, GPIO headers and lesson components

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

  1. Open this experiment
  2. 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.

Sources

Arduino-ESP32 ↗ · GPIO reference ↗

MAKE A THOUGHTFUL CHOICE

Your shortlist, side by side.

Pricing models are indicative. Check each official website for current plans and limits.