If you need to detect room occupancy or trigger a security light, the HC-SR501 PIR motion sensor outputs a clean 3.3V digital HIGH on motion and 0V LOW on idle. It requires zero analog-to-digital conversion, no logic level shifters for 3.3V microcontrollers, and operates on a 4.5V to 20V supply. For 90% of indoor hobbyist and smart-home builds, this is your default pick. Below is the exact bench data, timing math, and interference mitigation you need to wire it reliably to an ESP32, Arduino, or Raspberry Pi.

The Pyroelectric Sensing Principle

The HC-SR501 relies on the pyroelectric effect to detect changes in infrared (IR) radiation. Underneath the white polyethylene Fresnel lens sits a pyroelectric sensor (typically a D203S or similar) containing two distinct sensing slots wired in opposition. When a warm body moves across the sensor's field of view, it intercepts the ambient IR background, striking one slot before the other. This creates a differential voltage spike that the onboard BISS0001 signal conditioning chip amplifies and compares against a threshold.

Because the two slots are compared differentially, the sensor inherently rejects static heat sources. A hot radiator sitting still in the room emits massive IR, but because it hits both slots equally, the differential output remains zero. The sensor only registers a physical event when there is a change in the IR profile across the lens grid, which is why you must physically move to trigger it. For a deeper look at the semiconductor physics behind pyroelectric detection, refer to Texas Instruments' application notes on PIR signal conditioning.

Pinout, Wiring, and Power Specifications

A common bench mistake is attempting to power the HC-SR501 directly from a 3.3V microcontroller pin. The module features an onboard LDO (Low Dropout) voltage regulator that steps the input voltage down to 5V to run the BISS0001 chip. This LDO requires headroom; feeding it 3.3V will result in erratic behavior or total failure. Always power it from a 5V source, even when reading the signal with a 3.3V board.

Bench Tip: If you are using an ESP32 DevKit v1, wire the sensor's VCC to the VIN or 5V pin (assuming USB power), not the 3V3 pin. The OUT pin, however, safely outputs 3.3V, making it directly compatible with ESP32 and Raspberry Pi GPIOs without a voltage divider.
HC-SR501 Pinout and Electrical Specifications
Pin Label Function Electrical Spec / Range Wiring Target (ESP32 Example)
VCC Power Supply Input 4.5V to 20V DC (5V nominal) ESP32 VIN or 5V
OUT Digital Trigger Output HIGH: ~3.3V | LOW: 0V ESP32 GPIO 13 (or any input)
GND Ground Reference 0V ESP32 GND

Output Signal Math: Digital Logic and Timing Calibration

Unlike ultrasonic or LiDAR sensors, the HC-SR501 does not output an analog voltage proportional to distance, nor does it output a PWM pulse width. The output is strictly boolean. The "raw-to-unit" math for this sensor maps the digital logic state to a physical occupancy state, while the physical calibration maps potentiometer resistance to time and distance.

1. State Mapping (Raw Reading to Physical Unit)
The microcontroller reads the GPIO voltage ($V_{out}$) and maps it to a physical state ($S_{physical}$):

  • If $V_{out} \ge 2.5V$ (Logic HIGH) $\rightarrow S_{physical} = \text{Motion Detected (Occupied)}$
  • If $V_{out} < 0.5V$ (Logic LOW) $\rightarrow S_{physical} = \text{No Motion (Vacant)}$

2. Timing and Sensitivity Scaling Math
The module includes two trimpots (potentiometers) that scale physical resistance to operational parameters. Assuming a standard 10kΩ trimpot with a linear taper, the scaling equations are:

  • Time Delay ($T_{delay}$): The duration the OUT pin stays HIGH after motion ceases.
    Formula: $T_{delay} \approx 0.3\text{s} + (P_{ratio} \times 199.7\text{s})$
    Where $P_{ratio}$ is the potentiometer position from 0.0 (fully counter-clockwise) to 1.0 (fully clockwise). Range: 0.3s to 200s.
  • Sensitivity/Range ($D_{range}$): The physical detection radius.
    Formula: $D_{range} \approx 3\text{m} + (P_{ratio} \times 4\text{m})$
    Range: 3 meters to 7 meters.
