How the HC-SR501 PIR Motion Sensor Detects Movement
The HC-SR501 relies on the pyroelectric effect to detect changes in infrared radiation. Under the white Fresnel lens sits a dual-element pyroelectric sensor (typically LiTaO3). When a warm body moves across the sensor's field of view, it sequentially triggers the two elements, creating a tiny differential voltage spike. The lens focuses the IR energy into distinct detection zones, meaning the sensor inherently requires motion across these zones to trigger; a perfectly still human will eventually time out and register as absent.
This micro-volt analog spike is fed into the onboard BISS0001 signal conditioning IC. The BISS0001 amplifies the signal, filters out high-frequency noise and low-frequency thermal drift, and compares it against an internal threshold. Once the threshold is crossed, the IC drives the OUT pin to a digital HIGH state, holding it there for a user-configurable delay before returning to LOW. It is strictly a digital presence detector, not a rangefinder or analog thermometer.
Pinout, Power Supply Range, and ESP32 Wiring
The most common mistake hobbyists make with the HC-SR501 is frying their 3.3V microcontroller GPIO pins. The module requires a minimum of 4.5V to operate reliably, meaning you cannot power it directly from an ESP32's 3V3 rail without causing constant brownout false-triggers. However, powering it from the 5V rail means the OUT pin will push ~4.5V to 5V into your ESP32, which exceeds the 3.3V absolute maximum rating of the ESP32 GPIO pins.
| Pin | Function | Specification / Range | ESP32 Connection |
|---|---|---|---|
| VCC | Power Supply | 4.5V to 20V DC (5V nominal) | ESP32 5V (VIN) |
| OUT | Digital Output | HIGH ≈ VCC - 0.5V / LOW = 0V | Voltage Divider → GPIO 4 |
| GND | Ground Reference | 0V | ESP32 GND |
Output Signal Logic and Timing Math
The HC-SR501 outputs a push-pull digital voltage. It does not output PWM, analog resistance, or distance data. A HIGH state means "motion detected," and LOW means "clear." To use this in a microcontroller, you must map the raw pulse width (in milliseconds) to physical occupancy time, accounting for the sensor's hardcoded blocking time.
The BISS0001 IC features two timing circuits: the output delay ($T_d$) and the blocking/inhibit time ($T_i$). On the HC-SR501 module, $T_i$ is hardcoded via a fixed resistor and capacitor to approximately 2.5 seconds. This means after the OUT pin goes LOW, the sensor is blind to new motion for 2.5s. The output delay $T_d$ is adjustable via the onboard potentiometer from roughly 0.3s to 18s.
Raw-to-Unit Math: Calculating True Occupancy
If you are logging room occupancy, reading the raw millis() pulse width will overestimate the time the person was actually moving, because the sensor artificially holds the line HIGH. Use this formula in your code to extract the physical trigger duration:
True_Motion_Event_Time = Total_Pulse_Width - (T_d_Setting + 2.5s_Blocking_Time)
Calibration Procedure:
1. Turn the Delay potentiometer fully counter-clockwise. This sets $T_d$ to its minimum (~0.3s).
2. Walk in front of the sensor and measure the HIGH pulse width with pulseIn(). It should read roughly 2800ms (0.3s delay + 2.5s blocking tail).
3. If your application requires a strict 5-second alarm trigger, rotate the pot clockwise while monitoring the serial plotter until the total pulse width stabilizes at 7500ms (5.0s delay + 2.5s blocking).
Interference Sources and Bench Fixes
PIR sensors are notoriously susceptible to environmental noise. If your HC-SR501 is ghost-triggering (going HIGH with no one in the room), check these three culprits:
- RF Interference from WiFi/BLE: The 2.4GHz RF emissions from an ESP32-WROOM-32 antenna can induce micro-currents in the BISS0001's high-impedance analog front-end. Fix: Keep the ESP32 antenna at least 5cm away from the PIR dome, or wrap the PIR's PCB in copper tape tied to GND (leaving the dome exposed).
- Thermal Drafts and Sunlight: HVAC vents, space heaters, or direct sunlight moving across a floor will trigger the pyroelectric elements. Fix: Apply black electrical tape to the bottom segments of the Fresnel lens to restrict the vertical field of view away from heat registers.
- Power Supply Ripple: Switching buck converters (like the LM2596) often output high-frequency voltage ripple that the BISS0001 interprets as a thermal spike. Fix: Solder a 100µF electrolytic capacitor and a 0.1µF ceramic capacitor directly across the VCC and GND pins on the sensor PCB.
Decision Matrix: Choosing the Right Motion Sensor
The HC-SR501 is a legacy workhorse, but it isn't the right tool for every embedded project. Use this decision path to select the correct module for your specific build constraints.
| Project Constraint | If your requirement is... | Then choose this module |
|---|---|---|
| Power Supply | Native 3.3V logic and 3.3V power rail (e.g., coin cell or direct LiPo) | HC-SR602 (Mini PIR) |
| Detection Type | Must detect presence through walls, glass, or plastic enclosures | RCWL-0516 (Microwave Radar) |
| Form Factor | Must fit inside a standard 1-gang wall switch box with 120V AC nearby | HC-SR501 (with isolated PSU) |
| Pet Immunity | Needs to ignore cats/dogs under 40 lbs | AM312 (with custom pet-immune lens) |






