Python Code - notkevinjohn/PiGarageDoor GitHub Wiki

This is the code that actually runs on the Raspberry Pi to control the relay that opens and closes the door. We will use ssh to trigger this script from a remote device. This script will be saved in the home folder of the Raspberry Pi (/home/pi/).

the first line is called a 'shebang' its a comment that tells the linux on our Pi that it should execute this script with python. Next we import a couple of libraries, the first one is the Rpi.GPIO library, which knows how to do things like turn pins on and off. We also import the time library which knows how to do things like wait for a predetermined time.

After this, we specify that we will be controlling the device attached to pin 17. This is the pin to which we attach the input line of our relay.

The next line specifies we will be using the Broadcom chip for our GPIO controller. The line after that tells the Raspberry Pi not to give us warnings about our GPIO code. Finally, we specify that pin 17 is going to be used as an output pin that we can drive high or low, and not an input pin which we can measure if its being driven high or low.

The last part of the code is the most important. Here we turn the pin on, wait 1 second, and turn it off. This is equivalent to holding down the physical button that controls your current garage door for 1 second, and then letting it up.