PIR = Passive Infrared Sensor
A PIR sensor detects motion by measuring changes in infrared radiation.
Every warm object (like humans and animals) emits infrared (IR) radiation.
PIR sensors don’t emit anything; they only detect IR changes. That’s why they are called passive.
The PIR sensor has two slots made of pyroelectric sensors.
When a human or animal moves in front of the sensor, one slot sees more IR radiation than the other.
This sudden change causes a voltage difference and the sensor outputs HIGH (3.3V or 5V) for a short time.
So in short:
π No motion → LOW output
π Motion detected → HIGH output
| Component | Quantity |
|---|---|
| ESP32 board | 1 |
| HC-SR501 PIR sensor | 1 |
| Jumper wires | few |
| Breadboard (optional) | 1 |
| LED + 220Ω resistor (optional) | 1 |
| Pin | Description |
|---|---|
| VCC | Power supply (3.3V or 5V) |
| OUT | Digital output (HIGH when motion detected) |
| GND | Ground |
There are two knobs on the sensor:
Time Delay – Adjust how long output stays HIGH after motion.
Sensitivity – Adjust how far motion can be detected (typically up to 6 meters).
| PIR Sensor Pin | ESP32 Pin |
|---|---|
| VCC | 3.3V or 5V |
| GND | GND |
| OUT | GPIO 14 (any digital pin) |
If you’re using an LED for indication, connect:
LED anode (+) → GPIO 2 (or any other GPIO)
LED cathode (–) → 220Ω resistor → GND
Upload the code to ESP32.
Open Serial Monitor at 115200 baud rate.
Move your hand in front of the PIR sensor — you'll see Motion Detected!
Stay still — you'll see No Motion.
LED should turn ON/OFF according to motion.
| Project Idea | Description |
|---|---|
| π Security Alarm | Trigger buzzer or send message when motion detected |
| π‘ Smart Lighting | Turn on lights only when someone is in the room |
| π§ IoT Notification | Use WiFi to send alerts to mobile or Telegram bot |
| π Sleep Monitor | Turn off fan/light if no motion detected for 1 hour |
| πΆ Pet Detector | Know when your pet enters a room |
Q1: Can PIR detect behind walls?
β‘οΈ No, PIR only detects line-of-sight IR radiation. It cannot see through walls or glass.
Q2: Can PIR detect small objects?
β‘οΈ It depends on heat and movement. It’s good at detecting humans and large animals.
Q3: Is PIR sensor affected by sunlight or heat?
β‘οΈ Yes, strong sunlight or high ambient temperature can affect sensitivity.
HOW TO OPERATE
π Upload this using Arduino IDE. Make sure to select the right Board: ESP32 Dev Module and COM port.