D-0005: Difference between revisions

From 52Pi Wiki
Jump to navigation Jump to search
(Created page with "==PIR Sensor== ==Description== PIR sensor called: PIR motion sensor.<br> PIR stands for passive infrared. This motion sensor consists of a fresnel lens, an infrared detector,...")
 
Line 20: Line 20:
==How to build a circuit==
==How to build a circuit==
* Connect Raspberry Pi GPIO to the PIR motion sensor as per the connection diagram below:
* Connect Raspberry Pi GPIO to the PIR motion sensor as per the connection diagram below:
[[File:Pirdiagram.jpg|left|800px]]
[[File:Pirdiagram.jpg|left|500px]]
<br style="clear:both;">
<br style="clear:both;">
==How to code in Python==
==How to code in Python==
* Typing following code to install RPi.GPIO python liberary.
* Typing following code to install RPi.GPIO python liberary.

Revision as of 17:51, 18 March 2020

PIR Sensor

Description

PIR sensor called: PIR motion sensor.
PIR stands for passive infrared. This motion sensor consists of a fresnel lens, an infrared detector, and supporting detection circuitry.
The lens on the sensor focuses any infrared radiation present around it toward the infrared detector.
Our bodies generate infrared heat, and as a result, this heat is picked up by the motion sensor.
The sensor outputs a 5V signal for a period of one minute as soon as it detects the presence of a person.
It offers a tentative range of detection of about 6–7 meters and is highly sensitive.
When the PIR motion sensor detects a person, it outputs a 5V signal to the Raspberry Pi through its GPIO and we define what the Raspberry Pi should do as it detects an intruder through the Python coding.

Features

  • Easy to assemble
  • 5V signal
  • Adjustable sensitivity
  • Compatible with most MCU or Development Board

Specifications

Gallery

Package Includes

How to build a circuit

  • Connect Raspberry Pi GPIO to the PIR motion sensor as per the connection diagram below:
Pirdiagram.jpg


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