Door Open Alert Notification Message using ESP8266 and IFTTT
Table of Contents
Door Open Alert with ESP8266 & IFTTT:
Door Open Alert Notification Message using ESP8266 and IFTTT- In today’s article, I will show you how to make your own Door sensor that alerts your phone without using a GSM module. Previously, I built an IoT based Door security system IoT Door Sensor Reed Switch based Security System using Nodemcu ESP8266”. This project is based on the same electronics. The only difference is, this time I am using IFTTT instead of the Blynk application.
In this tutorial, I will show you how to send a notification message or alert message to your phone without using the GSM module. For this project, we need an ESP8266 Nodemcu module, a Reed switch that will be used for monitoring the door; with the help of a magnetic Reed switch we can easily monitor the door status if it is closed or opened, and then using the ESP8266 WiFi module we can send a notification message to any mobile with the help of IFTTT Applet.
The project installation is pretty simple, as you know the Magnetic Reed Switch consists of two parts; the permanent magnet and the Reed switch. The permanent magnet is fixed on the Door near the edge while the Reed switch is fixed on the Door frame near the permanent magnet. The distance between the magnet and the Reed switch should be enough so that the contacts inside the reed switch can open and close when the door is opened or closed, this is really important. When the door is opened, the contacts inside the Reed switch will disconnect and this will trigger the controller input pin and a result Door Open Alert message will be sent on the desired cell phone number. When the door is opened the Reed switch gives a High signal and when the door is closed the Reed switch gives a Low signal to the controller i.e. ESP8266.This project is very useful for security purposes. You can also improve this project by placing more sensors such as motion sensors e.g PIR Sensor, Microwave sensor which can detect humans behind the walls. But for now, we are only interfacing Reed switch with the ESP8266; so that you can easily understand the basic algorithm for designing this project using the IFTTT.
Interfacing Reed Switch with ESP8266:
You can see the circuit diagram is very simple and these are the minimal connections which you will need to test this project. Right now there is no external power supply. If you plan on adding an external power supply then read my other article “IoT Door Reed Switch”. As you know reed switch has two contacts, so one contact is connected with the Gnd pin of the ESP8266 and the other contact of the reed switch is connected with the D1 pin of the ESP8266 Nodemcu Module.
Designing IFTTT Application for Door Notification:
First open the IFTTT home page if you do not have an account then first create a free account on the IFTTT and sign in to the account in order to make the IFTTT applet. As I already have an IFTTT account; so, I will click on the create button.
When we will click on the create button a new window will open in which we will have two options; in the first option we will create the if statement and in the second we will perform the action. It works like, if this “some action” then that “some activity to perform”. Don’t get confused, you will learn everything.
Then click on if this and click on the add button and in choose a service search for the web hook.
When we click on the webhooks another window will open in which we will select receive a web request.
Then we will give a name to the event door and click on the create trigger button. When this event is triggered it will send notification to the IFTTT applet.
Now the request is triggered so when this event is triggered what we will do, we will click on the then that
When we will click on the then that we will search for notifications in choose a service tab then click on the notification.
Now after the selection of the notifications a window will open in which we will select send a notification from the IFTTT App.
Then we will write the notification in which we will send the door status notification through the IFTTT applet when the door will be opened and closed. We will write the message the door has beened open and then click on the add ingredient and select the occurred at option.
Then click on the web hook in order to get the key we will click on the documentation.
Now by clicking on the documentation we will get the key and also we can test our application. First of all, we will write the event name which is door and then enter the values in the value1 and value2 and then click on the test button a notification will be received in our mobile.
In order to receive the notification in the mobile we will need to install an IFTTT application in the mobile by simply downloading it from the Play store and login with the same account which we have used in the designing of IFTTT applet. This is really important make sure you use the same email account.
Door Open Alert ESP8266 Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
#include <ESP8266HTTPClient.h> #include <ESP8266WiFi.h> #define REED_SWITCH 5 //D1 int status = WL_IDLE_STATUS; //not required. const char* ssid = "AndroidAP3DEC"; const char* password = "12345678"; int doorClosed = 1; void setup() { pinMode(REED_SWITCH, INPUT_PULLUP); Serial.begin(115200); setupWifi(); //get_http(); } void setupWifi() { // Connect to WPA/WPA2 network. Change this line if using open or WEP network: WiFi.mode(WIFI_STA); status = WiFi.begin(ssid, password); Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); // Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.print("."); } Serial.println("Connected to wifi"); } void loop() { if (WiFi.status() != WL_CONNECTED) { setupWifi(); } // put your main code here, to run repeatedly: if ((digitalRead(REED_SWITCH) == HIGH) && (doorClosed == 1)) { Serial.println("DOOR OPEN!!"); while (get_http(String("DOOR_OPEN_")) != 0); doorClosed = 0; } else if ((digitalRead(REED_SWITCH) == LOW) && (doorClosed == 0)) { Serial.println("DOOR CLOSED!!"); while (get_http(String("DOOR_CLOSED_")) != 0); doorClosed = 1; } delay(10); } int get_http(String state) { HTTPClient http; int ret = 0; Serial.print("[HTTP] begin...\n"); // configure ifttt server and url should be HTTP only..not https!!! (http://) http.begin("https://maker.ifttt.com/trigger//with/key/fq3p4UpwPIdsAJQhCg0_VGy1TMpio6MtqOxmO63P"); //HTTP //If you have enabled value1 from iftt settings then uncomment below line to send value and comment out above line //http.begin("http://maker.ifttt.com/trigger/door/with/key/your_key_from_Iftt/?value1="+state); //HTTP Serial.print("[HTTP] GET...\n"); // start connection and send HTTP header int httpCode = http.GET(); // httpCode will be negative on error if(httpCode > 0) { // HTTP header has been send and Server response header has been handled Serial.printf("[HTTP] GET code: %d\n", httpCode); if(httpCode == HTTP_CODE_OK) { String payload = http.getString(); Serial.println(payload); } } else { ret = -1; Serial.printf("[HTTP] GET failed, error: %s\n", http.errorToString(httpCode).c_str()); delay(500); // wait for half sec before retry again } http.end(); return ret; } |
bonjour cela me mais une erreur
voici l erreur exit status 1
invalid preprocessing directive #d\u000000e9finir