Compoden
Published

ESP32 Light Meter with an LDR Module (Soldr Draft)

A learning light meter: ESP32 reads an LDR module on GPIO34/35 and streams raw values over Serial.

BeginnerFull instructions provided21
ESP32 Light Meter with an LDR Module (Soldr Draft)

Things used in this project

Hardware components

ESP32
Espressif ESP32
×1

Story

Read more

Code

esp32_ldr_light_meter.ino

Arduino
// ESP32 + LDR sensor module light meter
// Prompt used in Soldr: "write a code to interface an ldr sensor module with an esp32"
// Pins match the Soldr draft (GPIO34 analog AO, GPIO35 digital DO).
// Module: VCC, GND, AO, DO. Many modules: DO HIGH = dark (threshold pot).

const int AO_PIN = 34;  // ADC1, input-only
const int DO_PIN = 35;  // ADC1, input-only OK as digital read

void setup() {
  Serial.begin(115200);
  pinMode(DO_PIN, INPUT);
  analogReadResolution(12);  // 0..4095 on ESP32
}

void loop() {
  int ldr_raw = analogRead(AO_PIN);
  int digital = digitalRead(DO_PIN);
  Serial.print("[DATA] ldr_raw=");
  Serial.print(ldr_raw);
  Serial.print(" digital=");
  Serial.println(digital);
  delay(500);
}

Credits

Compoden
3 projects • 1 follower
Compoden is an AI-powered electronics store for makers, students, and builders in India.

Comments