Home Raspberry Pi Sensors Infrared Sensor HC-SR501 PIR Motion Sensor for a Raspberry PI and...

Infrared Sensor HC-SR501 PIR Motion Sensor for a Raspberry PI and Arduino

How to use PIR sensor with your Raspberry PI.

Tech details:

  • Voltage: 5V – 20V
  • Power Consumption: 65mA
  • TTL output: 3.3V, 0V
  • Adjustable delay time (0.3-300sec)
  • Lock time: 0.2 sec
  • Trigger methods: L – disable repeat trigger, H enable repeat trigger
  • Sensing range: less than 120 degrees, within 7 meters
  • Temperature: – 15 ~ +70
  • Dimension: 32*24 mm, distance between screw 28mm, M2, Lens dimension in diameter: 23mm


3 pin connector, pins as follows:

  • GND: 0V Ground
  • OUT: PIR output (max 3,3v)
  • VCC: 5V Supply (max 20v)

What does it do?

HC-SR501 PIR Motion Sensor is one of the more common types of sensors out there. Infrared light detection allows to track changes in the desired area and respond to the rapid changes. This allows us to detect movement. The sensor produces binary output (0=LOW, 1=HIGH). Sensor requires few moments to set the ambient reading before correct reading can be provided. The dials available on the sensor allow finer control over the sensitivity and the delay timing. Adjust incrementally as changes are rapid.

How to use it?


Connecting HC-SR501 PIR Motion Sensor is very simple. The first pin belongs to ground (black) and it is linked to any ground pin on RPI.

Middle (blue) is an output connection and it delivers 0/1 values to the RPI. There is no need for stepping down as the voltage at HIGH is 3.3V. It is powered by 5V input which can be drawn from the RPI (red) .


Also, present on the board are 2 dials to adjust your sensitivity distance (3-7m) and delay timer (0.3-300sec) turn clockwise to increase the value.

On this particular sensor, you can also notice 3 additional pins, with a jumper connector.  This allows to pick retrigger setting:

  • (pins L) unrepeatable trigger
  • (pins H) repeatable trigger

Sample code:

You can test the sonar using Python2 code from here

Project Download

Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.


Nothing says "Thank you" better than keeping my coffee jar topped up!


Support me on Patreon and get an early access to tutorial files and videos.


Bitcoin (BTC)

Use this QR to keep me caffeinated in style with crypto-currency


Add an SSD to Raspberry Pi 4 and turn it into a super-cooled NAS drive.

More HATs

Argon One

Enclose Raspberry Pi 4 inside this great case with custom I/O, cooling and GPIO

More cases on

Best Raspberry Pi Projects

How to use Raspberry PI as WOL (wake on lan) server

While you could wake up your PC from a mobile directly, having a dedicated server capable of doing so is the best solution. The reason is simple. You can hook up as many devices as you wish with a single endpoint. This is why Raspberry Pi is perfect for this.

Free wireless doorbell (Amazon Dash button hack)

The most terrifying situation I can imagine* is missing a parcel

Raspberry Pi NAS: (NAS-pi) Modding like a boss #part2

Plex and RAID1 NAS drive build log

MagPi – auto-downloader

Grab each edition of Mag Pi as soon as possible!


How to boot Raspberry Pi 4 from USB

How to set up and boot Raspberry Pi 4 from USB drive - headless guide.

Raspberry Pi Zero, Raspberry Pi 3A+ WiFi without keyboard or cables

Getting Raspberry Pi boards connected in seconds

Everything you need to start using JSON

It's JSON not Jason, just saying!

How to use Join App in NodeRED

The day finally comes where Join app is almost everywhere!

Driving LCD with Arduino and Raspberry Pi

Displaying things on an LCD screen is as easy as going through a cup of jellybeans while writing this tutorial!