PIR Motion Detection Sensor
Welcome To Hackaholic and this is Raspberry pi Hack Series. In this video I will show you how to use PIR motion detection sensor.
How PIR Motion detection Sensor Works.
When it Detects the motion in the environment, the out pin value changes from low to high (Key point). We need to check for out value of pir sensor when its 1 (motion detected).
Lets see python Program: Copy the code and save it as pir_sensor.py
import sys import time import RPi.GPIO as gpio gpio.setwarnings(False) gpio.setmode(gpio.BOARD) gpio.setup(7,gpio.IN) def motion_detect(): try: while True: if gpio.input(7)==1: print "Motion Detected" except KeyboardInterrupt: gpio.cleanup() print "\n Terminated by User" sys.exit() if __name__ == "__main__": motion_detect()
Watch the video for setup. Enjoy Hackaholic