Working Principle
The HC-SR501 is a passive infrared (PIR) motion detector based on a pyroelectric sensor element. All warm objects emit infrared radiation (~10 µm wavelength). The sensor contains two pyroelectric elements wired in opposite polarity. When a warm body moves across the sensor's field, it sequentially heats one element then the other, producing a differential voltage pulse that signals motion.
Analogy: Picture two thermometers side by side behind a slotted screen. A person walking past heats one thermometer then the other. The difference between them is your motion signal.
Electrical Characteristics
| Parameter | Value |
|---|---|
| Supply Voltage | 4.5 V – 20 V (on-board 3.3 V regulator) |
| Output | Digital HIGH (3.3 V) on motion |
| Detection Range | Up to 7 m (adjustable via potentiometer) |
| Detection Angle | <120° cone (Fresnel lens pattern) |
| Time Delay | 0.3 s – 5 min (adjustable via potentiometer) |
| Trigger Mode | Single trigger (L) / Retriggerable (H) |
| Warm-up Time | ~60 seconds after power-on |
| Current | <50 µA (quiescent) |
Interfacing with an MCU
The HC-SR501 has just three pins: VCC, OUT, and GND. Output goes HIGH (3.3 V) when motion is detected. Two potentiometers adjust sensitivity (range) and output hold time. A jumper selects single-trigger (L) or retriggerable (H) mode.
Calibration
The HC-SR501 requires no software calibration, but hardware tuning is essential:
- Sensitivity pot (CW): Increases detection range from ~3 m to ~7 m.
- Time-delay pot (CW): Increases output hold time from ~0.3 s to ~5 min.
- Warm-up period: After power-on, the sensor needs ~60 seconds to stabilise — ignore outputs during this window.
- Fresnel lens swap: Replace the dome lens with a flat Fresnel for narrower detection patterns.
Code Example
/*
* HC-SR501 PIR Motion Sensor — Arduino
* Wiring: OUT → Pin 2, VCC → 5V, GND → GND
* Allow 60s warm-up after power-on
*/
#define PIR_PIN 2
#define LED_PIN 13
volatile bool motionDetected = false;
void motionISR() {
motionDetected = true;
}
void setup() {
Serial.begin(9600);
pinMode(PIR_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
attachInterrupt(digitalPinToInterrupt(PIR_PIN), motionISR, RISING);
Serial.println("Warming up PIR sensor (60s)...");
delay(60000); /* Wait for sensor stabilisation */
Serial.println("HC-SR501 Ready");
}
void loop() {
if (motionDetected) {
motionDetected = false;
Serial.println("** MOTION DETECTED **");
digitalWrite(LED_PIN, HIGH);
delay(2000);
digitalWrite(LED_PIN, LOW);
}
}
Real-World Applications
Smart Lighting & HVAC Occupancy
Office buildings deploy PIR sensors in every room to control lighting and air conditioning based on occupancy. The sensor's ultra-low quiescent current (<50 µA) means battery-powered wireless nodes can run for years. Integrating with a building management system (BMS) reduces energy costs by 20–40%.
Limitations
- Motion only: Detects moving warm bodies, not stationary people — a seated desk worker may not retrigger.
- False triggers: Pets, sunlight changes, and convection heat can trigger false alarms.
- Line of sight: IR radiation does not penetrate glass, acrylic, or walls — place the sensor with a clear path.
- Dead zone: A 2.5-second blind window after each trigger (in single-trigger mode) can miss rapid events.