Mechatronics LAB
Published © MIT

https://mechatronicslabrpi. blogspot. com/2020/05/pir-motion-s

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

BeginnerProtip1 hour361
https://mechatronicslabrpi. blogspot. com/2020/05/pir-motion-s

Things used in this project

Story

Read more

Custom parts and enclosures

PIR Motion Sensor using Raspberry Pi4 | Interfacing Tutorial

Schematics

PIR Motion Sensor using Raspberry Pi4 | Interfacing Tutorial

Code

PIR Motion Sensor using Raspberry Pi4 | Interfacing Tutorial

Python
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()

Credits

Mechatronics LAB
75 projects • 45 followers
I am Sarful , I am a Mechatronics Engineer & also a teacher I am Interested in the evolution of technology in the automation industry .

Comments