PIR Motion Sensor using Raspberry Pi | Interfacing Tutorial
Today in this project I will show you how to interface PIR sensor using Raspberry Pi ,when the PIR Sensor detects any human motion, a buzzer is activated with a Relay Activate For this project you have to need know about PIR sensor and Raspberry Pi What is is PIR sensor: PIR sensors allow you to sense motion, almost always used to detect whether a human has moved in or out of the sensors range. They are small, inexpensive, low-power, easy to use and don't wear out. For that reason they are commonly found in appliances and gadgets used in homes or businesses. They are often referred to as PIR, "Passive Infrared", "Pyroelectric", or "IR motion" sensors
what is Raspberry : The Raspberry Pi is a low cost, credit-card sized computer that plugs into a computer monitor or TV, and uses a standard keyboard and mouse. It is a capable little device that enables people of all ages to explore computing, and to learn how to program in languages like Scratch and Python. It’s capable of doing everything you’d expect a desktop computer to do, from browsing the internet and playing high-definition video, to making spreadsheets, word-processing, and playing games. What’s more, the Raspberry Pi has the ability to interact with the outside world, and has been used in a wide array of digital maker projects, from music machines and parent detectors to weather stations and tweeting birdhouses with infra-red cameras. We want to see the Raspberry Pi being used by kids all over the world to learn to program and understand how computers work
Connect the VCC and GND pins of the PIR Motion Sensor to +5V and GND pins of the Raspberry Pi. Connect the DATA Pin of the PIR Sensor to GPIO24 of the Raspberry Pi. A 5V Buzzer is connected to GPIO20 i.e. and BC547 base Connected toGPIO 21 and Emitter Connected to GND and Collector connected to relay signal pin of the Raspberry Pi. The other pin of the buzzer and LED is connected to GND.
Code
The Programming part of the project is implemented using Python. The following is the Python Script for the PIR Motion Sensor using Raspberry Pi
import RPi.GPIO as GPIO
import time
sensor = 24
buzzer = 20
relay=21
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(sensor,GPIO.IN)
GPIO.setup(buzzer,GPIO.OUT)
GPIO.setup(relay,GPIO.OUT)
print ("Initialzing PIR Sensor......")
time.sleep(5)
print ("PIR Ready...")
print (" ")
try:
while True:
if GPIO.input(sensor):
GPIO.output(buzzer,True)
GPIO.output(relay,True)
print ("Motion Detected")
while GPIO.input(sensor):
time.sleep(0.2)
else:
GPIO.output(buzzer,False)
GPIO.output(relay,False)
print ("Motion Not Detected")
except KeyboardInterrupt:
GPIO.cleanup()
No comments