MyRoboPathOpen Robotics Lab
Arduino Uno #30 of 35
Est. 0.5 Hours
Budget: $2 - $4
Beginner

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.

Arduino Uno R3HC-SR501 PIRPyroelectric SensingFresnel OpticsMotion Security
HC-SR501 PIR Passive Infrared Human Motion Detector Blueprint
HC-SR501 PIR Passive Infrared Human Motion DetectorCAD Blueprint

Key Learning Objectives & Robotics Concepts

By building and programming this project, you will master the following core engineering skills:

1Understand dual-element differential pyroelectric sensing and why stationary warm objects stop triggering.
2Pop off the white Fresnel dome briefly to verify exact VCC / OUT / GND silkscreen labels underneath.
3Tune the two orange potentiometers: Sensitivity (Sx, 3–7m) and Hold Time (Tx, 3s–300s).
4Distinguish Repeatable (H) vs Non-Repeatable (L) trigger jumper modes.

Power Architecture & Voltage Staging

5V / 3.3V Regulated Power

The 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.

HC-SR501 PIR Passive Infrared Human Motion Detector Power Architecture Schematic
Figure: Regulated Arduino Uno supply rails, current budget, and component protection.Power Schematic

Bill of Materials (BOM) & Hardware Components

Bill of Materials for HC-SR501 PIR Passive Infrared Human Motion Detector
ComponentSpecifications & AlternativeQtyApprox Cost
Arduino Uno R3ATmega328P @ 16MHz1$8.00
HC-SR501 PIR Motion Sensor3–7m range, 110° cone, delay & sensitivity trimpots1$2.00
5mm LED + 220Ω ResistorMotion active indicator1$0.15
5V Piezo Buzzer (Optional)Audible entry chime on D91$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.

Figure: Complete Arduino Uno R3 pin-to-pin wiring schematic for HC-SR501 PIR Passive Infrared Human Motion Detector.
Figure: Complete Arduino Uno R3 pin-to-pin wiring schematic for HC-SR501 PIR Passive Infrared Human Motion Detector.Wiring Schematic

Autonomous Behavior & Finite State Machine (FSM)

Deterministic Arduino loop handling HC-SR501 Pyroelectric Motion Sensor acquisition, filtering, and real-time output updates.

Figure: Firmware execution flow and state transitions for HC-SR501 PIR Passive Infrared Human Motion Detector.
Figure: Firmware execution flow and state transitions for HC-SR501 PIR Passive Infrared Human Motion Detector.Control Algorithm

Step-by-Step Physical Assembly & Wiring Tutorial

Follow each of the 5 sequential milestone stages with technical photos, wiring checks, and pre-flight tests.

1

Pop Off Fresnel Dome to Check Pin Labels

Duration: 5 Mins

Gently lift the white plastic hemisphere to read VCC, OUT, and GND printed right beside the 3-pin header.

HC-SR501 PIR Passive Infrared Human Motion Detector hardware layout diagram
Stage 1: HC-SR501 Pyroelectric Motion Sensor hardware inspection & pinout overview.Stage 1 Diagram
Step Action Checklist:
  • 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.
Engineering & Tuning Tip: Keep the sensitivity pot (Sx) near midpoint indoors so HVAC drafts do not trigger false alarms.
2

Wire PIR OUT to D2 & Alert Outputs to D8/D9

Duration: 5 Mins

Connect power, ground, sensor signal, LED, and optional piezo chime.

HC-SR501 PIR Passive Infrared Human Motion Detector breadboard wiring check diagram
Stage 2: Breadboard layout & Arduino Uno pin-to-pin wiring audit.Stage 2 Diagram
Step Action Checklist:
  • 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.
Engineering & Tuning Tip: Arduino Uno reads 3.3V as a crisp digital HIGH (>3.0V threshold), so no level shifter is required on OUT.
3

Wait Out the 30-Second Pyroelectric Warm-Up

Duration: 5 Mins

Upload the motion monitor and sit still briefly while the sensor establishes ambient IR baseline.

