Complete guide to passive infrared motion detection sensors
PIR (Passive Infrared) sensors detect motion by measuring infrared light radiating from objects in their field of view, typically used to detect human movement.
| Operating Voltage | 5V-20V DC |
| Output Signal | Digital (3.3V TTL) |
| Detection Range | Up to 7 meters |
| Detection Angle | 110° |
| Time Delay Adjust | 5s-300s |
| Sensitivity Adjust | 3m-7m |
// Basic PIR Motion Sensor Example
#define PIR_PIN 2
void setup() {
Serial.begin(9600);
pinMode(PIR_PIN, INPUT);
Serial.println("PIR Sensor Warming Up (30-60 seconds)");
delay(50000); // Warm-up delay
Serial.println("PIR Sensor Ready");
}
void loop() {
if(digitalRead(PIR_PIN) == HIGH) {
Serial.println("Motion detected!");
delay(1000); // Avoid multiple detections
}
}
// PIR with visual/audio feedback
#define PIR_PIN 2
#define LED_PIN 3
#define BUZZER_PIN 4
void setup() {
pinMode(PIR_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
Serial.begin(9600);
delay(60000); // 60 second warm-up
}
void loop() {
if(digitalRead(PIR_PIN) == HIGH) {
triggerAlarm();
}
}
void triggerAlarm() {
Serial.println("ALERT: Motion detected!");
// Flash LED and sound buzzer
for(int i = 0; i < 5; i++) {
digitalWrite(LED_PIN, HIGH);
tone(BUZZER_PIN, 1000);
delay(200);
digitalWrite(LED_PIN, LOW);
noTone(BUZZER_PIN);
delay(200);
}
delay(5000); // 5 second cooldown
}
// PIR with WiFi notification
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#define PIR_PIN D2
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";
WiFiServer server(80);
void setup() {
Serial.begin(115200);
pinMode(PIR_PIN, INPUT);
WiFi.begin(ssid, password);
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
delay(60000); // PIR warm-up
}
void loop() {
if(digitalRead(PIR_PIN) == HIGH) {
sendNotification();
delay(10000); // 10 second delay between detections
}
}
void sendNotification() {
WiFiClient client;
if(client.connect("maker.ifttt.com", 80)) {
String url = "/trigger/motion_detected/with/key/YOUR_KEY";
client.print("GET " + url + " HTTP/1.1\r\n" +
"Host: maker.ifttt.com\r\n" +
"Connection: close\r\n\r\n");
Serial.println("Notification sent");
}
}
Automatic light that turns on when motion is detected.
Sound alarm and send notification when motion detected.
Track when your pet enters/leaves certain areas.
Turn off devices when no motion is detected.
Count people entering/exiting a space.
Trigger camera when animal motion is detected.
// Components needed:
- Multiple PIR sensors
- ESP32-CAM
- Magnetic door/window sensors
- Siren
- Keypad
- OLED display
- Cloud service
// Features:
1. Multi-zone motion detection
2. Live video capture on alarm
3. Mobile notifications
4. Armed/disarmed states
5. Entry delay
6. Battery backup
// Implementation Tips:
- Use deep sleep for battery operation
- Implement zone-specific responses
- Add two-stage arming (stay/away)
- Create custom alert patterns
- Add remote configuration
- Implement event logging
| Mistake | Consequence | Solution |
|---|---|---|
| No warm-up time | False alarms | Always allow 30-60s stabilization |
| Pointing at heat sources | False triggers | Avoid vents, heaters, windows |
| Improper mounting height | Reduced detection | Mount 2-3m high |
| Too short time delay | Constant triggering | Set appropriate delay (30s+) |
| Dirty lens | Reduced sensitivity | Clean regularly |