Back to Browse

Raspberry Pi Workshop Kit Tutorials - 9 Passive Infrared Sensor

1.9K views
Jun 15, 2017
6:09

Welcome to the Raspberry Pi Workshop Tutorials, brought to you by ModMyPi, BuyaPi.ca, and PiShop.us. In this series, we’ll demonstrate nine projects that can be made using the YouTube Workshop Kit for Raspberry Pi. These projects are a great way to familiarize yourself with the Pi’s input and output functions, as well as creating programs in Python that we’ll use to control the Pi’s hardware. Tutorial 9 - Passive Infrared Sensor Circuit Diagram: http://www.modmypi.com/download/led_button_buzzer_temp_ldr_pir_bb.png Tutorial 9 Download: http://www.modmypi.com/download/youtube_workshop_9_pir.pdf View Tutorial Online: https://www.modmypi.com/blog/youtube-workshop-kit/gpio-and-python-99-pir *** Code Used In This Tutorial *** #!/usr/bin/python import RPi.GPIO as GPIO from time import sleep GPIO.setmode(GPIO.BCM) GPIO.setup(27,GPIO.OUT) GPIO_PIR = 7 print "PIR Module Test (CTRL-C to exit)" # Set pin as input GPIO.setup(GPIO_PIR,GPIO.IN) Current_State = 0 Previous_State = 0 try: print "Waiting for PIR to settle ..." # Loop until PIR output is 0 while GPIO.input(GPIO_PIR)==1: Current_State = 0 print " Ready" # Loop until users quits with CTRL-C while True : # Read PIR state Current_State = GPIO.input(GPIO_PIR) if Current_State==1 and Previous_State==0: # PIR is triggered print " Motion detected!" # Record previous state GPIO.output(27,GPIO.HIGH) sleep(1) GPIO.output(27,GPIO.LOW) Previous_State=1 elif Current_State==0 and Previous_State==1: # PIR has returned to ready state print " Ready" Previous_State=0 # Wait for 10 milliseconds sleep(0.01) # clean up gpio pins when we exit the script except KeyboardInterrupt: print " Quit" # Reset GPIO settings GPIO.cleanup()

Download

0 formats

No download links available.

Raspberry Pi Workshop Kit Tutorials - 9 Passive Infrared Sensor | NatokHD