HC-SR501 PIR Sensor – Learn how to use with Arduino

Learn to use the HC-SR501 PIR Sensor. In this post we’ll go over how to use this sensor in standalone applications (i.e. without a microcontroller) and with an Arduino.

The HC-SR501 PIR sensor is a Passive Infrared sensor that can be used to detect the presence of a body. This is accomplished by the sensor by sensing the amount of infrared radiation within its range. When there isn’t anything in front of the sensor (other than whatever is in the background), the sensor will be in a steady state, but when something passes in front of it, the infrared radiation sensed by the PIR sensor will change, and once the body passes, it will return to normal. This change is what’s detected, resulting in the sensor outputting a signal that indicates a body was detected.

Testing HC-SR501 with a hand.

HC-SR501 Sensor Pins

The HC-SR501 PIR sensor has three pins: GND, Out, and VCC.

GND – This pin is connected to the main circuit ground. If used with an Arduino, the sensor and the Arduino’s ground must be connected.
VCC – A typical voltage for VCC for this sensor is 5V.
Out – This pin will output 3.3V when motion is detected, and 0V when there is no motion.

HC-SR501 sensor pins.

HC-SR501 Sensor Setting

There are two main settings that can be adjusted: sensitivity and time delay. Both of these settings can be adjusting by turning the screws show on the image to the right.

Sensitivity – This will define the range/distance over which the sensor will be “looking” for motion. The lowest setting would be approximately 10ft/3meters and the highest setting would be roughly 23ft/7meters.

Time Delay – This is how long the sensor will provide an output of 3.3V after the motion has been detected. This will range from 3 seconds, to 5 minutes.

HC-SR501 time delay and sensitivity adjustment knobs.

Other considerations

The sensor takes about a minute to start-up. So once you provide power by connecting to VCC and GND, wait roughly one minute before expecting any readings from the sensor.

HC-SR501 without an Arduino

In this example we will setup a buzzer (KY-012) and red LED to make some noise and light up when motion is detected. To enable this, a 2N2222 transistor will be used as a switch (as shown below). The two images below show the breadboard and circuit for the same example:

Click to enlarge

Click to enlarge

HC-SR501 with an Arduino

In this example we connect the HC-SR501 sensor to an Arduino UNO by connecting the sensor output to digital input port #2 on the Arduino. This will enable the Arduino to know when the sensor output is active (i.e. sending 3.3V) and when it’s not (i.e. at 0V). Separately, we connect an LED and 220Ohm resistor in series with digital output #6 and then connect to ground. This allows us to trigger a command in the Arduino to light up the LED when the sensor output is active.

Click to enlarge

Arduino Code

Components used in this example

*As an Amazon Associate I earn from qualifying purchases.

Where to buy [Amazon Affiliate]:
Arduino UNO: https://amzn.to/3U7xAoT
Electronic Component Kit: https://amzn.to/3xDtHAn
Hilitchi Transistors Assortment Kit: https://amzn.to/4aI8Mux
HC-SR501 (PIR sensor): https://amzn.to/4b4TYWJ
Breadboard (Elenco 9440): https://amzn.to/4b5Onzq

Leave a Reply

Your email address will not be published. Required fields are marked *