D-0005: Difference between revisions

From 52Pi Wiki
Jump to navigation Jump to search
Line 35: Line 35:
import RPi.GPIO as GPIO
import RPi.GPIO as GPIO
import time
import time
GPIO.setwarnings(False)
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setmode(GPIO.BOARD)
Line 40: Line 41:
GPIO.setup(3, GPIO.OUT)        #LED output pin
GPIO.setup(3, GPIO.OUT)        #LED output pin
while True:
while True:
i=GPIO.input(11)
    i=GPIO.input(11)
if i==0:                #When output from motion sensor is LOW
    if i==0:                #When output from motion sensor is LOW
print "No intruders",i
        print "No intruders",i
GPIO.output(3, 0)  #Turn OFF LED
        GPIO.output(3, 0)  #Turn OFF LED
time.sleep(0.1)
        time.sleep(0.1)
elif i==1:              #When output from motion sensor is HIGH
    elif i==1:              #When output from motion sensor is HIGH
print "Intruder detected",i
        print "Intruder detected",i
GPIO.output(3, 1)  #Turn ON LED
        GPIO.output(3, 1)  #Turn ON LED
time.sleep(0.1)
        time.sleep(0.1)
</pre>
</pre>
* Run it in a terminal
* Run it in a terminal
Line 54: Line 55:
python3 pir.py
python3 pir.py
</pre>
</pre>
==Keywords==
==Keywords==

Revision as of 17:53, 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