Earn Maker Points on Every Order! Learn More!

PIR Sensor with Raspberry Pi

Back to Blog
PIR Sensor with Raspberry Pi - PIR Sensor with Raspberry Pi - PIR Sensor with Raspberry Pi - PIR Sensor with Raspberry Pi

PIR Sensor with Raspberry Pi

PIR Sensor is a passive infrared sensor which senses IR (Infrared) emitted by humans (all objects emit a certain amount of IR). A hotter object emits more IR than a colder one.

The PIR Sensor is also called as Pyroelectric IR Sensor, Passive Infrared Sensor or IR Motion Sensor. The applications of PIR are Burglar Alarm, Motion detected Floor Lamps, Automatic Door Open System and more.

The PIR Works on a change in the difference of IR Levels on the two Layers of its Lens. Means, the sensor (Inside the round metal with a rectangular crystal in the center) is split into two half on the Lens Area, where signals are opposite to each other.

In default condition on the two layers, the difference in two signal will cancel each other and don’t trigger any output. When a human crosses, the variation of IR levels in PIR output’s a trigger. This trigger signal is then processed and output the signal by an IC on the PIR Module.

PIR-Sensor-WorkingNote: The sensitivity and delay time of the sensor can be adjusted on the module by the two potentiometers on it.

Sensitivity: The sensitivity determines the Range of the Sensor. It ranges from 3 to 5 meters.

Delay Time: It determines how long the output of the PIR Sensor remains HIGH.

In this project, we will see how to use PIR Sensor with Raspberry Pi and will light up an LED (You can use buzzer alternatively).

We will write a python code to detect a human presence and turn ON an LED during the trigger time. So whenever a human presence is detected the PIR Sensor will output a HIGH Signal (+5v or +3.3v). According to the delay time we set on PIR Sensor the LED will turn ON during that period. When no human presence is detected the PIR Sensor output’s a LOW Signal.

Circuit Diagram:

PIR Sensor with Raspbberry Pi_bb


import RPi.GPIO as GPIO

import time



GPIO.setup(11, GPIO.IN)         #PIR sensor as INPUT

GPIO.setup(3, GPIO.OUT)         #LED as OUTPUT

while True:


if sens==0:                 #When output from motion sensor is LOW

print "No intruders",sens

GPIO.output(3, 0)  #Turn OFF LED


elif sens==1:               #When output from motion sensor is HIGH

print "Intruder detected",sens

GPIO.output(3, 1)  #Turn ON LED


Steps to Run our Python Program:

Step 1:

On the desktop, right click and create a text document. Name it as ‘PIRtest.py’ and save.

Step 2:

Now open terminal, type ‘cd Desktop’ to navigate to the desktop.

cd Desktop

Step 3:

Open the file in nano editor by using the command,

nano PIRtest.py

It will open the file, copy paste the code given above and save it by pressing Ctrl+X. And type y to save it.

Step 4:

Once everything is setup, run the file using the command

python PIRtest.py

Wave your hands in front of PIR Sensor. You can able to see the light will Turn ON according to the time delay set on PIR. Similarly, the print command will display the result on the screen.

Share this post

Leave a Reply

Back to Blog