Creation repo sue RPi3

This commit is contained in:
Bruno 21
2019-02-04 10:14:50 +01:00
commit fb93c53f4f
31 changed files with 659 additions and 0 deletions

35
pir/pir.py Executable file
View File

@@ -0,0 +1,35 @@
# MBTechWorks.com 2017
# Use an HC-SR501 PIR to detect motion (infrared)
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD) #Set GPIO to pin numbering
pir = 8 #Assign pin 8 to PIR
led = 10 #Assign pin 10 to LED
GPIO.setup(pir, GPIO.IN) #Setup GPIO pin PIR as input
GPIO.setup(led, GPIO.OUT) #Setup GPIO pin for LED as output
print ("Sensor initializing . . .")
time.sleep(2) #Give sensor time to startup
print ("Active")
print ("Press Ctrl+c to end program")
try:
while True:
if GPIO.input(pir) == True: #If PIR pin goes high, motion is detected
print ("Motion Detected!")
GPIO.output(led, True) #Turn on LED
time.sleep(4) #Keep LED on for 4 seconds
GPIO.output(led, False) #Turn off LED
time.sleep(0.1)
except KeyboardInterrupt: #Ctrl+c
pass #Do nothing, continue to finally
finally:
GPIO.output(led, False) #Turn off LED in case left on
GPIO.cleanup() #reset all GPIO
print ("Program ended")

43
pir/pir2.py Normal file
View File

@@ -0,0 +1,43 @@
# MBTechWorks.com 2017
# Use an HC-SR501 PIR to detect motion (infrared)
#!/usr/bin/python
import RPi.GPIO as GPIO
import time, datetime
GPIO.setmode(GPIO.BOARD) #Set GPIO to pin numbering
pir = 8 #Assign pin 8 to PIR
led = 10 #Assign pin 10 to LED
GPIO.setup(pir, GPIO.IN) #Setup GPIO pin PIR as input
GPIO.setup(led, GPIO.OUT) #Setup GPIO pin for LED as output
print ("Sensor initializing . . .")
time.sleep(2) #Give sensor time to startup
print ("Active")
print ("Press Ctrl+c to end program")
# Function to create new Filename from date and time
def getFileName():
return datetime.datetime.now().strftime("%Y-%m-%d_%H.%M.%S.jpg")
try:
while True:
if GPIO.input(pir) == True: #If PIR pin goes high, motion is detected
print ("Motion Detected!")
GPIO.output(led, True) #Turn on LED
time.sleep(4) #Keep LED on for 4 seconds
GPIO.output(led, False) #Turn off LED
time.sleep(0.1)
filename = getFileName()
print(filename)
except KeyboardInterrupt: #Ctrl+c
pass #Do nothing, continue to finally
finally:
GPIO.output(led, False) #Turn off LED in case left on
GPIO.cleanup() #reset all GPIO
print ("Program ended")