I am working on a Raspberry Pi garage door opener. I have the base code written so far, but I am looking to add one more thing in, but I'm not sure how to. For those of you who don't know, the Raspberry Pi has GPIO pins that can be set using Python scripts. I am using a script that sets a GPIO pin to high (5 volt output), staying on for 0.5 seconds, and then to low. The output is connected to a relay which is then connected to my garage door.
What I want to do is use the other GPIO pin to trigger an alarm for 2 seconds, and then set the state of the first GPIO pin to high, therefore opening the door. Here is what I have so far.
#!/usr/bin/python
# Import required Python libraries
import RPi.GPIO as GPIO
import time
# Use BCM GPIO references instead of physical pin numbers
GPIO.setmode(GPIO.BCM)
# init list with pin numbers
pinList = [2]
# loop through pins and set mode and state to 'low'
for i in pinList:
GPIO.setup(i, GPIO.OUT)
GPIO.output(i, GPIO.HIGH)
def trigger() :
for i in pinList:
GPIO.output(i, GPIO.LOW)
time.sleep(0.5)
GPIO.output(i, GPIO.HIGH)
GPIO.cleanup()
try:
trigger()
except KeyboardInterrupt:
print " Quit"
# Reset GPIO settings
GPIO.cleanup()
Can anyone help me figure out how to add another GPIO pin to trigger for 2 seconds, and THEN trigger the main relay to open the door?