HC-SR501 PIR Passive Infrared Human Motion Detector power rail protection diagram
Stage 3: Supply rail check (USB 5.0V Regulated Rail (<1mA standby)) and circuit protection verification.Stage 3 Diagram
Step Action Checklist:
  • 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".
Engineering & Tuning Tip: Skipping warm-up causes 1–2 false startup triggers—our firmware handles this cleanly automatically.
4

Test Hand Wave & Walk-By Detection

Duration: 5 Mins

Wave your warm hand 50cm in front of the Fresnel dome and verify immediate detection.

HC-SR501 PIR Passive Infrared Human Motion Detector serial telemetry verification diagram
Stage 4: Firmware upload & 115200 baud Serial Monitor verification.Stage 4 Diagram
Step Action Checklist:
  • 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.
Engineering & Tuning Tip: Set the small yellow trigger jumper on the PCB corner to "H" (Repeatable) for hallway lights that stay on while people move.
5

Calibrate Range & Delay for Real Deployment

Duration: 5 Mins

Fine-tune Sx (range) and Tx (hold duration) for your room geometry.

HC-SR501 PIR Passive Infrared Human Motion Detector live operational logic diagram
Stage 5: Live operational logic flow & calibration verification.Stage 5 Diagram
Step Action Checklist:
  • 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.
Engineering & Tuning Tip: Never place a PIR behind glass—ordinary window glass blocks far-infrared (8–14µm) body heat completely!

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 Diagnostic

Minimal standalone sketch to verify pin wiring and signal response for HC-SR501 Pyroelectric Motion Sensor before running the full project firmware.

Arduino IDE Diagnostic ScriptC++ / Arduino
// 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); }
Expected Output: QUIET (LOW) when still; jumps to MOTION (HIGH) for ~3s on hand wave.

Complete Production Firmware

Full working C++ source code with pin mappings, non-blocking timers, and FSM avoidance routines.

arduino_uno_pir_hcsr501_motion_detector.ino
arduino_uno_pir_hcsr501_motion_detector.inoArduino C++
/**
 * 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

1Double-check all 5 Arduino Uno pin connections against the wiring schematic before plugging in USB.
2Upload the Bench Diagnostic sketch first and confirm Serial Monitor at 115200 baud matches: QUIET (LOW) when still; jumps to MOTION (HIGH) for ~3s on hand wave.
3Upload the complete production sketch and verify every condition in the operational truth table below.

Input Signal vs. System Output Truth Table:

Operational truth table for HC-SR501 PIR Passive Infrared Human Motion Detector
Input / StatePin / SignalDetected ConditionExpected Output
Warm Body MovesD2 = HIGH (3.3V)IR Zone ChangeD8 LED ON + Entry Chime
Room StillD2 = LOW (0V)Thermal EquilibriumD8 LED OFF (Armed)

Engineering Troubleshooting Matrix

Engineering troubleshooting matrix for HC-SR501 PIR Passive Infrared Human Motion Detector
ProblemLikely CauseDiagnostic CheckEngineering Solution
Stays stuck HIGH for several minutesTime-Delay trimpot (Tx) turned clockwise near 5-minute maxInspect Tx potentiometer positionTurn Tx fully counter-clockwise for ~3-second reset time.
False triggers in empty roomAimed at sunny window, space heater, or Wi-Fi/RF noiseCover dome with cardboard box to confirm electrical vs thermal triggerRelocate away from drafts/sunlight and lower Sx slightly.
Never detects motionVCC/GND swapped or plastic dome missingVerify 5V on VCC pin under dome silkscreenConfirm 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:

Level 1Auto-Off Smart Desk Lamp

Keep an LED lit for 30 seconds after the last detected movement, resetting the timer on every new motion.

Level 2Timestamped Security Log

Pair with DS3231 RTC (Project 18) to record exact HH:MM:SS timestamps for every visitor.

Level 3Smart Energy-Saving Nightlight

Combine with LDR (Project 13) so motion activates the light ONLY when the room is dark!