Beginner’s Guide to Raspberry Pi Garage Door Opener

When I was a kid, I was supposed to open and close my dad’s garage door manually so that he can move in or out his car. But since the first Raspberry Pi launched in 2012, I started tinkering to make an automatic garage door opener using my Pi board and smartphone together. Today, I will discuss the same with you.

Raspberry Pi Garage Door Opener

First of all, let’s see which things you should need to create an automatic garage door opener using Raspberry Pi.

  • A suitable Raspberry Pi starter kit (I used CanaKit Raspberry Pi kit)
  • Protective case to save your Pi board from any accidental damage
  • Two-channel relay
  • A compatible USB WiFi adapter or an Ethernet cable (as per your preference)
  • Jumper wires (female to female)
  • Micro SD card of 4GB or higher
  • Micro USB charger
  • Raspbian OS
  • USB keyboard and mouse
  • One 10K and one 1K Ohm resistor

Other optional things like magnetic switch to check the door is open or closed, USB to serial TTL adapter if you are having serial connections or anything else depending on your skills and requirements

Software setup

The first and one of the essential things is to install the Raspbian OS on the micro SD card. It is the official and of the best Operating Systems for Raspberry Pi. You can take help of NOOBS to make this process easier and quicker. Download the image of the Official Raspbian OS which is around 800MB.

After installing the OS, connect your Raspberry Pi to a keyboard, mouse and hook it up to a monitor. I used Wheezy, and I assume that you will use it too. When you boot the OS for the first time, the configuration rasp-confg will run automatically. Enable the ssh in the advanced menu option. If you are using an SD card with less capacity, you can remove GUI packages depending on X11 to free up some space.

If you want to use the serial interface with the help of USB to serial TTL adapter, then install appropriate drivers for it and assign a COM port on the PCB board. Connect the TX and RX cable to your Raspberry Pi as it uses USB connection for power. After doing this, take the necessary wiring actions to complete the setup.

Now setup the WiFi adapter using commands.

If you want to use an Ethernet cable for the connection with your Pi, then you can skip this. But if you want to operate it wirelessly, then follow the instructions below.

Step-1: First, power up the Raspberry Pi without attaching the WiFi adapter to it. The Ethernet NIC should be connected to the network through an Ethernet cable to access the headless device.

Step-2: Now access the remote terminal prompt by connecting your Pi through ssh and enter the command:

sudo nano /etc/network/interfaces

Step-3: For enabling a WiFi dongle, in the nano text editor, add the command written below the three lines showing the iface setup:

allow-hotplug wlan0

iface wlan0 inet manual

address (your IP)

netmask (assigned network address)

gateway (system gateway)

wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface default inet dhcp

Step-4: Save the file by pressing Ctrl + X and exit the nano editor. When prompted again, enter the below command:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Step-5: Depending on your current WiFi node configuration, edit and add the code as shown below:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev



ssid=“enter your SSID”

psk=“enter your password”

proto=WPA (for WPA1) or RSN (for WPA2)


pairwise=CCMP (for WPA2) or TKIP (for WPA1)



Step-6: Again press Ctrl + X to save the file and then exit the editor.

Step-7: Remove the Ethernet cable and plug in the USB WiFi adapter.

Step-8: Enter the below command in the command prompt:

Sudo reboot

When your device reboots, it will be automatically enabled for using a wireless connection. If you are facing the problem using the WiFi, then connect the Ethernet cable again and double check all the configuration.

After enabling the WiFi, install the other necessary software for your Raspberry Pi. If you are a Ubuntu user, type ssh pi@(IP address of your Pi) in the terminal and if you are using the Windows OS version, the use Putty. For the Wheezy crazies, the default password is ‘raspberry.’

When you logged in, install the WebIOPi by following the WebIOPi installation guide and make sure that it is running successfully. Now install PHP and Apache by writing the below commands in the editor:

$ sudo apt-get update

$ sudo apt-get install apache2 php5 libapache2-mod-php5

This will turn your Raspberry Pi into a web server. You can check this by typing in your Pi’s IP address in your web browser and if the default website of Apache is seen, means it’s fine!

Now, install the garage door controller application. You can use your preferred resource for it as there are some couple of good options available on the web for this. Download the Filezilla, in the ssh terminal, write below commands:

$ ssh pi@(Pi’s IP address)

$ sudo chown –R pi:root /var/www

Now in Filezilla, log in by entering the hostname, username as ‘pi’ and password as ‘raspberry.’

After this, upload the files from the application to /var/www. And delete the index.html file which already exists.

Note: If you are using the latest Chrome version on your Android or having an iPhone, then this will work like an application on it and you do not need to run the browser for that. Just make sure you are connected with your home WiFi at that time.

Hardware setup

Use the jumper wires to connect your Raspberry Pi board with the relay. The GPIO pins on the Pi make it able to communicate with other peripheral devices. I used GPIO4 to finish the setup. You can use your preferable pin out but make sure to do changes in the code accordingly.

You may know or not, but when the signal in the relay is OFF then the circuit stays on, and when the signal is ON, then the circuit is off. So, when the Pi loses its power, the safety mechanism of relay keeps the circuit offline. This sometimes means in the morning; the garage door opens automatically when you get out of your bed!

To avoid this situation, I tinkered with the code and actually able to make it right. To make the relay stay off after initialization, before setting the GPIO mode, set the GPIO pin to ON by doing gpio write 4 1. You should remember that without writing the command (gpio mode 4 out), the relay will not initialize.

Write the script at startup;

$ ssh pi@(your Pi’s IP)

$ sudo nano /etc/init.d/garagedelay

When prompted by your device system, write the needed functions

Case “$1” in


echo “Starting Relay”

/usr/local/bin/gpio write 4 1

/usr/local/bin/gpio mode 4 out



echo “stopping GPIO”



echo “Usage: /etc/init.d/garagedelay {start|stop}”

exit 1



exit 0

$ sudo chmod 777 /etc/init.d/garagerelay

$ sudo update-rc.d –f garagedelay start 7

That’s it!

Connect your Raspberry Pi with Garage Motor

You can assign this task to your kid too! He will easily attach the Pi with garage motor by following the wires on the button and can also connect the relay exactly like that. Don’t worry about the direction, because the relay will isolate the circuit.


You have made the garage door opener powered by Raspberry Pi! Go, test, and enjoy your day. I hope this will work for you. Let me know in the comments below.

Jessica Ward

Hey! I am Jessica Ward. I love to write about technology and learn or thinking about latest techno. And my forever ever love technology project is Raspberry Pi. I do and know more or more for Raspberry Pi.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button