Garage Door Controller Tutorial

At this point you should have setup ArduinoIDE with Engimusing librariessetup openHAB, setup Mosquitto, and linked an engimusing device to openHAB using MQTT. This tutorial will show how to setup the Garage Door Controller to work with OpenHAB using MQTT.

Garage Door Controller Sketch

The first step to getting the garage door controller board setup is to upload the MqttHub\GarageDoor\Garage_Door_Controller example.

Start by opening the Garage_Door_Controller.ino file from the Arduino IDE File->Exmples->MqttHub->GarageDoor->Garage_Door_Controller menu item.

This sketch contains an example of how to setup most of the devices on the garage door controller board.

Lets take a closer look at the setup() function in the sketch. 

First up is the setup for the LEDs.

  //Initialize the on off control to connect it to
  // the LED that is on the board
  LEDCtrl_RED.begin(HUB, ledId[0], "GDOOR/BOARD/LED_RED", LOW);
  LEDCtrl_BLUE.begin(HUB, ledId[2], "GDOOR/BOARD/LED_BLUE", LOW);

These lines setup connect the Tri Color LED on the board to some MQTT topics. This is basically the same as in the LED tutorial. The first parameter is the MQTT hub object to connect the module to. The second is the pin that the LED is connected to. The third is the MQTT topic to listen for. The last is the state of the pin that turns the LED on.

The next device in the Garage_Door_Controller sketch is the TMP102: 

  //Initialize the tmp control class which will send the 
  // temperature over MQTT every 10 seconds
  TMP102.begin(HUB, "GDOOR/BOARD/TMP102", &Wire0, -1, 10000); 

This code configures the Energy Micro to communicate with the TMP102 device that is conneted to Wire0. There is no power pin for this board so it is set to -1. The last parameter specifies how often the temperature should be sent to the MQTT server. For this example it is set to 10000 which is in milliseconds so it will send every 10 seconds.

Next up are the Reflective Sensors: 

  //On the side of the garage door board with less on it there are
  // three QRE1113 reflectivity sensors. These work well as proximity sensor
  // buttons.
  ReflectiveSensorSwitch0.begin(HUB, 30, "GDOOR/BOARD/QRE0", 10, 1);
  ReflectiveSensorSwitch1.begin(HUB, 31, "GDOOR/BOARD/QRE1", 10, 3);
  ReflectiveSensorSwitch2.begin(HUB, 15, "GDOOR/BOARD/QRE2", 10, 45); 

The second parameter is the pin that is the output of the reflective sensor. The forth parameter is the number of samples that need to be the same result before the switch is considered toggled. Larger numbers for this parameter will result in the press taking longer to register but will avoid false positives. The last parameter is the pin that enables the sensor. When one of the proximity sensors registers something near it, the board will send an MQTT message to the server letting it know about the event.

Setup next is the MQ7 Carbon Monoxide detector. The initial configuration should not be used as a emergency CO detector since it has not been tested against a real CO scenario. Please continue to use a retail CO detector and use this only as a remote test to know to check the retail CO detector.

  //The large round orange object on the side of the garage door board with more on it
  // is the MQ7 CO detector.
  Mq7.begin(HUB, "GDOOR/BOARD/MQ7", 48, 33, 10000);  

The last three parameters are the 2 pins needed to use the MQ7 and the rate at which the MQ7 results should be reported to the MQTT server in milliseconds.

 Noa1212 is a light level sensor that reports on the light level in the garage.  

  //Light sensor that is on the front of the board.
  Noa1212.begin(HUB, "GDOOR/BOARD/NOA1212", 16, 25, 24, 32, Noa1212Module::MEDIUM_GAIN, 10000); 

The 4 pins are a power pin, 2 gain settings pins, and the result pin. The gain setting can be HIGH, MEDIUM, or LOW. HIGH gain is good for detecting differences in the dark, LOW gain is good for detecting differences in the bright and MEDIUM is a compromise between the two. Lastly, there is a parameter for how often the Noa1212 should report the light level to the MQTT server. This can be used to know if the lights were left on in the garage or as a secondary sensor for checking if a garage door has been left open during the day.

