Garage Door Sensor

Updated 31 March 2022

This project uses a US100 ultrasonic distance sensor to detect instances of a garage tilt door being left open and sends an alert via the IFTTT mobile app. Additionally, the device logs temperature and pressure to a Thingspeak channel using a BMP280 sensor.

For this Project, a device was required to detect if the garage door had been left open and send an alert to the owners mobile. When the door is open it sits flat about 200mm below the roof of the garage, hence an ultrasonic distance sensor mounted on the roof was used to detect if the open door could be detected. The project used an ESP8266 WiFi module to send an alert to a mobile device. Initially, it was planned to operate the device from batteries so the circuit and code were designed to use very little power; the final project was powered from USB. In an effort to put the ESP8266 to good use a BMP280 temperature and pressure sensor was added to create a basic weather logger. The components were assembled on some perfboard and housed in a 3D printed enclosure. ThingSpeak was used to store the data and IFTTTWebhooks was used to create the alert.

To Create this project the following components were used:

How I built this project:

ESP8266 and breakout board

Using a breakout board for the ESP8266 makes perfboard prototyping much easier as the SMD connectors on the ESP chip do not align with the 2.54 perfboard holes. Not only does the breakout board fix this, it includes 10K SMD pull-up and pull-down resistors for CHIP_PD and GPIO_15 respectively. The breakout board comes with a 0 ohm SMD resistor in the centre at the bottom, if the VCC is 3.3v this can be left as is, however removing the component allows a 3.3v HT7333 stepdown regulator to be used to convert the 5V USB source to the required 3.3V and the breakout board has the correct footprint for this on the back. The VCC on the breakout board is then connected to the screw terminal block which is connected to the sacrificial USB cable. To ensure reliable performance of the ESP8266 a 3300uF capacitor was added as well as a 10K pull-up resistor for GPIO_0, connecting GPIO_16 to RST to enable wake from deep sleep and some header pins for programming.

BMP280 temperature and pressure sensor

The BMP280 sensor was connected to the ESP8266 using GPIO_4 and GPIO_2 as SCL and SDA with 4.7K pull-up resistors for each. The VCC was supplied from the HT7333. As previous projects had discovered that the BMP280 temperature was susceptible to heating effects from the ESP8266 it was placed as far away as practically possible from the ESP8266.

US100 ultrasonic distance

The US100 can operate in two modes, serial or ping. For this project serial mode is being used as it provides the advantage of using the US100 circuitry to calculate distance and not having to worry about timing routines. To select serial mode there is a jumper on the back of the US100 directly above the IC in the centre. To get the part to sit flat on the board the jumper pins were desoldered and the pads bridged with solder. TX and RX on the US100 were connected to GPIO_12 and GPIO_13 on the ESP8266 and the US100 VCC was connected to GPIO_14 so the part could be powered down between readings.

The Case

The enclosure for the device was based upon the Project Box by giufini, Published on August 24, 2013: www.thingiverse.com/thing:139275 The project box was modified in Tinkercad to add two holes for the US-100 Ultrasonic sensor, and a couple of standups for the PCB. Ultimately I couldn't find screws small enough for the standups so I added a drop of PVA glue to each corner which worked well.

Software and Code:

Code for the project is linked below. The code makes use of open source libraries available in the Arduino IDE, and I would like to thank the various library authors for their contributions.

The device was programmed using the Arduino IDE. There are some user inputs at the start which need to be set to log data to the users ThingSpeak channel and specify the webhook event to trigger. The users can also set the time interval between measurements, the distance threshold for determining an open door, and the number of intervals the door has to be open before triggering.

After some initialisation commands, setting pins etc, the program checks if the ESP8266 Real Time Clock (RTC) memory is initialised. RTC memory is utilised to store the data between deep sleep instances.

Following this, a check is done on the state of GPIO5 - our WiFiConfig button. The WiFiManager library provides a great utility to allow the ESP8266 to easily connect to different WiFi Access Points via a config page, by default if it cannot connect it creates a new WiFi network and hosts a page which allows the user to scan for existing networks and configure the connection settings. If our wifi is down temporarily (auto resets, watchdog, power issues) we don't want the device to waste power by keeping a separate WiFi network up every time, hence we set the timeout to 1ms and force the new WiFi network and config page if GPIO5 is pulled low via the switch.

Next, the device reads the distance to object from the US-100 sensor, if the distance measure is less than the threshold the door must be open and the counter is incremented. As the sensor is being used in the serial mode we can also get temperature but the output precision is only to whole degrees. It is logged regardless as it is useful to ensure the BMP280 is reading accurately and not being affected by heat from the ESP8266. Temperature and pressure are logged using the BMP280. When using the Adafruit BMP280 library the CPP file was modified similar to the linked post to set values for weather station use, i.e. x1 oversample and forced mode to save power and prevent self-heating of the chip. Once the readings have been taken the values are stored to RTC memory.

https://forums.adafruit.com/viewtopic.php?f=19&t=84229#p556013

 write8(BMP280_REGISTER_CONTROL, 0x25);
 uint8_t config = read8(BMP280_REGISTER_CONFIG) & 0x03;
 write8(BMP280_REGISTER_CONFIG, 0x1C | config);
 return true;

After collecting the value the door counter and data counter are checked to see if information needs to be sent. If the door counter is greater than the specified limit then an IFTTT webhooks event is fired. IFTTT is a free service which allows simple "If This Then That" recipes to connect all different devices. Once your account is set up, alter the code with your webhooks key (https://ifttt.com/services/maker_webhooks/settings) and create a new applet where THIS is a webhooks "Receive a web request" (Create a new event name e.g. Garage_Open) and THAT is "Send a notification from the IFTTT app" (Alter the message if you wish). Also download the IFTTT app on your phone, sign in and allow push notifications. While I know that the IFTTTWebhook library by John Romkey works from my previous projects I couldn't get it to work in this instance. As it's a really simple alert that is being sent I use the HTTPClient library and trigger the alert that way using the same https fingerprint from Romleys library.

If the data counter is greater than the specified number the data is uploaded to ThingSpeak via a JSON format bulk update. The bulk update feature is really useful as it allows us to save up a heap of data points the upload them all at once to minimise WiFi connections and reduce power usage. I created a new ThingSpeak channel with fields for BMP280 temperature, US-100 temperature, BMP280 pressure and distance to object. If the data receipt is acknowledged the counter resets otherwise it continues to increment until the RC memory is full at which time it begins to shift data records so that the oldest point is discarded to make room for the newest data.

Finally, the program determines how long until the next data sample and based on the counters if the ESP8266 should have WiFi on or off when it wakes next from deep sleep.

Installation

Once testing was complete the device was installed in the garage, in my case this meant using a cable tie and fastening it to a drain pipe (interestingly any time someone has a shower the hot water in the pipe can be seen as a small increase in the temperature readings for about 15 minutes, I added an extra bit of cardboard as insulation to try to reduce this). The images below how the garage door is positioned.

Results

Data logged on the ThingSpeak channel is shown below. It can be seen that the two temperature values are similar in terms of absolute value but the BMP280 has greater resolution. The atmospheric pressure readings seem reasonable and the distance log shows that when the garage door is open it is about 140mm from the sensor and when it is closed the ground below is detected at 2220mm from the sensor. A door threshold distance of 800mm is used to differentiate between open and closed.

If the door is detected open over 5 consecutive samples at 1-minute intervals an alert is sent. An example of the alert provided by the IFTTT app for IOS is shown below:

Attachment - Project Files

Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.