-
Notifications
You must be signed in to change notification settings - Fork 1
/
BirdSweeper.py
57 lines (49 loc) · 1.39 KB
/
BirdSweeper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# the following program is provided by DevMiser - https://github.com/DevMiser
from picamera import PiCamera
import time
import RPi.GPIO as GPIO
from subprocess import call
# Pins definitions
sensor_pin = 22
servo_pin = 18
relay_pin = 25
# Set up pins
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(sensor_pin, GPIO.IN, GPIO.PUD_DOWN)
GPIO.setup(servo_pin, GPIO.OUT)
GPIO.setup(relay_pin, GPIO.OUT)
# Set pulse width modulation (PWM) frequency
frequency = 50
# Remember the current and previous button states
current_state = False
prev_state = False
def servo_move():
servo = GPIO.PWM(servo_pin, frequency)
servo.start(8.5)
sweep = 1
while sweep <= 1:
servo.ChangeDutyCycle(7.3)
time.sleep(0.5)
servo.ChangeDutyCycle(8.5)
time.sleep(0.5)
sweep = sweep + 1
print ("sweep activated")
servo.stop()
try:
while True:
current_state = GPIO.input(sensor_pin)
if (current_state == True) and (prev_state == False):
moment = time.ctime()
print("motion detected at: %s" % moment)
GPIO.output(relay_pin,GPIO.HIGH)
time.sleep(2)
servo_move()
time.sleep(1)
GPIO.output(relay_pin,GPIO.LOW)
time.sleep(1)
prev_state = current_state
time.sleep(1)
# When ctrl+c is pressed, this will be called
finally:
GPIO.cleanup()