DC Relays are how the garage door will be controlled. They will be hooked up in parallel to any other garage door buttons or receivers that are connected to the garage door opener.  

  //onoff controls for the dcrelays. These are auto turned off in the loop() after a set amount of time
  DcRelay1.begin(HUB, 5, "GDOOR/BOARD/DCRELAY1", LOW);
  DcRelay2.begin(HUB, 6, "GDOOR/BOARD/DCRELAY2", LOW);

The DC Relays are connected using the same module class as the LED switches in order to allow the MQTT server to control when the DC Relay is set to closed. Looking down lower in the sketch in the loop() function the DC Relays are controlled so they work to trigger the garage door opener to open/close the garage just like the physical garage door button does: 

  //Turn dcrelay off after a set amount of time so that the garage door is opened/closed
  if(DcRelay1.pinState() > 0)
        if(dcRelay1TurnOnTime == -1)
            dcRelay1TurnOnTime = millis();
        if(dcRelay1TurnOnTime + dcRelayOnTime < millis())
            dcRelay1TurnOnTime = -1;

Basically, this code checks to see if the DC Relay is set to closed and if it is then after 1 second it sets it back to open. This is the equivalent of pressing the garage door button for 1 second.

The last piece of the setup code sets up the 6 monitors. These are just digital sensors that will let the MQTT server know if the wire they are connected to is LOW or HIGH.  

  //Connects up the 6 monitor wires to the MQTTHub
  Monitor1.begin(HUB, 42, "GDOOR/BOARD/MON1", 10);
  Monitor2.begin(HUB, 41, "GDOOR/BOARD/MON2", 10);
  Monitor3.begin(HUB, 14, "GDOOR/BOARD/MON3", 10);
  Monitor4.begin(HUB, 43, "GDOOR/BOARD/MON4", 10);
  Monitor5.begin(HUB, 47, "GDOOR/BOARD/MON5", 10);
  Monitor6.begin(HUB, 13, "GDOOR/BOARD/MON6", 10); 

These 6 monitors can be connected up to sensors like a Reed switch, a physical switch, a reflectivity sensor, or any other sensor that is a single wire output. These sensors can be used to know if the garage door has been left fully open, fully closed, or partially in between if they have been setup correctly.

Configuring OpenHAB

Setting up the OpenHAB side of things is about the same as the setup openHAB tutorial. 

First, download the configuration file for the Garage Door Controller here:

DOWNLOAD link to garage door controller configuration

Copy the garage_tutorial.items into the configurations/items directory of your openHAB installation.

Copy the garage.sitemap into the configurations/sitemaps directory. 

If openHAB is now already running, start it up using the start.bat in the root directory for the openHAB installation.

After a minute or two openHAB will be up and running and you can go to: 


(Replace localhost with the hostname/ip address for the server if it is no on the same machine as the web broswer.)

You should now see something like this:

 Click the MQTT Controlled Garage item and you should see all the items:

 If you got to this point without first running Mosquitto then you should close the OpenHAB console window and start up Mosquitto first. Then restart OpenHAB and start the EFMcomm application as well.

Once the OpenHAB server is back up and the EFMcomm application is started as well, go back to the OpenHAB garage sitemap website and the items page should look something like this:

At this point if you switch the LED switches on the website you should see the LED light on the board turn on and off.

Take a look at garage_tutorials.items to see how each of the items are configured and connected up to the MQTT server.

Connecting to Garage Door Opener

The majority of garage door openers have a simple push button switch that is used to control when the garage door should open. 


In order to keep the original garage door opener working we need to add the Engiumsing Garage Door Controller in parallel. There are two DC relays available on the garage door controller. Lets connect the DC Relay 1 in parallel with the regular garage door opener like this:


At this point if the garage door controller is still connected to a computer with the EFMcomm application running then the Door Control 1 switch should now work to open and close the garage door. 

If you have a second garage door then you can connect it up the same way to DC Relay 2.

Related follow-up tutorials:

Adding Sensors to the Garage Door Controller.

Adding a WiFi Connection to the Garage Door Controller.

Configuring Garage Door Controller Buttons.

Adding a LCD Screen to the Garage Door Controller.