HC-SR501 PIR Sensor


Introduction

HC-SR501 PIR sensor is built around the BISS0001 Micro Power PIR Motion Detector IC. It can be used as a standalone unit or connected to an PCB board like Arduino.

Specifications

Operating voltage4.520 V
Quiescent current50 μA
Level output3.3 / 0 V
TriggerL single trigger / H repeating trigger
Delay time3300 s
Blocking time2.5 s (default)
Measuring range37 m
Measuring angle< 110° cone angle
Fresnel lens dimensions15 mm x 23 mm diameter
Operating temperature-1570 °C

How PIR works

PIR stands for Passive INfrared. A PIR motion sensors is made up by two main components:

  1. pyroelectric sensing element
  2. fresnel lens

The pyroelectric sensing element can detect infrared radiation. All objects with a temperature above absolute zero (-273.15 °C) emit heat energy in the form of infrared radiation.

A pyroelectric sensor has two rectangular slots in it, both made of a material that allows the infrared radiation to pass. Behind these, there are two separate infrared sensor electrodes:

  • one produce a positive output
  • the other, a negative output

The sensor needs both of them since it’s looking for a change in IR levels (and not ambient IR levels). If one half sees more or less IR radiation than the other, the output will swing high or low.

The on-board signal processing IC processes this signal and turns the output pin of the sensor HIGH or LOW accordingly.

working principles part 1

The white dome in front of the sensing element is a fresnel lens. This lens focuses the infrared radiation onto the sensor.

working principles part 2

Adjust the sensor

On the back of the board there are two potentiometers and a jumper.

HC-SR501 pinout annotation

Range

The HC-SR501 detection range goes from 3 meters up to 7 meters. You can adjust the sensing distance by rotating the sensitivity potentiometer clockwise (increase) or counterclockwise (decrease).

Time-delay (Tx)

This potentiometer can be used to adjust the time that the output stays HIGH for after motion is detected. The delay goes from 3 seconds up to 300 seconds (5 minutes). Turn the potentiometer clockwise to increase the delay and counterclockwise to decrease it.

Trigger selection jumper

The (yellow) jumper can be used to select one of the two trigger modes. It can be set to either:

  • L - Single trigger: The output will turn HIGH as soon as motion is detected.
    It will stay HIGH for the time set by the potentiometer. Any movement during this period is not processed and does not restart the timer.
  • H - Repeating trigger: Every time motion is detected, the delay timer is restarted.

Difference between L and H selections

Standalone unit

Hardware requirements & setup

  1. HC-SR501 sensor
  2. LED
  3. Resistors (if needed)
  4. Hook-up wires of different colors
  5. Breadboard

For most basic applications, you can use the HC-SR501 as a standalone unit. The output signal will directly trigger components like relays or LEDs.

Wiring schema as a standalone units

And that’s it: no code needed!

Arduino

Please refer to the official Getting Started guide to install the Arduino IDE on the OS you prefer.

Hardware requirements & setup

  1. Arduino Uno board or any Arduino-like board
  2. HC-SR501 sensor
  3. Hook-up wires of different colors
  4. Breadboard

The OUT pin is connected to digital pin 8 but ou can connect it any digital pin.

Wiring schema with Arduino Uno

Code

The code will read the state of the sensor (HIGH or LOW) and turn ON or OFF the built-in board LED accordingly. Moreover, it will print debugging-like messages to the Serial Monitor.

I suggest you to set the H mode (repeat trigger) and adjust the time-delay potentiometer to the lowest value.

The test code is HC-SR501-Test.ino from arduino-projects GitLab repository.

The output will be like:

#HC-SR501: Motion detected
#HC-SR501: Motion ended
#HC-SR501: Motion detected
#HC-SR501: Motion ended
#HC-SR501: Motion detected
#HC-SR501: Motion ended
...

Conclusion

HC-SR501 needs some time to initialize and adjust to the infrared levels in the room. This process takes approximately 1 minute when it is first powered up. You should try to delete any motion in front of the sensor during this period. Moreover, wind and a light source close to the sensor can cause interference.

Besides the delay-time (Tx), the sensor also has a blocking-time (Ti). By default, the blocking time is 2.5 seconds (it’s not so easy to change). Each time the output goes from HIGH to LOW, blocking period starts. During this time period, the sensor will not detect any motion.

When designing a system based on the HC-SR501, you will need to take Tx and Ti delay periods into account.

Documentation

Useful links: