The HC-SR501 PIR sensor is the undisputed $2 workhorse of hobbyist motion detection. However, its 5V logic output and susceptibility to RF interference frequently brick ESP32 GPIO pins or cause phantom triggers in smart home builds. This guide skips the generic overviews and provides the exact bench-tested procedures for voltage division, BISS0001 timing math, and interference mitigation required to integrate this module reliably into 3.3V microcontroller ecosystems.

How the HC-SR501 PIR Sensor Actually Detects Motion

The sensor relies on the pyroelectric effect. Inside the metal can, there is a pair of pyroelectric slots made of a crystalline material (typically lithium tantalate) that generates a surface charge when exposed to infrared radiation. When a warm body enters the detection zone, it intercepts the ambient IR background, causing a differential voltage spike between the two slots. The onboard BISS0001 processing IC amplifies this micro-volt signal, filters out low-frequency thermal drift, and triggers the output pin if the signal crosses the internal comparator threshold.

The white plastic dome is a multi-faceted Fresnel lens that focuses IR energy onto the sensor elements while creating a grid of alternating "blind" and "active" zones. Motion is only detected when a heat source crosses from one zone to another, creating the necessary differential pulse. This optical geometry is why the HC-SR501 PIR sensor is completely blind to stationary humans, no matter how close they stand to the lens, and why it requires physical movement across its field of view to register a state change.

Pinout, Wiring, and Power Requirements

The HC-SR501 module breaks out three pins. While it accepts a wide supply range, the output logic level scales with the input voltage, which creates a critical hazard for 3.3V microcontrollers like the ESP32 or Raspberry Pi Pico.

Pin Label Function Specifications Wiring Notes
VCC Power Supply 5V to 20V DC (5V nominal) Must be ≥ 4.5V for the onboard LDO to properly bias the BISS0001 IC.
OUT Digital Output HIGH ≈ VCC - 0.5V Warning: Outputs ~4.5V when powered at 5V. Requires a voltage divider for 3.3V MCUs.
GND Ground 0V Reference Share common ground with the microcontroller.
ESP32 Voltage Divider Requirement: Feeding the 4.5V HIGH signal directly into an ESP32 GPIO will degrade the silicon over time and may instantly destroy the pin. Use a simple resistor divider: place a 2.2kΩ resistor in series with the OUT pin, and a 3.3kΩ resistor from the ESP32 GPIO to GND. This drops the 4.5V signal down to a safe ~2.7V, which easily clears the ESP32’s 2.47V logic HIGH threshold.

Output Signal Math and Logic States

A common beginner mistake is conflating this module with analog IR thermopiles (like the MLX90614). The HC-SR501 PIR sensor outputs a strictly digital binary signal. It does not output analog distance, temperature, or velocity data. The "raw reading" is a discrete logic state, and the physical unit mapping is a boolean presence variable.

Here is the raw-to-unit math for interpreting the electrical signal and the onboard timing components:

  • Voltage-to-Logic Mapping: The physical output voltage is $V_{out} = 0V$ (Vacant) or $V_{out} \approx V_{cc} - 0.5V$ (Occupied). For a 5V supply, $V_{out(HIGH)} \approx 4.5V$. The microcontroller maps this to a physical state: $Presence = 1$ if $V_{read} > V_{IH}$ (Input High Voltage threshold), else $0$.
  • Time Delay Math: The physical time the output stays HIGH after motion ceases is governed by an RC network on the BISS0001 IC. The formula is $T_{delay} \approx R_{pot} \times C_{timing} \times K$, where $C_{timing}$ is fixed at 10nF on most modules, and $R_{pot}$ is the blue trimpot adjustable from ~300kΩ to 3.2MΩ. This yields a physical delay scaling from $T_{min} \approx 0.3$ seconds to $T_{max} \approx 200$ seconds.
  • Lockout Time: After $T_{delay}$ expires, the IC enforces a hardware lockout period ($T_{lock} \approx 2.5$ seconds) where it ignores all pyroelectric inputs to allow the internal op-amps to stabilize.

Calibration, Timing, and Interference Troubleshooting

