DHT sensor library
Adafruit Unified Sensor

3.Develop an ESP32 program to detect motion using a PIR sensor and display the detection status using serial communication.

sketch.ino:


#define PIR_PIN 4

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

  pinMode(PIR_PIN, INPUT);

  Serial.println("PIR Motion Detection Started");
}

void loop() {
  int motion = digitalRead(PIR_PIN);

  if (motion == HIGH) {
    Serial.println("Motion Detected!");
  }
  else {
    Serial.println("No Motion");
  }

  delay(1000);
}


diagram.json:


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