In this project you’re going to monitor the status of a door using an ESP8266. The goal of this project is to show the endless possibilities that this $4 WiFi module offers when integrates with a free platform that I’m about to show you.

Before continue reading this project, please complete the following tutorials or use them as a reference:
- How to get started with the ESP8266
- How to Install the ESP8266 Board in Arduino IDE
- Monitor Your Door Using Magnetic Reed Switch and Arduino
Let’s get started!
About IFTTT
In order to accomplish this task you have to sign up for one free service called IFTTT which stands for “If This Then That”.
IFTTT is a platform that gives you creative control over dozens of products and apps.
You can make apps work together. For example when you send a request to IFTTT, it triggers a recipe that sends you an email alert.
Creating Your IFTTT Account
Creating an account on IFTTT is free!
Go the official site: https://ifttt.com/ and click the “Sign Up” button in top of the page.
Complete the form with your personal information (see figure below) and create your account.

After creating your account, follow their getting started tutorial.
Open the Applet
I’ve created an Applet that integrates perfectly in this project and you can also use it.
If you’re logged in at IFTTT and you open this URL below to use my Applet instantly:
Press the “Turn on” button:

Next, you need to grant access permissions:

Let your IFTTT account connect to your Gmail account. A new page loads when you finish connecting your Gmail.

Complete the Applet
Fill the Applet with your own information. Follow these instructions:
- Type “door_status” in your event name
- Add an email address
- Edit the subject and body of your email. Do not delete the Value1 in the subject
- Press the “Save” button

https://tpc.googlesyndication.com/safeframe/1-0-37/html/container.html
Now, go to this URL: https://ifttt.com/maker_webhooks and open the “Settings” tab.

Copy you secret key to a safe place (you’ll need them later in this project). In my example my secret key is: b6eDdHYblEv2Sy32qLwe

Test Your Applet
Let’s test if your request is working properly. Replace YOUR_API_KEY from the following URL:https://tpc.googlesyndication.com/safeframe/1-0-37/html/container.html
https://maker.ifttt.com/trigger/door_status/with/key/YOUR_API_KEY
With your API KEY:
https://maker.ifttt.com/trigger/door_status/with/key/b6eDdHYblEv2Sy32qLwe
Open your URL with your API KEY in your browser.

You should see something similar to the preceding Figure. Then go to your email client and new email should be there!

Parts List
Here’s the hardware that you need to complete this project:
- ESP8266 – read Best ESP8266 Wi-Fi Development Boards
- FTDI programmer
- 1× Magnetic Reed Switch
- 1× 10kΩ resistor
- 1× breadboard
- Jumper wires
Schematics (3.3V FTDI Programmer)
The schematics to upload code to your ESP8266 are very straight forward. You only need to establish a serial communication between your FTDI programmer and your ESP8266 to upload some code.https://tpc.googlesyndication.com/safeframe/1-0-37/html/container.html

Uploading your ESP8266 code
Having the ESP8266 add-on for the Arduino IDE installed (How to Install the ESP8266 Board in Arduino IDE).
Go to Tools and select “Generic ESP8266 Module”.

https://tpc.googlesyndication.com/safeframe/1-0-37/html/container.html
Copy the sketch below to your Arduino IDE. Replace the SSID, password and the IFTTT API Key with your own credentials.
/*
Welcome to Gnd_To_Vcc!!
Based on some ESP8266 code examples
*/
#include <ESP8266WiFi.h>
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";
const char* host = "maker.ifttt.com";
const char* apiKey = "YOUR_IFTTT_API_KEY";
int pin = 2;
volatile int state = false;
volatile int flag = false;
const char* door_state = "closed";
unsigned long previousMillis = 0;
const long interval = 3000;
void changeDoorStatus() {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
state = !state;
if(state) {
door_state = "opened";
}
else{
door_state = "closed";
}
flag = true;
Serial.println(state);
Serial.println(door_state);
}
}
void setup() {
Serial.begin(115200);
delay(100);
Serial.println("Preparing the Door Status Monitor project...");
pinMode(pin, OUTPUT);
attachInterrupt(digitalPinToInterrupt(pin), changeDoorStatus, CHANGE);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
if(flag){
Serial.print("connecting to ");
Serial.println(host);
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
String url = "/trigger/door_status/with/key/";
url += apiKey;
Serial.print("Requesting URL: ");
Serial.println(url);
client.print(String("POST ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Content-Type: application/x-www-form-urlencoded\r\n" +
"Content-Length: 13\r\n\r\n" +
"value1=" + door_state + "\r\n");
flag = false;
}
delay(10);
}
After modifying my sketch upload it to your ESP8266 (If you can’t upload code to your ESP8266, read this troubleshooting guide).
Final Circuit
Now follow the schematics below to create your Door Status Monitor.https://tpc.googlesyndication.com/safeframe/1-0-37/html/container.html
Demonstration
For prototyping/testing you can apply the magnetic reed switch to your door using Velcro.

Now when someone opens/closes your door you get notified via email (watch the video at the beginning of this project for a live demonstration).
Wrapping Up
Do you have any questions? Leave a comment down below!
Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my blog.https://tpc.googlesyndication.com/safeframe/1-0-37/html/container.html
P.S. If you got stuck during this tutorial make sure you read “ESP8266 Troubleshooting Guide“
4 thoughts on “Door Status Monitor using the ESP8266”