Out of the box, the HC-SR501 is rarely tuned for indoor embedded projects. Calibration requires adjusting the two blue trimpots and setting the trigger mode jumper.

  1. Sensitivity Potentiometer (Sx): Adjusts the comparator threshold on the BISS0001. Turning it counter-clockwise lowers the gain, reducing the detection cone from 7 meters down to ~3 meters. For indoor hallways, dial it back 40% to prevent triggering on pets in adjacent rooms.
  2. Time Delay Potentiometer (Tx): Adjusts the output hold time. For lighting automation, set this to ~15 seconds. For security alarms, maximize it to ensure the MCU captures the event even during sleep cycles.
  3. Trigger Jumper: Set to H (Retriggerable) for most applications. In H mode, any new motion resets the $T_{delay}$ timer. Set to L (Non-retriggerable) only if you need a strict, unextendable pulse width regardless of continuous motion.

Common Interference Sources

If your sensor is ghost-triggering, check these three bench-proven culprits:

  • RF Interference: The BISS0001 high-impedance amplifier acts as an antenna. Placing an ESP32 or ESP8266 WiFi antenna within 2 inches of the sensor IC will inject 2.4GHz RF noise, causing phantom HIGH states. Maintain a 5cm clearance or shield the sensor can with copper tape tied to GND.
  • Power Supply Ripple: Cheap 5V buck converters with >50mV ripple will inject noise directly into the pyroelectric amplifier. Always solder a 100µF electrolytic capacitor and a 0.1µF ceramic capacitor across the VCC and GND pins on the sensor PCB.
  • Thermal Drafts: HVAC vents or direct sunlight moving across the Fresnel lens will create rapid ambient temperature shifts that mimic human movement. Avoid mounting the sensor facing windows or air returns.
// ESP32 Non-Blocking PIR Read with Software Debounce
const int pirPin = 14;
unsigned long lastTrigger = 0;
const unsigned long debounceDelay = 2000; // 2s software lockout

void setup() {
  Serial.begin(115200);
  pinMode(pirPin, INPUT);
  Serial.println("HC-SR501 Calibrating...");
  delay(30000); // Mandatory 30s hardware warm-up for BISS0001 baseline
}

void loop() {
  if (digitalRead(pirPin) == HIGH) {
    if (millis() - lastTrigger > debounceDelay) {
      lastTrigger = millis();
      Serial.println("Motion Detected (Physical Presence = 1)");
    }
  }
}

HC-SR501 PIR Sensor FAQ

Why is my HC-SR501 PIR sensor constantly triggering with no motion?

Constant phantom triggering is almost always caused by RF interference or power ripple, not a defective sensor. If you are using an ESP32, the 2.4GHz WiFi transmission bursts are coupling into the BISS0001 op-amp. Move the WiFi antenna away from the sensor, add a 100µF decoupling capacitor across the sensor’s VCC and GND pins, and wrap the metal sensor can in grounded copper tape. If the issue persists, dial the sensitivity potentiometer counter-clockwise to lower the amplifier gain.

Can I power the HC-SR501 directly from the 3.3V pin of an ESP32?

No. While the ESP32’s 3.3V pin can supply enough current (~50mA), the HC-SR501 module features an onboard linear regulator designed to step down higher voltages. The BISS0001 IC requires a minimum operating voltage of 4.5V to function reliably. If you feed it 3.3V, the internal LDO dropout will leave the IC with roughly 2.8V, causing it to brownout, fail to initialize, or output a continuous, erratic HIGH signal. Always power the VCC pin with a stable 5V source.

How do I calculate the exact detection distance of the HC-SR501?

The physical detection distance is not a linear value you can calculate with a simple formula; it is dictated by the inverse-square law of IR radiation and the specific geometry of the Fresnel lens. The sensor detects a $\Delta T$ (temperature differential) between adjacent lens facets. A human (37°C) against a 20°C background provides a strong $\Delta T$, allowing detection up to 7 meters. If the background is 30°C, the $\Delta T$ shrinks, and the effective range drops to under 3 meters. You scale this physical range electrically by adjusting the Sx trimpot, which alters the voltage threshold of the internal comparator.