Introduction: Smart Garage Controller
This project came about when I would leave the house for work and get half way there, only to have a moment of panic set in where I could not remember if I had closed the garage door. Sometimes I was convinced I had not, and turned around, just to confirm I had indeed closed the garage door. Now I get to be 30 min late to work...great. Once I bought my own house, I figured now is when I can do whatever I want to my garage door opener, and this idea was born.
- Raspberry Pi - I think just about any model should work, as long as it can run Django, NGINX, and gunicorn. I used a Raspberry Pi 3 B+. You may need to change some things if you have a different version. - (https://www.adafruit.com/product/3775)
- microSD card (for
- 40-pin ribbon cable for GPIO pins - (https://www.adafruit.com/product/1988)
- 4-pin GPIO breakout board - (https://www.adafruit.com/product/2029)
- Opto-Isolated relay board rated for >20v DC - (https://www.amazon.com/gp/product/B07M88JRFY)
- Perma-Proto half-sized board - (https://www.adafruit.com/product/1609)
- hookup wire (~24-20 AWG) - (https://www.amazon.com/dp/B01LH1FYHO)
- Magnetic Reed Switch - (https://www.amazon.com/gp/product/B076GZDYD2)
- Raspberry Pi HDMI dust cover - (https://www.amazon.com/gp/product/B07P95RNVX)
- Raspberry Pi Ethernet dust cover - (https://www.amazon.com/gp/product/B01I814D0U)
- Raspberry Pi USB dust covers (4) - (https://www.amazon.com/gp/product/B074NVHTF9)
- Raspberry Pi power source (depending on the model of raspberry pi you are using)
- Raspberry Pi case - (https://www.amazon.com/gp/product/B07QPCPK8G)
- 3.5 mm jack - (https://www.amazon.com/gp/product/B00OGLCR3W)
- M2.5 screw/standoffs for mounting boards - (https://www.amazon.com/dp/B0721SP83Q)
- 18 AWG cable - (https://www.amazon.com/gp/product/B07TL9XK2K)
- 3mm clear acrylic - (https://www.amazon.com/gp/product/B07RY4X9L3)
- access to laser cutter
Step 1: Assemble RPi
write the microsd card with the latest raspbian image of your choice. (https://www.raspberrypi.org/documentation/installation/installing-images/) then assemble the board in the case, and attach the ribbon cable before securing the lid on the case. Then add the dust ports.
Step 2: Cut and Assemble Control Box
You'll need to find a place that will let you cut out your box on a laser cutter, look for a local makerspace or online for places that can cut acrylic. Alternatively, you can probably use any other kind of project box with the proper. Be sure to add a 330 Ohm resistor between 3.3v line and the COM terminal of the reed switch. N.O. terminal goes back to GPIO pin of choice.
Wire the relay with 5v going to DC+, GND to DC-, and GPIO pin of choice to IN.
Garage door opener terminals will go connected to the relay at COM and NO
Step 3: Mount Reed Switches and Run Cable
Make sure your cable does not impede the travel of your door. Wire to the same two screws that your wall buttons connect to to open the door.
Step 4: Connect Your Raspberry Pi to Your Wifi
and make sure you can SSH to your raspberry pi so you can setup the web server. you can then mount it in your garage and the rest can be done from your computer.
Step 5: Install and Configure Software
on the Raspberry Pi, install Django with commands:
- `sudo apt update`
- `sudo apt install python3-pip`
- `sudo pip3 install django`
Then install NGINX and gunicorn
- `sudo apt install nginx`
- `sudo pip3 install gunicorn`
Install the python module create a django project, create migrations, and configure settings.py
- copy the tarball to /srv
- install using `sudo pip3 install django-smart-carhole-0.1.tar.gz`
- create django project with `sudo django-admin startproject my_smart_garage`
edit the settings.py file found at /srv/my_smart_garage/my_smart_garage/setting.py
add the IP address of the raspberry pi or its hostname in ALLOWED_HOSTS
add 'door_control', to the INSTALLED_APPS list
Edit TIME_ZONE to your time zone
Add the following settings to the end of the file: RPI_SENSOR_PIN, RPI_RELAY_PIN, IP_WHITELIST_DOORCONTROL and fill out with it's respective values. See images for examples.
Add "path('door_control/', include('door_control.urls'))," to the /srv/my_smart_garage/my_smart_garage/urls.py in the urlpatterns list
add ', include' to the import line at the top for django.urls library. See images for examples.
migrate the app with 'sudo python3 manage.py migrate'
test to make sure things work by running the test server with: `python3 manage.py runserver 0.0.0.0:8000`
Navigate to your raspberry pi like so: http://[ipaddress]:8000/door_control
You should be met with a page like shown.
Now it's time to set it up so the web server runs automatically.
- First disable debug mode in the setting.py file
- uncomment the server_names_hash_bucket_size 64 in /etc/nginx/nginx.conf
- copy the gunicorn file to /etc/systemd/system/gunicorn.service
- copy the nginx file to /etc/nginx/conf.d/smart_carhole.conf
- start both processes
- systemctl enable gunicorn.service
- systemctl start gunicorn.service
- systemctl enable nginx.service