Back to Tutorial
esp32_with_pir_sensor

ESP32 and PIR Sensor: A Simple Motion Detection System

Introduction

The ESP32, a powerful microcontroller, coupled with a Passive Infrared (PIR) sensor, can be used to create a versatile motion detection system. This combination allows for a wide range of applications, from home automation to security systems.

Understanding the Components

  • ESP32: A versatile microcontroller with Wi-Fi and Bluetooth capabilities, making it ideal for IoT projects.
  • PIR Sensor: Detects motion by sensing changes in infrared radiation emitted by moving objects.

Required Components:

  • ESP32 Development Board
  • PIR Sensor Module
  • Resistors (10k and 220 ohms)
  • Jumper Wires
  • Breadboard
  • Power Supply (5V DC)

Circuit Connection:

  1. Power: Connect the 5V and GND pins of the ESP32 and PIR sensor to the 5V and GND of the power supply.
  2. PIR Sensor Output: Connect the output pin of the PIR sensor to the digital input pin of the ESP32.
  3. Pull-up Resistor: Connect a 10k ohm resistor between the digital input pin of the ESP32 and 3.3V.
  4. LED (Optional): Connect an LED and a 220 ohm resistor to the same digital output pin of the ESP32 to indicate motion detection.

Code Implementation (Arduino IDE)

C++

const int PIR_PIN = 34; // Digital pin connected to PIR sensor output

void setup() {
  pinMode(PIR_PIN, INPUT_PULLUP);
  Serial.begin(115200);
}

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

  if (val == LOW) {
    Serial.println("Motion Detected!");
    // You can add actions here, like turning on lights, sending notifications, etc.
  } else {
    Serial.println("No Motion");
  }

  delay(100);
}

How it Works:

  1. The PIR sensor continuously monitors the environment for changes in infrared radiation.
  2. When motion is detected, the sensor’s output pin goes LOW.
  3. The ESP32 reads the input pin and triggers the appropriate action, such as turning on a light or sending a notification.

Applications:

  • Home Automation: Automatically turning on lights when motion is detected.
  • Security Systems: Triggering alarms or sending alerts when intruders are detected.
  • Pet Monitoring: Monitoring pet activity and sending notifications if unusual behavior is detected.
  • Energy Efficiency: Turning off lights or appliances when a room is unoccupied.

By combining the power of the ESP32 and the sensitivity of the PIR sensor, you can create a wide range of innovative motion detection projects.

Would you like to delve deeper into specific applications or explore advanced features of the ESP32 and PIR sensor?

Share this post

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Tutorial