Article & guide
Read the full article
## Turn changing light into a number This project uses a light-dependent resistor and a fixed resistor as a voltage divider. The ESP32 reads the junction and prints a relative light-level signal. You will compare readings in shade, normal room light and near a lamp, then decide whether those differences are useful for your own application. ## Components - Classic ESP32-WROOM-32 development board — 1 - Light-dependent resistor (LDR) — 1 - 10 kilohm resistor — 1 - Breadboard, jumper wires and USB data cable ## Understand the divider Wire 3.3 V through the LDR to the measurement junction, then through the 10 kilohm resistor to GND. Connect the junction to GPIO34. As the LDR resistance changes, so does the junction voltage. On this classic ESP32, GPIO34 is an input-only ADC1 pin; other ESP32 families have different pin maps. The displayed ADC value is a raw, relative reading. It is not lux and should not be presented as a calibrated voltage. ADC behaviour, the LDR response and the light source all affect the result. Keep the junction within the input limits for your exact board and configured ADC range. Never feed it 5 V. ## Compare before you automate Write down ten readings for each condition without moving the circuit. Compare the spread, not only one number. If room light and shade overlap, improve the sensor placement or reconsider the divider before choosing a threshold. A desk lamp also changes heat and angle, so record the distance and allow conditions to settle. If you later trigger an output, use separate turn-on and turn-off thresholds to reduce rapid switching near the boundary. This starter version only reads and prints; it does not control a mains lamp. ## References ADC API: https://docs.espressif.com/projects/arduino-esp32/en/latest/api/adc.html Classic ESP32 GPIO map: https://docs.espressif.com/projects/esp-idf/en/v6.0/esp32/api-reference/peripherals/gpio.html ## Before you begin This is an educational build plan for a classic ESP32-WROOM-32 development board, not a report of a physically tested prototype. Check the pin labels and documentation for your exact board. Disconnect USB before changing wiring. Keep the circuit at USB/3.3 V levels; do not connect mains power. The AI-generated cover is illustrative and is not a wiring diagram.
1. Assemble the divider
Disconnect USB. Connect 3.3 V → LDR → junction → 10 kilohm resistor → GND. Run a jumper from the junction to GPIO34. Inspect for a short between the supply rails.
2. Read the input
Upload and open Serial Monitor at 115200 baud: ```cpp const int lightPin = 34; void setup() { Serial.begin(115200); analogReadResolution(12); } void loop() { int raw = analogRead(lightPin); Serial.println(raw); delay(250); } ``` The delay is acceptable here because this single-purpose starter has no other timed task.
3. Run three comparisons
Observe shade, room light and a lamp at a fixed distance. Note minimum and maximum readings for each. If readings stay near a limit, recheck wiring and consult the ADC input/attenuation documentation before interpreting them.
4. Write the conclusion
Describe what the sensor can distinguish in your setup, the conditions tested and what remains uncalibrated. Do not label the graph with lux unless you have a defensible calibration process.
