The Complete Guide to the HC-SR501 PIR Motion Sensor

When it comes to detecting motion in DIY electronics, the HC-SR501 PIR sensor is one of the most popular and affordable choices. It’s used everywhere: alarm systems, automatic lights, smart home devices, and even art installations. In this guide we’ll cover how the sensor works, its specifications, wiring, configuration, and how to use it with Arduino or ESP32.

What is the HC-SR501?

The HC-SR501 is a PIR (Passive Infrared) motion sensor. It detects changes in infrared radiation — essentially, it senses when a warm body (like a human or animal) moves in its field of view. Unlike radar sensors (like the LD2410), the HC-SR501 cannot detect micro-motion or stationary presence. It only triggers when there’s a change in IR levels (motion).

Why use it?

  • Very low cost and widely available
  • Simple digital output (HIGH/LOW)
  • Adjustable sensitivity and delay time
  • Good for indoor use (lights, alarms, presence detection)
  • Works with 3.3V and 5V systems

Key Specifications

ParameterValue
Operating Voltage4.5 – 20 V (works on 5V and 3.3V logic)
Current Consumption~50 µA (standby)
OutputDigital HIGH (3.3V) / LOW (0V)
Detection Range3 – 7 m (adjustable)
Field of View~120° cone
Trigger ModesNon-retriggerable / Retriggerable
Delay TimeAdjustable (≈ 3 s to 300 s)
SensitivityAdjustable (distance control, up to ~7 m)
Working Temperature−15 °C to +70 °C

How Does it Work?

  • The HC-SR501 has a pyroelectric sensor behind a white Fresnel lens.
  • The lens focuses infrared from the environment onto the sensor.
  • When a warm object moves (like a human body), the infrared pattern changes.
  • The onboard amplifier & comparator generate a digital HIGH signal on motion.
  • After the set delay time, the output goes LOW again.

Pinout and Wiring

The module typically has 3 pins:

PinNameFunction
VCCPower (5V recommended, works from 4.5–20V)
OUTDigital output: HIGH when motion detected
GNDGround

Example Wiring with ESP32 / Arduino

  • VCC → 5V (or 3.3V if module supports it)
  • GND → GND
  • OUT → Digital GPIO pin

Configuration: Delay & Sensitivity

On the HC-SR501 board you’ll find two orange potentiometers:

  • Delay time adjustment: sets how long output stays HIGH after detection (3 s – 300 s). (the pot on the left, see image below).
  • Sensitivity adjustment: sets detection distance (approx. 3 m – 7 m).(the pot on the right, see image below).

There is also a small jumper to set trigger mode:

  • H (retriggerable): Output stays HIGH if motion continues.
  • L (non-retriggerable): Output goes LOW after delay, even if motion continues.

Example Code (Arduino)

Here’s a simple sketch to read the PIR output:

#define PIR_PIN 2  // OUT pin connected to D2

void setup() {
  Serial.begin(115200);
  pinMode(PIR_PIN, INPUT);
}

void loop() {
  int pirValue = digitalRead(PIR_PIN);
  
  if (pirValue == HIGH) {
    Serial.println("Motion detected!");
  } else {
    Serial.println("No motion.");
  }
  
  delay(500);
}

Example Code (ESP32)

Same as Arduino, but you can also attach interrupts for instant detection:

#define PIR_PIN 17

volatile bool motionDetected = false;

void IRAM_ATTR detectMotion() {
  motionDetected = true;
}

void setup() {
  Serial.begin(115200);
  pinMode(PIR_PIN, INPUT);
  attachInterrupt(digitalPinToInterrupt(PIR_PIN), detectMotion, RISING);
}

void loop() {
  if (motionDetected) {
    Serial.println("Motion detected!");
    motionDetected = false;
  }
}

Practical Tips

  • Warm-up time: After powering up, the sensor needs 30–60 seconds to stabilize.
  • Mounting height: Best results at 2–3 m height, angled to cover the detection area.
  • Avoid false triggers: Keep away from heat sources (heaters, vents, sunlight).
  • Pets: Sensitive enough to detect animals — useful or problematic depending on your project.
  • Indoors only: Outdoors, sun & wind may cause false triggers unless carefully shielded.

Project Ideas

The HC-SR501 is simple but versatile. Some use cases:

  • Automatic lights: turn on when motion is detected, off after timeout.
  • Security alarms: trigger a siren or send a notification.
  • Smart home presence detection: integrate with ESPHome/Home Assistant.
  • Interactive art / exhibits: trigger sounds, visuals, or motors when people walk by.
  • Energy saving: power down devices when no movement is detected.

Conclusion

The HC-SR501 PIR motion sensor is one of the easiest and cheapest ways to add motion detection to a project. With adjustable range and delay, simple digital output, and low power consumption, it’s ideal for beginners and professionals alike. If you need to detect still presence or want finer distance information, you might want radar modules like the HLK-LD2410. But for most everyday motion sensing, the HC-SR501 is a rock-solid choice.

error: Content is protected !!
Scroll to Top