D-0005
Jump to navigation
Jump to search
PIR Sensor
Description
PIR stands for Pyroelectic Infrared Radial Sensor or Passive Infrared Sensor.
PIR is an electronic sensor which detects the changes in the infrared light across certain distance and gives out an electrical signal at its output in response to a detected IR signal.
It can detect any infrared emitting object such as human beings or animals if it is the range of the sensor, or moves away from the range, or moves within the range of the sensor.
The PIR sensor module can be divided in to two parts an infrared sensitive crystal and the processing circuit.
Features
- Easy to assemble
- 5V signal
- Adjustable sensitivity
- Compatible with most MCU or Development Board
Specifications
Gallery
Package Includes
- 1 x PIR motion Sensor
How to build a circuit
- Connect Raspberry Pi GPIO to the PIR motion sensor as per the connection diagram below:
How to code in Python
- Typing following code to install RPi.GPIO python liberary.
sudo apt-get update sudo apt-get -y install python3-RPi.GPIO or sudo pip3 install RPi.GPIO
- Edit a file named: pir.py and copy following code and save it.
import RPi.GPIO as GPIO import time GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(11, GPIO.IN) #Read output from PIR motion sensor GPIO.setup(3, GPIO.OUT) #LED output pin while True: i=GPIO.input(11) if i==0: #When output from motion sensor is LOW print "No intruders",i GPIO.output(3, 0) #Turn OFF LED time.sleep(0.1) elif i==1: #When output from motion sensor is HIGH print "Intruder detected",i GPIO.output(3, 1) #Turn ON LED time.sleep(0.1)
- Run it in a terminal
python3 pir.py
Keywords
- PIR motion sensor, Raspberry Pi 4B, PIR