HC-SR501 PIR Passive Infrared Human Motion Detector
Detect warm human movement across a 7-meter Fresnel dome cone for automatic hallway lights and security alarms.
Sense human presence silently and efficiently with the HC-SR501 Passive Infrared (PIR) motion module. Unlike active sonar or IR beams, PIR emits zero radiation—its dual pyroelectric sensor detects moving body heat through a segmented Fresnel lens, outputting clean 3.3V HIGH triggers to Arduino Uno.
Key Learning Objectives & Robotics Concepts
By building and programming this project, you will master the following core engineering skills:
Power Architecture & Voltage Staging
5V / 3.3V Regulated PowerThe HC-SR501 runs directly on 5V (regulated internally to 3.3V by its onboard HT7133 LDO) drawing only ~65µA quiescent current—ideal for battery-powered security nodes. Allow 30–45 seconds of still room warm-up after power-on so the pyroelectric element learns ambient thermal background without false triggers.
Bill of Materials (BOM) & Hardware Components
| Component | Specifications & Alternative | Qty | Approx Cost |
|---|---|---|---|
| Arduino Uno R3 | ATmega328P @ 16MHz | 1 | $8.00 |
| HC-SR501 PIR Motion Sensor | 3–7m range, 110° cone, delay & sensitivity trimpots | 1 | $2.00 |
| 5mm LED + 220Ω Resistor | Motion active indicator | 1 | $0.15 |
| 5V Piezo Buzzer (Optional) | Audible entry chime on D9 | 1 | $0.80 |
Electrical & System Architecture
Connect HC-SR501 VCC to 5V, GND to GND, and OUT (middle pin) to Arduino D2. Wire an intruder alert LED (+220Ω) to D8 and optional piezo buzzer to D9.
Autonomous Behavior & Finite State Machine (FSM)
Deterministic Arduino loop handling HC-SR501 Pyroelectric Motion Sensor acquisition, filtering, and real-time output updates.
Step-by-Step Physical Assembly & Wiring Tutorial
Follow each of the 5 sequential milestone stages with technical photos, wiring checks, and pre-flight tests.
Pop Off Fresnel Dome to Check Pin Labels
Gently lift the white plastic hemisphere to read VCC, OUT, and GND printed right beside the 3-pin header.
- Pull the white dome straight up (it snaps right back on!).
- Confirm outer pins VCC and GND plus middle OUT pin, then snap the dome securely back on.
- Turn the Time-Delay pot (Tx) fully counter-clockwise (~3 seconds hold) for snappy bench testing.
Wire PIR OUT to D2 & Alert Outputs to D8/D9
Connect power, ground, sensor signal, LED, and optional piezo chime.
- Connect HC-SR501 VCC → 5V, GND → GND, and OUT → D2.
- Wire Red LED (+220Ω) to D8 and optional Piezo Buzzer to D9.
- Point the white dome into open room space away from sunlit windows or heaters.
Wait Out the 30-Second Pyroelectric Warm-Up
Upload the motion monitor and sit still briefly while the sensor establishes ambient IR baseline.
- Upload the production sketch below and open Serial Monitor at 115200 baud.
- Watch the 30-second stabilization countdown complete.
- Confirm status transitions cleanly to "ARMED - Awaiting Motion".
Test Hand Wave & Walk-By Detection
Wave your warm hand 50cm in front of the Fresnel dome and verify immediate detection.
- Wave across the field of view → D8 LED lights instantly and Serial logs Motion Event #1.
- Hold still for ~4 seconds until the Tx timer expires and D8 turns OFF.
- Observe the 2.5-second hardware blocking window before HC-SR501 re-triggers.
Calibrate Range & Delay for Real Deployment
Fine-tune Sx (range) and Tx (hold duration) for your room geometry.
- Test walking across the room at 2m and 4m distance.
- Notice PIR detects lateral (side-to-side) motion across Fresnel zones much faster than straight-on approach.
- Verify zero false triggers during 60 seconds of an empty room.
Subsystem Benchtop Verification Scripts
Test each hardware subsystem independently before deploying the full autonomous firmware.
1Bench Diagnostic: HC-SR501 Pyroelectric Motion Sensor Hardware Check
Subsystem DiagnosticMinimal standalone sketch to verify pin wiring and signal response for HC-SR501 Pyroelectric Motion Sensor before running the full project firmware.
// Diagnostic: Raw HC-SR501 Motion Pin Readout
void setup() { pinMode(2, INPUT); Serial.begin(115200); }
void loop() { Serial.println(digitalRead(2) ? "MOTION (HIGH)" : "QUIET (LOW)"); delay(250); }Complete Production Firmware
Full working C++ source code with pin mappings, non-blocking timers, and FSM avoidance routines.
/**
* Project 30: HC-SR501 PIR Passive Infrared Motion Security Monitor
* Board: Arduino Uno R3 | Pins: D2 (PIR OUT), D8 (LED), D9 (Chime Buzzer)
*/
const uint8_t PIR_PIN = 2;
const uint8_t ALERT_LED = 8;
const uint8_t BUZZER_PIN = 9;
const uint8_t WARMUP_SEC = 30;
bool motionActive = false;
unsigned long eventCount = 0;
void setup() {
Serial.begin(115200);
pinMode(PIR_PIN, INPUT);
pinMode(ALERT_LED, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
Serial.println(F("PIR Sensor Stabilizing (30s)..."));
for (int s = WARMUP_SEC; s > 0; s--) {
digitalWrite(ALERT_LED, s % 2);
if (s % 5 == 0 || s <= 3) { Serial.print(F("Warmup: ")); Serial.print(s); Serial.println('s'); }
delay(1000);
}
digitalWrite(ALERT_LED, LOW);
Serial.println(F("PIR ARMED - Monitoring for human motion..."));
}
void loop() {
bool detected = (digitalRead(PIR_PIN) == HIGH);
if (detected && !motionActive) {
motionActive = true;
eventCount++;
digitalWrite(ALERT_LED, HIGH);
tone(BUZZER_PIN, 1800, 140);
Serial.print(F("[ALERT] Motion Event #"));
Serial.print(eventCount);
Serial.print(F(" at t=")); Serial.print(millis() / 1000); Serial.println('s');
} else if (!detected && motionActive) {
motionActive = false;
digitalWrite(ALERT_LED, LOW);
Serial.println(F("[CLEAR] Motion ended - re-armed."));
}
delay(40);
}Firmware Architecture Explanation:
- Executes a clean 30-second pyroelectric thermal settle phase with blinking status feedback.
- Uses edge-state tracking (motionActive) so the buzzer chirps once per entry rather than shrieking nonstop.
- Logs numbered intrusion events with uptime timestamps over 115200 baud Serial.
Operational Verification & Pin State Matrix
Input Signal vs. System Output Truth Table:
| Input / State | Pin / Signal | Detected Condition | Expected Output |
|---|---|---|---|
| Warm Body Moves | D2 = HIGH (3.3V) | IR Zone Change | D8 LED ON + Entry Chime |
| Room Still | D2 = LOW (0V) | Thermal Equilibrium | D8 LED OFF (Armed) |
Engineering Troubleshooting Matrix
| Problem | Likely Cause | Diagnostic Check | Engineering Solution |
|---|---|---|---|
| Stays stuck HIGH for several minutes | Time-Delay trimpot (Tx) turned clockwise near 5-minute max | Inspect Tx potentiometer position | Turn Tx fully counter-clockwise for ~3-second reset time. |
| False triggers in empty room | Aimed at sunny window, space heater, or Wi-Fi/RF noise | Cover dome with cardboard box to confirm electrical vs thermal trigger | Relocate away from drafts/sunlight and lower Sx slightly. |
| Never detects motion | VCC/GND swapped or plastic dome missing | Verify 5V on VCC pin under dome silkscreen | Confirm VCC/OUT/GND orientation and keep white Fresnel dome snapped on. |
Engineering Challenges & Upgrades
Take your build to the next level with these progressive engineering upgrades:
Keep an LED lit for 30 seconds after the last detected movement, resetting the timer on every new motion.
Pair with DS3231 RTC (Project 18) to record exact HH:MM:SS timestamps for every visitor.
Combine with LDR (Project 13) so motion activates the light ONLY when the room is dark!