Software apps and online services
Hand tools and fabrication machines
There are lots of garage door monitor projects on hackster.io and other Maker sites. I wanted a project that would be extensible, to build on, for future IOT projects. Plus I wanted a platform that was well-documented and well-supported. Adafruit's cloud service for Makers, adafruit.io, fit the requirements.
In addition, I was motivated by personal need. My nice neighbors had, once too often, called late at night to remind me the garage door was open ;-)
This post appears in a longer form, discussing the "Maker's Journey".
This project's differences vs. Adafruit IFTTT Door Detector:
- GarageDoorMon doesn't use a battery, it's powered by a 5V wall adapter; you'll need a long wire from the door and place the Feather Huzzah near a mains power source
- Logic is reversed, a '1' is sent to adafruit.io when the garage door is OPEN, '0' when closed(SHUT)
- Added: raspberry pi zero W runs a system service to monitor the door status, shows on 4-digit display
- IFTTT is not required! Of course, you can use it if you like, in addition or instead.
- The pi zero W uses MQTT subscribe directly from adafruit.io feed, via python cllient code.
An Adafruit Feather Huzzah checks whether the garage door is open/shut via a magnetic switch, then sends the current status to an adafruit.io feed. Inside the house, a Raspberry Pi Zero W with a 4 digit alpha display subscribes to the feed via MQTT and displays the current status. You can also get a notification on your phone from IFTTT.Cost
There are two versions:
Option 1: About $20 USD, build an Adafruit Huzzah status checker and send Notifications to your phone with IFTTT (free, sign-up required)
Option 2: About $40 USD (includes Option 1 cost), build Option 1, and add an LED status display with a Raspberry Pi Zero WDifficulty
Easy. About 2-3 hours, depending on Options.Process
- sign up for an adafruit.io account, if you don't have one; create a feed for the garage door
- download the GarageDoorMonitor.ino from github
- solder up the Huzzah and personalize/upload the sketch GarageDoorMonitor.ino and config.h
- wire up your garage door with a magnetic switch and test that the feed is working
- set up IFTTT to monitor the feed
- download latest Raspbian and install on pi zero W
- on the pi zero W, git clone GarageDoorMon and install other software (especially Adafruit Python LED Backpack)
Use the Adafruit article at Using IFTTT with Adafruit.IO to Make an IOT Door Detector up through the Adafruit IO Setup section. Via links, this will walk you through signing up for adafruit.io and getting the project going. Create a feed called GarageDoor.
The Adafruit project is mounted on an interior door frame and is battery powered. Mine has the sensor on the garage door frame with long wires from the switch to position the Huzzah near a 5V wall power source. Mount the sensor on the garage door when the door is open, with the sensor aligned to its magnet.
How this works!
The magnetic switch/sensor is NO ("Normally Open") when away from the magnet. When the magnet is close enough, the switch will be "closed". The Adafruit Door Detector post expects an open door to be a rare event. The Adafruit Arduino code does no notification whatsoever if the door is closed!
Update September 2, 2020:
As of July, 2020 Adafruit has updated their security "fingerprint" for access to adafruit.io. This update is included in the Adafruit IO Arduino library, supplied in the Manage Libraries section of the Arduino IDE. You need at least version 3.7.0 installed.
The following talks about how the code works as written in the article. My code is different, and it reverses the logic so LOW (connect to GND/closed switch) is sent to the Huzzah pin for an open door!
How does the Huzzah detect an open or closed door? Magic!
Well, the magic of resistance. The magnetic switch is wired to GND and a pin that is "pulled up" by a significant resistance (10K Ohm) to a +V. If the switch is closed (in the presence of a magnet), there's little to NO resistance on the GND side, but high resistance on the pin side. Using the path of least resistance, this registers as a "LOW" condition and no notification.
But! If the door opens, and the sensor is pulled away from the magnet, the resistance on the GND side can be thought of as virtually "infinite". Since the resistance on the pin side (tied to +V) is something, but less than infinite, this registers as a "HIGH" condition. The code for door_open (and only door_open) runs and a feed to adafruit.io takes place.
See the great Adafruit tutorial on pullup/down resistors for more info.
There was a problem on my build - kept getting floating values even though a pullup resistor was set in code. I used an external pullup resistor network of 10K Ohm and 100 Ohm resistors on a protoboard - fixed that!The Adafruit code also uses a little trick to run periodically. All of the functional code is in the void setup routine - the main loop has no code! With wiring to the RST pin on the Huzzah, the setup routine resets based on the value (in seconds) of a SLEEP_LENGTH variable (3 seconds default). The setup routine runs each time reset is run - no need for loop code!
My Code - differences from Adafruit This Garage Monitor:
- Runs from wall power instead of battery - no battery charge checking code as in the Adafruit version
- Runs continuously from void loop, doesn't reset at timed intervals
- Sends a new feed value when the "state" (either OPEN/SHUT) changes
You should monitor your feed rate if you have an Adafruit free account - capped at max 10 feeds, 30 feeds a minute. The feed rate is much lower when you only send a feed on state change.
Why did I change the door logic in the code? Simple - the switch would be closer to the power source when open, less wire was needed to hook it up. Use the Arduino Code section from the article for set-up and loading the Huzzah, but load the Garage_Door_Monitor.ino sketch from github, with its required config.h file. Don't forget! Change the config.h file for your adafruit.io username and key and supply your wifi SSID and password.
Position the magnet and the sensor carefully on the garage door. You want the magnet and sensor to be aligned horizontally about 6mm apart when triggered. Place the sensor on a fixed part of the door, and the magnet on the moving door itself. Be careful that there are no obstructions when you operate the door that will dislodge the magnet. Set up your Huzzah per the instructions in the Adafruit article Wiring Section:
- Pin 13 to one side of door sensor
- GND to opposite side of door sensor
I soldered female jumper wires to the long wires. To connect to the Huzzah, use male-to-female jumpers - female to Huzzah, male to long wires. Test it by operating the door and monitoring your adafruit.io feeds from a web page
When the Huzzah and adafruit.io are working together, follow the instructions to set up IFTTT to adafruit.io. The Adafruit article sends an email message. The images below show how you can send a notification to your phone:
Step 1: Raspbian Stretch Lite
- Download Debian Stretch Lite
- Install to micro sd card. This is a good set of instructions.
- Two files need to be added to the /boot directory on the new sd image card.
On Windows, create an empty file called ssh and a file named wpa_supplicant.conf with the contents shown (second box) below.
sudo touch ssh
sudo nano wpa_supplicant.conf
And for Windows/Linux/Mac, enter and save the following, changing ssid and psk to your router's ssid and password:
ssid="Your network SSID"
psk="Your WPA/WPA2 security key"
After getting Raspbian configured, run headless (no monitor/keyboard/mouse) - insert the SD card into your pi and power up. Allow a couple of minutes for the pi to fully start up. If you are running Windows, download the putty terminal emulator to connect to the pi with SSH. You should be able to find the IP address from your router's web page. And, to SSH in from a Mac/Linux terminal:
ssh "192.168.0.xxx" -l pi
Where "192.168.0.xxx" = your pi's IP address (without quotes). The default password is raspberry. Be sure to change it on first login. You should also configure other settings, via:sudo raspi-config
- Network Options/Hostname (I named my host GarageMon)
- Localisation Options
- Advanced Options - Expand Filesystem
After completing the config, reboot. When you sign back in, update packages and set up git:
sudo apt-get update
sudo apt-get upgrade # This step takes a long time!
sudo apt-get install git-core
git clone http://github.com/thisoldgeek/GarageDoorMon
Cloning this github repository will create a new directory under /home/pi/GarageDoorMon. This GarageDoorMon directory contains all the assets needed for this project, including setup scripts and code.Do:
sudo shutdown -h now
Step 2: Display and System Service
- Connect display + (power) to Raspberry Pi 3.3V or 5V power (red wire). 5V is brighter but if you have other devices on the I2C bus its better to go with 3.3V
- Connect display - (ground) to Raspberry Pi ground (black wire).
- Connect display D (data/SDA) to Raspberry Pi SDA (orange wire).
- Connect display C (clock/SCL) to Raspberry Pi SCL (purple wire).
- If there's a Vi2c or IO pin, connect that to 3.3V as well
Power back up.
From a terminal connected to the raspberry pi zero W, run the following:
- Follow the Adafruit instructions for Usage to install software for the 14 segment display - scroll down a bit to find the sample script (alphanum4_test.py) to test the display under 14 Segment Alphanumeric Display
git clone http://github.com/thisoldgeek/GarageDoorMon
- Modify garage_mon.py for your adafruit.io username and key, using the nano editor on the pi; run it with python3 garage_mon.py and it should display STRT
chmod +x garage_mon.py
sudo cp garage_mon_service.txt /etc/systemd/system/gmon.service
sudo chmod 644 /etc/systemd/system/gmon.service
sudo systemctl enable gmon
The display will initially show STRT until there is a change in the data feed. After that, with a slight delay, it should display the current state - SHUT/OPEN.UPDATE: 12/15/2019
Added an optional buzzer on the display that beeps three times when OPEN state is first received. There is a default "quiet_time" function in the buzzer script - the buzzer will not sound between hours you set, currently between 21:00 and 09:00.
The new python script is named garage_mon_buzzer.py. Download this script and copy it like so:
sudo cp garage_mon_buzzer.py garage_mon.py
# Add the library:
sudo apt-get install python-rpi.gpio python3-rpi.gpio
Remember! Change username and AIO_Key in garage_mon.py after copying.
Use an active piezo buzzer, connect female-to-female jumpers:
- +/positive (usually longer pin) to BCM pin 17
- -/negative (shorter pin) to GND
sudo systemctl restart gmon # Restart the service