Oh yeah, another garage door opener project! After introducing myself to the world Arduino IDE programming I searched for a project to keep me busy during the winter months. I'm an avid bicyclist and it's tough trying to ride through the cold and snow. One idea that came to mind was some sort of monitor to determine if the garage door was open or closed. Many a time my wife and I, after leaving to go on an errand, have returned home to check if we closed the garage door. Besides that we have left the door open all night, inviting critters into my garage, dining in my garbage can.
I originally purchased an Arduino Uno Wifi board to do the job. It would connect wireless with my PC but after many attempts and working with the very helpful tech people I could not get it to connect with any of the smart phone apps available. In my opinion, the Arduino Uno Wifi is a lemon. After some research I decided to buy a Particle Photon and have been very pleased with its performance and ease of setup. The Blynk app was also easy to install and set up. The Blynk app seems to have the desired internet security and ease of use.
I researched other garage door projects and came up with the following features:
- Open and close the garage door remotely.
- Know the current status of the door (is it open, closed or stuck halfway open). The solution is to use two magnetic door (reed) switches attached to the door and frame. One switch to determine proof of being closed and the other proof of being opened. I looked at using the HC SR04 ultrasonic module but it would not provide a definite proof of the door status. The door could get stuck halfway and the HC-SR04 would sense the door position incorrectly.
- Avoid the accidental opening/closing of the door after recovery from a power loss. A number of projects and personal experimentation determined this is a problem. The solution I got from other projects was to use two relays, one hooked normally open and the other normally closed.
- Prevent accidental opening/closing of the door via 'butt dialing' or stray touching the Blynk app. This could be accomplished by using another (third) relay as a lock out (safety) device, requiring the user to push in succession two buttons on the app instead of one.
- Notification if the door is open at night or if it gets stuck halfway open.
- History log of door activity. Nice to know what time you left the house for a day trip to determine travel time.
While I was at it and had the hardware, add a gas sensor and a temperature/humidity sensor.
Setting up the Photon was a piece of cake. The instructions to do this were easy to follow. https://docs.particle.io/guide/getting-started/intro/photon/. I used Particle build for the coding. Over the air downloading of code is the way to go!
Again, easy to set up, excellent instructions. Go to http://www.blynk.cc/getting-started/. You will need to download the app on your smart phone, get the auth token and install the Blynk library.
You will need to determine which two terminals on your garage door opener to jump. It should be the same two terminals used by the wall button currently being used. I installed one of the magnetic door switches on the side of the door for proof of being open and the other at the center of the door under the garage door rail for proof of being closed. After using it for a few days the magnetic switches would not work properly. Apparently the final door location is not exactly the same every time. To remedy the situation I purchased some magnets from Harbor Freight and installed them next or in place of the small magnet used in the door switch.
As mentioned I used the Particle build IDE. The code is attached and has been commented extensively. I tried to simplify the code but it still a bit complicated. I am wondering if it could be simplified. Any comments for improvement will be welcomed.
Using delays in the loop function will cause the Blynk app to disconnect and reconnect endlessly. You need to use timers for Blynk and the Photon to interact properly.
Once the code is downloaded the Photon will send to the Blynk app the door status (open,closed,halfway) every second. The temperature, humidity, WiFi strength and gas concentration is sent once a minute. The Photon clock time is updated once a day.
Please note in the code (line 109) where relay #3, the lockout relay, is set to low when the door is 'halfway' (i.e. both magnetic switches are low). This is to allow operation of your wall switch. If relay #3 is high the wall switch will not work.
The Fritzing is attached. I did not include the YwRobot MB 102 power supply module. I discovered a need for a better power supply when the relays were not reliable after the addition of the MQ2 sensor. Relatively speaking the MQ2 sensor is a power hog and the phone style USB power supply I used did not have the oomph. You will need a 6.5-12V power supply for the MB 102. I got the power supply for the MB 102 from Goodwill for $0.99 . Be sure to check the output voltage (center barrel positive) of the power supply before using it. I got one where the label stated 9V output and it measured 12.7V. There is a great write up on the MB 102 by Peter Vis. Also, before connecting the Photon to the MB 102, check the output of the MB 102. You never know.... http://www.petervis.com/Raspberry_PI/Breadboard_Power_Supply/YwRobot_Breadboard_Power_Supply.html
Another issue was the WiFi connection. My wireless router is about as far away from the garage as possible. This caused the connection to be tenuous at best. Luckily I had a Netgear Powerline AV500 Adapter and XWN 5001 Access Point that was not being used (got it for the wife so she could watch Netflix while working out on the treadmill- used twice). It uses X-10 technology to send the Ethernet through your electrical power lines. This worked out well since the power for the opener is 3 feet away.
The case surrounding the Photon is a work of art. My 32 year old son left behind a box of Legos. Needless to say it was fun building the case out of Legos. And yes, my wife got PO'ed when she stepped on one with her bare feet. A clear cover is needed to finish it up.
Open/Closing: In the Blynk app I have two buttons labeled 'Locked' and 'Off'. To operate the door you need to first press the 'Locked' button, then press the 'Off' button. Pressing the 'Off' button with the 'Locked' button reading locked will not open the door. This should minimize any unintentional opening or 'butt dialing' of the app.
- Notifications: The Blynk app will send a notification to your phone if the door is halfway open for more than 10 minutes, or open during the night.
- History Graph: A chart displays the history of the door activity, temperature, humidity and WiFi signal from the last hour to the previous 3 months.
- History: The terminal screen will display the last 25 times the door was activated by Blynk, the remote or the wall button plus any notifications.
Fix the DHT 11 sensor. The DHT 11 sensor will send a crazy high temperature and crazy low humidity reading at random times. You can see this in the screen shot above. It did this with and without the YwRobot power supply and MQ2. Any suggestions for a fix would be appreciated.
Develop code to revert the 'Lock' button from unlocked status to locked status if the button is left in the unlocked state for a specified time.
Notification if the door is open for a specified period when the ambient temperature is below freezing to prevent frozen water pipes in the garage. This would involve adding webhooks to a weather web site.
Rather than using a fixed start and stop time for the door open notification, use a webhook to get the daily times for sunrise and sunset.
Improve security by moving the data collection from the Blynk server to my own Raspberry Pi server.
The MQ2 gas sensor needs to be calibrated. Sandbox Electronics has an excellent description of the sensor. Follow this up with notification if the gas sensor reads high (I have a gas water heater and furnace). http://sandboxelectronics.com/?p=165