The HC-SR501 PIR sensor outputs a digital 3.3V HIGH signal on its OUT pin when infrared motion is detected, and 0V LOW when the area is clear. It requires a DC supply voltage between 4.5V and 20V (5V is the standard benchmark). Unlike analog infrared distance sensors, the HC-SR501 does not output a variable voltage proportional to distance or temperature; it is strictly a binary occupancy switch driven by an onboard comparator chip.

The Physics of the HC-SR501: How Pyroelectric Sensing Works

The HC-SR501 relies on a pyroelectric sensor (typically the D203B or a similar dual-element chip) housed beneath a hemispherical polyethylene Fresnel lens. Pyroelectric materials generate a temporary surface voltage when exposed to changes in infrared (IR) radiation. The dual-element design is crucial: the two sensing windows are wired in opposition. When a warm body moves across the sensor's field of view, the IR radiation strikes the first element, then the second, creating a differential voltage spike that cancels out ambient, static heat sources like a sunlit wall.

The raw microvolt spikes from the pyroelectric element are fed into the onboard BISS0001 analog processing chip. This chip amplifies the signal, filters out high-frequency noise via internal op-amps, and passes it through a dual-window comparator. If the amplified signal crosses the threshold set by the sensitivity potentiometer, the BISS0001 triggers the output pin HIGH for a duration dictated by the delay potentiometer. For a deeper look at the underlying physics of passive infrared detection, Adafruit's PIR Sensor Guide provides an excellent breakdown of the Fresnel lens optics.

Hardware Pinout, Wiring, and Power Requirements

Wiring the HC-SR501 to a microcontroller is straightforward, but power delivery is where most beginners run into brownout issues. The module features an onboard 3.3V LDO voltage regulator (usually an ABLIC S-817 or similar 7133 clone). When you supply 5V to the VCC pin, the LDO drops it to 3.3V to power the BISS0001 chip. Because the OUT pin is tied to the BISS0001's VCC rail, the output HIGH signal is naturally 3.3V, making it directly compatible with ESP32 and Raspberry Pi GPIO pins without a logic level shifter.

Pin Label Function Electrical Specifications Wiring Target
VCC Power Supply Input 4.5V to 20V DC (5V recommended) Arduino 5V / ESP32 VIN (or external 5V PSU)
OUT Digital Motion Signal ~3.3V HIGH (Motion) / 0V LOW (Clear) Any digital GPIO (e.g., ESP32 GPIO 14)
GND System Ground 0V Reference Microcontroller GND / PSU GND
Bench Tip: If you are powering the HC-SR501 directly from an ESP32's 3.3V pin, the sensor will likely fail to initialize. The pyroelectric element and the LDO headroom require at least 4.5V to operate reliably. Always feed VCC with 5V, and rely on the module's internal LDO to handle the 3.3V logic output.

Output Signal Math, Scaling, and Calibration

Because the HC-SR501 is a digital sensor, there is no analog voltage scaling required to convert a raw ADC reading into distance. The raw-to-physical unit mapping is a direct binary state translation. However, the timing calibration involves specific RC network math governed by the BISS0001 chip.

Raw to Physical State Mapping

In your microcontroller code, the physical unit of measurement is binary occupancy (1 = Occupied, 0 = Vacant). The mathematical mapping in C++ is:

int raw_state = digitalRead(PIR_PIN);
int occupancy_state = (raw_state == HIGH) ? 1 : 0;

Timing Calibration and the BISS0001 Math

The HC-SR501 features two trimpots: Sensitivity (Sx) and Delay Time (Tx). The delay time is controlled by an external RC network connected to the BISS0001's timing pins. According to the SparkFun PIR Hookup Guide and BISS0001 datasheets, the output delay time formula is:

T_x ≈ 49152 × R_x × C_x

On standard HC-SR501 clones, the delay capacitor (C_x) is typically marked '104' (0.1 µF). The potentiometer (R_x) sweeps from roughly 0Ω to 1MΩ. If we plug these into the formula:

  • Minimum Delay: 49152 × 0Ω × 0.0000001F = 0 seconds (The chip enforces a hardware minimum of ~0.3s).
  • Maximum Delay: 49152 × 1,000,000Ω × 0.0000001F = ~4.9 seconds.

