In this tutorial we will be integrating If This Then That(IFTTT) into our smart garage setup and with it create a smart garage door opener that can be controlled by a mobile phone.
Knowing how to control devices like a garage door opener from a mobile device has huge implications. Imagine for a second you had to suddenly leave the house and forgot you had food on the stove cooking. If the stove were hooked up to an embedded system you could receive a notification when you get far away from the your home that the stove is still on and turn off the stove from a remote location. Also think about how useful being able to control your garage from anywhere could be. You could let your kids into the house even if you’re not home. You could set up a geofence to automatically close the door if you forget and start driving away. The possibilists here are endless.
What is IFTTT?
The number of technologies that exist in the world continues to increase and IFTTT is dedicated to making all that tech work together in harmony. For example, phone might be made by Apple and your TV by Samsung. IFTTT makes it so that you can control the TV through your Apple device. For the more advanced, IFTTT allows you to call the API that devices have and connect those to other devices’ APIs.
How does the Relay Work?
The way we integrate our cell phone into our smart garage setup is fairly simple to understand. The IFFTT app is going to use what’s called a webbooks to alert a server to open the garage door and the relay will be listening to that server and toggle the state of the garage.
- Wemos Relay Shield
- Wemos Micro Controller
- Arduino D1 Mini
- Mobile Device (preferably phone)
Let’s start by getting setting up the external software.
- Go to adafruit.io and create an account
- Navigate to “IO” tab and find “Feeds”
- Select create new feed and call it garageTrigger
- In the settings make sure that the feed is public and not private
- Go to IFTTT.com and setup an account
- Select create widget
- In the IF This section find the “Button Pressed Wiget”
- You could also do google assistant voice commands, geofence, etc.
- In the Then That section search for Adafruit
- When prompted to connect your account click connect
- You should be redirected to Adafruit.io where you should authorize the connection
- Now back in the IFTTT you should have a window showing multiple adafruit options, we want to send data to Adafruit
- Once you find that option you should see a screen like this
- Use the drop down menu to find the garageTrigger feed and select it
- The data to save to the feed is just the number “1”
- Hit add ingredient and lets move on to setting up the relay.
- grab your breadboard, wires, arduino and relay
- Place both the arduino and relay into the breadboard so that each won’t interfer with each other’s circuits
- Take the wires and connect the D1 pin on the Arduino and connect it to the D1 pin on the Relay
- Do the same thing with Ground (GND) and 5V
- You should have something like this
- The code is a fairly simple concept we need to connect to both the MQTT broker we setup in a previous lab and to your Adafruit feed
- The Arduino will be waiting to see if anything has been posted to the Adafruit feed and when it does will set off the relay
- Once the relay is set off the Arduino will then publish to the MQTT broker the state of the Garage door opener.
- Here’s a code diagram I found on Aaronnelson95.com that illustrates the process well
To see my code used for this tutorial check out my Github
Certificate of Work
The work here represents my own and where I used other’s work I gave due credit.
- https://github.com/adafruit/Adafruit_MQTT_Library/blob/master/examples/mqtt_esp8266_callback/mqtt_esp8266_callback.ino an example of how to do a Adafruit MQTT call back
- http://www.aaronnelson95.com/IT441Lab6.php a student from before who wrote a very comprehensive tutorial
- https://www.instructables.com/id/Arduino-WiFi-Garage-Door-Opener/ – A simple tutorial on actually connecting the relay to the garage door button (I don’t do this in my tutorial but here’s your chance to go the extra mile)