// ESP32 Interrupt-Based PIR Reading (Avoids polling delays)
const int PIR_PIN = 13;
volatile bool motionDetected = false;

void IRAM_ATTR handleMotion() {
  motionDetected = true;
}

void setup() {
  Serial.begin(115200);
  pinMode(PIR_PIN, INPUT);
  // Trigger on RISING edge (0V to 3.3V transition)
  attachInterrupt(digitalPinToInterrupt(PIR_PIN), handleMotion, RISING);
}

void loop() {
  if (motionDetected) {
    Serial.println("[PHYSICAL STATE] Occupied");
    motionDetected = false; // Reset flag
  }
  delay(100); // Yield to RTOS
}

Interference Sources and Bench Fixes

The HC-SR501 is notoriously susceptible to environmental noise. If your ESP32 is throwing phantom triggers or the sensor refuses to settle into a LOW state, check these three interference vectors:

  1. RF Interference from WiFi/Bluetooth: The ESP32's 2.4GHz antenna emits RF bursts that can couple into the PIR's high-impedance analog front-end, mimicking a pyroelectric spike. The Fix: Keep the ESP32 antenna at least 5cm away from the PIR lens. If space is constrained, solder a 100µF electrolytic capacitor and a 0.1µF ceramic decoupling capacitor directly across the VCC and GND pins on the sensor PCB to filter power rail noise.
  2. Thermal Drafts and HVAC: Because the sensor detects changes in IR, a sudden blast of hot air from a heating vent moving across the lens grid will trigger it, even without a solid object. The Fix: Aim the sensor away from HVAC registers and use the sensitivity trimpot to reduce the detection cone if the room is small.
  3. Power Supply Ripple: If you are powering the sensor from a cheap, unregulated 5V wall wart, AC ripple on the DC line will cause the BISS0001 chip's internal comparators to chatter. The Fix: Use a regulated power supply or add bulk capacitance (470µF) at the breadboard power rails.

For a comprehensive breakdown of how Fresnel lenses focus IR and the common pitfalls of PIR deployment, the Adafruit PIR Sensor Guide remains an excellent visual reference.

Decision Matrix: Choosing the Right Occupancy Sensor

While the HC-SR501 is the workhorse of the maker bench, it is not the only motion technology available. Use this decision tree to verify you have the right module for your specific enclosure and power constraints.

Project Constraint If your build requires... Then choose this sensor Why?
Standard Indoor Room 3.3V logic, 5V power available, line-of-sight detection HC-SR501 Cheap ($1.50), adjustable delay, native 3.3V output.
Through-Wall / Hidden Detecting motion behind plastic enclosures, wood, or drywall RCWL-0516 (Microwave Radar) 5.8GHz Doppler radar penetrates non-metallic materials; PIR cannot see through walls.
Battery / Wearable Ultra-low quiescent current (<100µA), tiny PCB footprint AM312 (Mini PIR) Draws ~12µA at rest. The SR501's LDO and BISS chip draw ~50mA, killing coin cells.
Pet Immunity Ignoring dogs/cats under 40lbs while detecting humans Dual-Element PIR with Pet Lens Standard SR501 lenses trigger on any heat mass; specialized pet-immune lenses mask the lower grid.

The Final Verdict

Default Pick: Buy the HC-SR501. At roughly $1.50 per module, it offers the best balance of adjustable timing, safe 3.3V logic levels for modern microcontrollers, and wide availability.

Switch to the RCWL-0516 only if you need to hide the sensor inside a 3D-printed PLA/PETG enclosure without cutting a hole for the Fresnel lens. Switch to the AM312 only if your project runs on a lithium coin cell or AA batteries and cannot afford the 50mA quiescent draw of the SR501's onboard voltage regulator.

Safety Note: The HC-SR501 OUT pin can only source roughly 10mA. Never wire it directly to a mains-voltage relay coil or a high-power LED strip. Always use the OUT pin to trigger a logic-level MOSFET (like an IRLZ44N) or an optocoupler to switch heavier loads safely.