Freezer Door Alarm System Using MQTT and ESP8266
by suriono in Circuits > Sensors
279 Views, 3 Favorites, 0 Comments
Freezer Door Alarm System Using MQTT and ESP8266



Learn how to create a door alarm system using an ESP8266 (https://www.wemos.cc) and MQTT (https://mqtt.org/). This tutorial demonstrates the process using a freezer door as an example, but the system can be adapted for other types of doors.
This project began after noticing the basement freezer door was sometimes left ajar, and the built-in beeper wasn't loud enough to be heard upstairs.
MQTT was chosen for this project due to its open-source nature, free availability, lightweight design, widespread use in the IoT community, and extensive resources.
The ESP8266 is a tiny but mighty computer chip that's become a favorite for many electronics enthusiasts and professionals, especially those working with the Internet of Things (IoT). It has built-in Wi-Fi, making it easy to connect devices to wireless networks and the internet.
Note: Prior Arduino, ESP8266, and Raspberry Pi experience is required.
GitHub: Firmware is available via this link. Refer to the instructions below for proper unit-specific uploads.
Features:
- Opening the freezer door initiates a 120-second countdown timer.
- Once the timer reaches zero, the separate display unit upstairs will beep, and an email alert will be dispatched.
Supplies





- Two Wemos D1 Mini
- 100 Ohm resistor
- Piezo buzzer/beeper.
- Small rectangular magnets
- Magnetic Reed switch
- A 2.8-inch TFT LCD display with a resolution of 240x320 pixels and an SPI interface. Alternatively, displays of other sizes are also acceptable.
- 3D printer filament to build the casings.
- Power supply options to provide 5V to the Wemos:
- Buck converters and repurposed chargers.
- USB chargers.
Install MQTT Server
Use my Instructible to install the MQTT server, from this link.
- To complete this project, you'll require the server's username, password, and IP address.
Door Sensor Wirings and Firmware





The image illustrates the wiring. When a magnet is brought near the Reed switch, it activates, closing the circuit. Otherwise, the switch remains open. This unit "publishes" the data into the MQTT server. To power the unit:
- Dial the Buck converter until the output is 5.1V using a multimeter as the voltmeter.
Upload the firmware code to the Wemos microcontroller, the code is available from my GitHub link here.
- Notice near the top of the code:
- EspMQTTClient client( WIFI_SSID, WIFI_PASSWD, "192.168.0.122", MQTT_USER, MQTT_PASSWD, "uzbasementfreezer",1883); // passwords are hidden
- Replace the variables:
- WIFI_SSID: your home WiFi SSID
- WIFI_PASSWD: your home WifFi password
- 192.168.0.122: the MQTT IP address
- MQTT_USER: MQTT username
- MQTT_PASSWD: MQTT password
- "uzbasementfreezer": use any name to distinguish from other MQTT client.
- Another line near the top of the code:
- #define TIMER_TIME 120 // number of countdown before sending alerts
- Change 120 to the desired number of seconds for the door-open alert delay.
Note: Upon connection to a power meter, this unit registered a power consumption of only 0.7 watt.
Email Alert

These steps explain how to set up email alerts. While Gmail is used as an example, the process is similar for other email servers.
- Go to your Google account: https://myaccount.google.com/
- On top, search for "App password", and select "App Password".
- Enter your Google account authentications.
- Enter any "App name", "Freezer door" for instance.
- A password will be generated, save the password for the next step.
Display and Data Processor Unit Wirings and Firmware



The first image provides a detailed wiring diagram for the display unit, illustrating the connections between its various components.
Upload the firmware code to the Wemos microcontroller, the code is available from my GitHub link here:
- Notice near the top of the "Display.ino" file:
- EspMQTTClient client( WIFI_SSID, WIFI_PASSWD, "192.168.0.122", MQTT_USER, MQTT_PASSWD, "uzbasementfreezer",1883); // passwords are hidden
- Replace the variables:
- WIFI_SSID: your home WiFi SSID
- WIFI_PASSWD: your home WifFi password
- 192.168.0.122: the MQTT IP address
- MQTT_USER: MQTT username
- MQTT_PASSWD: MQTT password
- "uzmqtt": use any name to distinguish from other MQTT client.
- Notice near the top of the "smtp.ino" file:
- Replace the variables:
- SMTP_HOST: I use "smtp.gmail.com" for gmail, alternatively other email server could be used.
- AUTHOR_EMAIL: your gmail email address
- AUTHOR_PASSWORD: the Google App password from the previous step (look up).
- In the tft.ino file:
- Line: countDown_screenOFF = 240;
- The screen automatically turns off after 240 seconds of inactivity to save power and prolong its lifespan. Any door activity (open or close) will immediately turn the screen back on. You can modify this timeout duration as needed.
Note: Upon connection to a power meter, this unit registered a power consumption of only 0.9 watt when the display is on, and 0.7 watt when the display turns off.
3D Printing
The 3D print files are free to download.
https://www.printables.com/model/1205023-freezer-door-alarm-system-using-mqtt-and-esp8266