The Clone Discrepancy: You will often see silkscreen on the HC-SR501 claiming a delay range of '0.3s to 200s'. On the bench, most modern cheap clones max out around 5 to 15 seconds because manufacturers substitute the 1.0 µF capacitor specified in the original reference design with a cheaper 0.1 µF cap. If you genuinely need a 200-second delay, you must desolder the '104' ceramic capacitor on the board and replace it with a '105' (1.0 µF) or larger capacitor.

Interference Sources and False Trigger Mitigation

The HC-SR501 is notoriously susceptible to environmental noise. If your sensor is randomly triggering with no human present, you are likely experiencing one of three interference vectors:

  1. RF Interference (The ESP32 Problem): The 2.4 GHz radio transmissions from an ESP32 or WiFi router can induce micro-currents in the high-impedance pyroelectric element, mimicking a heat signature. Fix: Solder a 100 µF electrolytic capacitor directly across the VCC and GND pins on the sensor module to act as an RF decoupling buffer, and mount the sensor at least 15 cm away from the microcontroller's antenna.
  2. Thermal Drafts: HVAC vents, space heaters, or even a sudden draft from an opening door can change the ambient IR profile fast enough to trip the comparator. Fix: Aim the sensor away from air conditioning returns and use the sensitivity pot to dial back the detection range from 7m to 3m.
  3. Direct Optical IR: Direct sunlight or incandescent bulbs contain massive amounts of infrared radiation. While the Fresnel lens focuses IR, direct saturation will blind the D203B element. Fix: Never point the sensor toward a window or an unshielded heat lamp.

Non-Blocking ESP32 Implementation Code

When integrating the HC-SR501 into a larger IoT project, using delay() to wait for the sensor to clear will brick your system's responsiveness. Use this non-blocking state-machine approach for the ESP32:

// HC-SR501 Non-Blocking Polling for ESP32
const int PIR_PIN = 14;
unsigned long lastMotionTime = 0;
const unsigned long cooldownPeriod = 5000; // 5s software cooldown

void setup() {
  Serial.begin(115200);
  pinMode(PIR_PIN, INPUT);
  // Allow the BISS0001 chip to stabilize on boot (requires ~30s)
  Serial.println("Calibrating sensor baseline...");
  delay(30000); 
  Serial.println("Sensor Active.");
}

void loop() {
  int currentReading = digitalRead(PIR_PIN);
  
  if (currentReading == HIGH) {
    if (millis() - lastMotionTime > cooldownPeriod) {
      Serial.println("MOTION DETECTED: Room Occupied");
      lastMotionTime = millis();
      // Trigger MQTT publish or relay here
    }
  }
  
  // Handle other non-blocking tasks here
}

Frequently Asked Questions (FAQ)

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

Constant false triggering is almost always caused by RF noise or power rail instability. If you are using an ESP32, the WiFi radio drawing peak current during transmission causes a voltage sag on the 5V rail, which the HC-SR501's cheap onboard LDO interprets as a signal anomaly. Soldering a 100 µF to 470 µF electrolytic capacitor directly to the VCC and GND pins of the PIR module will smooth out these transients. Additionally, ensure the sensor is not pointed at a heat source or a drafty window.

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

No. While the ESP32's 3.3V pin can supply enough current (the HC-SR501 draws roughly 65 µA quiescent), the voltage is too low. The HC-SR501 requires a minimum of 4.5V to overcome the forward voltage drops of its internal components and the LDO regulator. If you feed it 3.3V, the BISS0001 chip will fail to initialize, and the OUT pin will either float randomly or stay permanently LOW. Always power the VCC pin with 5V.

What is the difference between the H and L jumper modes on the HC-SR501?

The 3-pin header on the bottom corner of the module dictates how the BISS0001 handles continuous motion. In H mode (High/Repeatable Trigger), the output stays HIGH as long as motion is continuously detected; the timer resets every time a new movement occurs. In L mode (Low/Non-Repeatable Trigger), the output goes HIGH upon initial detection, but the sensor ignores all subsequent motion until the delay timer expires and the output drops LOW. For most home automation and security lighting applications, you want the jumper set to H mode so the lights don't turn off while you are sitting still reading a book.