Friday, January 6, 2017

The 'brain' is the ESP8266 uC. It is available with on board WiFi and plenty of I/O for smaller projects. All this for well under $10USD with programming options for NodeMCU, MicroPython, and the Arduino IDE.
-----
There seems to be an unstoppable drive in the hacker DIY community for web based garage door openers and we were compelled to respond. The garage door opener we have opens/shuts from a push button switch that basically creates a short to connect two terminals on the garage door opening unit. That allows easy implementation because all that is required is a ESP8266 controlled relay wired across those two terminals to create a switch closure.

In addition to activating the door any activity is logged to a Google Sheet via the IFTTT.com Maker Channel. This is handy to track all activation usage and ESP8266 server restarts.
-----
The main components are the ESP8266, a relay module, a BS170 N-Channel MOSFET.

-----
Simple. Connect the 'stuff' as shown in the schematic:

and it will look something like this:

----
Use the Arduino IDE to load the source code below into the ESP8266 then wire the Normally Open (NO) side of relay you are controlling to the two terminals on the garage door opener that active the motor when 'shorted' together.

A few comments on the application:

Control works from Android, iPhone, PC, etc. Basically any browser. In the source code below if a device can open "http://192.168.0.28/long_confusing_URL_to_activate_relay" it will activate the garage door.

There is a "TEST" URL in the source code (http://192.168.0.28/) that confirms the ESP8266 is online but does not activate the door.

Set a static IP for the ESP8266 in your WiFi router. Otherwise it may be assigned a different local IP if the ESP8266 or WiFi router is restarted.

Use long/complex URLs. That way those that are connected to your router
don't have a 'obvious' URL to activate the rig or one they can remember
if you demo it.

We only wanted control of the door when connected to the host WiFi
router locally (LAN) and not from anyplace on the planet. If you want extended control to the WWW open a port on your
router, but be aware of the concerns. We wanted to limit use only to those
authorized to connect the WiFi router locally (LAN). Plus, we didn't want to
risk accidentally activating the door from a remote location.

The source code has separate IFTTT.com Maker Channel triggers to log events. We could use one Maker Channel trigger and just pass different GETPOST variables. However, creating multiple Maker Channel triggers would easily allow usage tracking on individuals by assigning each one a unique trigger name. (/ZenaActivate, /KelsoActivate, etc...)

Any time the door is activated or the ESP8266 is restarted (power outage, etc) a Google Sheet is updated to log the event as shown below.

-----
The Arduino IDE source code is:

/*
* Garage Door Opener via Web Browser and log to IFTTT.com
* ESP8266 NodeMCU Board using Arduino IDE
* WhiskyTangoHotel.Com DEC2106
*
* Blue on board LED is active LOW on GPIO2 (D4 on silkscreen)
* Relay to control Garage Door is active HIGH on GPIO5 (D1 on silkscreen)
*
* Opening 192.168.0.28/long_confusing_URL_to_activate_relay is called. Every effort is made to keep the relay off
* so the door does not close/activate by accident.
*
* A 'test' message is display on browser to see if server is up by calling root at:.
* 192.168.0.28/ This WILL NOT ACTIVATE THE RELAY. Only tests the server
*
* The 'meat' is at 192.168.0.28/long_confusing_URL_to_activate_relay. This will send a msg to the browser AND open/close the door.
*
*/

int randNumber; // Random# generated just to show a change in the screen. Help to verify updated page call.

void handleRoot() {
// This is called if 192.168.0.28/ is requested. The root.
// The 'meat' is at /long_confusing_URL_to_activate_relay.
// This is just here to test the ESP8266 connectivity of the WiFi network without moving the relay
// Show a message and flash the on board LED.
randNumber = random(1, 10000); // Random number just to show a change on the webpage at reload.
server.send(200, "text/plain", "Testing ESP8266. Response is: " + String(randNumber));
digitalWrite(led, 0); // Active LOW. Turn On board LED On
delay(2000);
digitalWrite(led, 1); // Active LOW. Turn On board LED Off
}

server.on("/long_confusing_URL_to_activate_relay", [](){
// This is called when 192.168.0.28/long_confusing_URL_to_activate_relay is called
randNumber = random(1, 10000); // Random number just to show a change on the webpage at reload.
server.send(200, "text/plain", "Relay activated @ESP8266. Code: " + String(randNumber));
digitalWrite(led, 0); // Active LOW. Turn On board LED On
digitalWrite(relay, 1); // Relay ON