DHT sensor library
Adafruit Unified Sensor

2.Develop an ESP32 program to read light intensity using an LDR module and display the readings using serial communication.

sketch.ino:


#define LDR_PIN 34

void setup() {
  Serial.begin(115200);

  Serial.println("LDR Sensor Started");
}

void loop() {
  int lightValue = analogRead(LDR_PIN);

  Serial.print("Light Intensity: ");
  Serial.println(lightValue);

  if (lightValue < 1500) {
    Serial.println("Low Light");
  }
  else if (lightValue < 3000) {
    Serial.println("Medium Light");
  }
  else {
    Serial.println("High Light");
  }

  Serial.println("--------------------");

  delay(1000);
}


diagram.json:


{
  "version": 1,
  "author": "",
  "editor": "wokwi",
  "parts": [
    {
      "type": "board-esp32-devkit-c-v4",
      "id": "esp",
      "top": 0,
      "left": 0,
      "attrs": {}
    },
    {
      "type": "wokwi-photoresistor-sensor",
      "id": "ldr",
      "top": -20,
      "left": 200,
      "attrs": {}
    }
  ],
  "connections": [
    ["esp:TX", "$serialMonitor:RX", "", []],
    ["esp:RX", "$serialMonitor:TX", "", []],
    ["ldr:VCC", "esp:3V3", "red", []],
    ["ldr:GND", "esp:GND.1", "black", []],
    ["ldr:AO", "esp:34", "green", []]
  ],
  "dependencies": {}
}