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:
- Power: Connect the 5V and GND pins of the ESP32 and PIR sensor to the 5V and GND of the power supply.
- PIR Sensor Output: Connect the output pin of the PIR sensor to the digital input pin of the ESP32.
- Pull-up Resistor: Connect a 10k ohm resistor between the digital input pin of the ESP32 and 3.3V.
- 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:
- The PIR sensor continuously monitors the environment for changes in infrared radiation.
- When motion is detected, the sensor’s output pin goes LOW.
- 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?
Leave a Reply
You must be logged in to post a comment.