How to Use a PIR Motion Sensor with Raspberry Pi | raspberry pi for beginners

Published: 02 March 2021
on channel: Rahul Jadhav
1,766
57

For any queries please contact me on whatsapp/email ::
Mob No :: 9922512017
Mail ID :: [email protected]

Code:
import RPi.GPIO as GPIO # Import Library to access GPIO PIN
import time # To access delay function
GPIO.setmode(GPIO.BOARD) # Consider complete raspberry-pi board
GPIO.setwarnings(False) # To avoid same PIN use warning
Relay_PIN = 11 # Define PIN for Relay
PIR_PIN = 7 # Define PIN for PIR Sensor
GPIO.setup(Relay_PIN,GPIO.OUT) # Set pin function as output
GPIO.setup(PIR_PIN,GPIO.IN) # Set pin function as input
while (1):
if GPIO.input(PIR_PIN) == GPIO.HIGH:
print "Bulb ON"
GPIO.output(Relay_PIN,GPIO.LOW) #Relay ON
else :
print "Bulb OFF"
GPIO.output(Relay_PIN,GPIO.HIGH) # Relay OFF


Watch video How to Use a PIR Motion Sensor with Raspberry Pi | raspberry pi for beginners online without registration, duration hours minute second in high quality. This video was added by user Rahul Jadhav 02 March 2021, don't forget to share it with your friends and acquaintances, it has been viewed on our site 1,766 once and liked it 57 people.