Skip to content
Go back

PIR HC-SR501 Sensor: Datasheet and Wiring

Published:  at  11:15 AM

What the HC-SR501 detects

The HC-SR501 is a PIR module that detects changes in infrared radiation produced by the movement of warm bodies. It’s cheap and simple, but it doesn’t detect static presence: if a person stays still they may stop triggering the output.

It’s good enough for a hallway light or a movement alert. To know whether someone is still sitting in a room, an mmWave radar such as the LD2410 may fit better.

Pins and controls

Most modules expose three pins:

PinFunction
VCCPower for the module
OUTDigital motion output
GNDCommon ground

They usually also include two adjustments: one for sensitivity and another for how long the output stays active. Some modules include a retrigger mode selector. The silkscreen can vary, so check the module before wiring it.

Wiring to the ESP32

For a simple test, connect VCC to a compatible voltage, GND to the ESP32 ground and OUT to a GPIO configured as an input. The output level must be compatible with the ESP32: don’t assume that any module powered at 5 V can drive a 5 V signal straight into a 3.3 V GPIO.

An example connection could use GPIO27 for OUT, but pick a free pin on your board and avoid the ones used during booting. Test first with a multimeter or a low-current LED, and don’t connect relays or dangerous loads directly to the output.

Wiring diagram of the HC-SR501 PIR sensor to the ESP32
The PIR provides a digital motion output to GPIO27 on the ESP32.

Configuration with ESPHome

binary_sensor:
  - platform: gpio
    pin: GPIO27
    name: "Hallway motion"
    device_class: motion
    filters:
      - delayed_off: 10s

The filter keeps the state active for a few seconds after the last trigger and stops a light from switching off immediately. The module’s physical time and the software filter add up, so tune both during testing.

Sensitivity and false detections

Mount the sensor at a height and orientation that cover the real zone, not pointing at a window with temperature changes or at a heat source. Lateral movement is usually easier to detect than walking straight towards the sensor.

Start with moderate sensitivity and time. If you turn them up to the maximum, a door, a draught or thermal changes can keep the output active. If you turn them down too far, a person can walk through the zone without triggering the module.

Frequent problems

PIR or mmWave

The PIR is a good option for cheap, simple movement detection. mmWave is more suitable if you need static presence, although it requires more careful tuning and can be more sensitive to the environment. Don’t choose on the datasheet alone: test the sensor in the actual room.

Security

Use the sensor for reversible automations. A movement detection shouldn’t be the only condition for opening a lock, disabling an alarm or switching on a dangerous load. Keep a manual control and check what happens if the ESP32 loses the network.

Sources and next step

Read the ESPHome GPIO sensor documentation and the datasheet of the specific module. For temperature and humidity projects, see DHT11 vs DHT22.

The homeiotguide editorial team

Editorial lead: Néstor Espuch


Suggest changes
Share this article on:

Previous article
ESP32 vs ESP8266 vs Arduino: which to choose
Next article
HLK-LD2410 mmWave Presence Sensor with Home Assistant