{"id":18043,"date":"2021-09-29T11:12:00","date_gmt":"2021-09-29T11:12:00","guid":{"rendered":"http:\/\/randomnerdtutorials.com\/?p=18043"},"modified":"2021-09-30T15:02:06","modified_gmt":"2021-09-30T15:02:06","slug":"door-status-monitor-using-the-esp8266","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/door-status-monitor-using-the-esp8266\/","title":{"rendered":"ESP8266 NodeMCU Door Status Monitor with Email Notifications (IFTTT)"},"content":{"rendered":"\n<p>In this project,&nbsp;you&#8217;re going to monitor the status of a&nbsp;door using an&nbsp;ESP8266 NodeMCU board and a magnetic reed switch. You&#8217;ll receive an email notification whenever the door changes state: opened or closed. The email notifications will be sent using IFTTT, and the ESP8266 board will be programmed using Arduino IDE.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/ESP8266-Door-status-monitor-thumbnail.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 NodeMCU Door Status Monitor with Email Notifications IFTTT Arduino IDE\" class=\"wp-image-106860\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/ESP8266-Door-status-monitor-thumbnail.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/ESP8266-Door-status-monitor-thumbnail.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/ESP8266-Door-status-monitor-thumbnail.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/ESP8266-Door-status-monitor-thumbnail.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n\n<p>Instead of sending email notifications with IFTTT, you can use an SMTP server instead. To learn how to send emails with your ESP8266 using an SMTP server, you can follow the next tutorial:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-send-email-smtp-server-arduino\/\">ESP8266 NodeMCU Send Emails using an SMTP Server: HTML, Text, and Attachments (Arduino)<\/a><\/li><\/ul>\n\n\n\n<p>If you prefer, you can also send notifications to your Telegram account. Learn how to use Telegram with the ESP8266 on the following tutorial:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/telegram-esp8266-nodemcu-motion-detection-arduino\/\" title=\"Telegram: ESP8266 NodeMCU Motion Detection with Notifications (Arduino IDE)\">Telegram: ESP8266 NodeMCU Motion Detection with Notifications (Arduino IDE)<\/a><\/li><\/ul>\n\n\n\n<p>We have a similar tutorial for the ESP32 board: <a href=\"https:\/\/randomnerdtutorials.com\/esp32-door-status-monitor-email\/\">Door Status Monitor with Email Notifications (IFTTT)<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Project Overview<\/h2>\n\n\n\n<p>In this project, you&#8217;ll send an email notification whenever a door changes state. To detect the change, we&#8217;ll use a magnetic contact switch. To send an email we&#8217;ll use IFTTT.<\/p>\n\n\n\n<p>A magnetic contact switch is basically a reed switch encased in a plastic shell so that you can easily apply it to a door, a window, or a drawer to detect if the door is open or closed.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/reed-switch-door-status-monitor-sensor.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"magnetic contact switch reed switch\" class=\"wp-image-106893\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/reed-switch-door-status-monitor-sensor.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/reed-switch-door-status-monitor-sensor.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>The electrical circuit is closed when a magnet is near the switch\u2014door closed. When the magnet is far away from the switch\u2014door open\u2014the circuit is open. See the figure below.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/i2.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/02\/magnetic_reed_switch_howitworks.png?resize=665%2C374&amp;quality=100&amp;strip=all&amp;ssl=1\" alt=\"magnetic reed switch how i tworks\" class=\"wp-image-17317\"\/><\/figure><\/div>\n\n\n\n<p>We can connect the reed switch to an ESP8266 GPIO to detect changes in its state.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Sending Emails with IFTTT<\/h2>\n\n\n\n<p>To send emails with the ESP8266, we&#8217;ll use a free* service called IFTTT, which stands for &#8220;If This Then That&#8221;. <\/p>\n\n\n\n<p>IFTTT is a platform that gives you creative control over dozens of products and apps. You can make apps work together. For example, sending a particular request to IFTTT triggers an applet that makes something happen, like sending you an email alert.<\/p>\n\n\n\n<p>I like IFTTT service and once you understand how it works, it is easy to use. However, I&#8217;m not too fond of the layout of their website and the fact that it is constantly changing.<\/p>\n\n\n\n<p class=\"rntbox rntclgray\">* currently, you can have three active applets simultaneously in the free version.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Creating an IFTTT Account<\/h2>\n\n\n\n<p>Creating an account on IFTTT is free!<\/p>\n\n\n\n<p>Go to the official site: <a href=\"https:\/\/ifttt.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/ifttt.com\/<\/a> and click the <strong>Get Started<\/strong> button at the top of&nbsp;the page or Signup if you already have an account.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"365\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/IFTTT-Get-Started-Page.png?resize=750%2C365&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"IFTTT Get Started Web Page\" class=\"wp-image-106770\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/IFTTT-Get-Started-Page.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/IFTTT-Get-Started-Page.png?resize=300%2C146&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Creating an Applet<\/h2>\n\n\n\n<p>First, you need to create an Applet in IFTTT. An Applet connects two or more apps or devices together (like the ESP8266 and sending an email). <\/p>\n\n\n\n<p>Applets are composed of triggers and actions:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Triggers<\/strong> tell an Applet to start. The ESP8266 will send a request (webhooks) that will trigger the Applet. <\/li><li><strong>Actions <\/strong>are the end result of an Applet run. In our case, sending an email.<\/li><\/ul>\n\n\n\n<p>Follow the next instructions to create your applet.<\/p>\n\n\n\n<p><strong>1)<\/strong> <a href=\"https:\/\/ifttt.com\/create\" target=\"_blank\" rel=\"noreferrer noopener\">Click on this link to start creating an Applet<\/a>.<\/p>\n\n\n\n<p><strong>2)<\/strong> Click on the <strong>Add <\/strong>button.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"557\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-1-ifttt.png?resize=750%2C557&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"IFTTT Create your applet\" class=\"wp-image-106787\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-1-ifttt.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-1-ifttt.png?resize=300%2C223&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p><strong>3)<\/strong> Search for &#8220;Webhooks&#8221; and select it.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"677\" height=\"431\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-2.png?resize=677%2C431&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"IFTTT Create your applet choose a service\" class=\"wp-image-106788\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-2.png?w=677&amp;quality=100&amp;strip=all&amp;ssl=1 677w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-2.png?resize=300%2C191&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 677px) 100vw, 677px\" \/><\/figure><\/div>\n\n\n\n<p><strong>4)<\/strong> Select the option &#8220;Receive a web request&#8221;.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"630\" height=\"805\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-3.png?resize=630%2C805&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"IFTTT Create your applet webhooks receive a web request\" class=\"wp-image-106789\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-3.png?w=630&amp;quality=100&amp;strip=all&amp;ssl=1 630w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-3.png?resize=235%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 235w\" sizes=\"(max-width: 630px) 100vw, 630px\" \/><\/figure><\/div>\n\n\n\n<p><strong>5)<\/strong> Enter the event name, for example, <strong>door_status<\/strong>. You can call it any other name, but if you change it, you&#8217;ll also need to change it in the code provided later on.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"746\" height=\"680\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-4.png?resize=746%2C680&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"IFTTT Create your applet receive a web request\" class=\"wp-image-106790\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-4.png?w=746&amp;quality=100&amp;strip=all&amp;ssl=1 746w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-4.png?resize=300%2C273&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 746px) 100vw, 746px\" \/><\/figure><\/div>\n\n\n\n<p><strong>6)<\/strong> Then, you need to click the <strong>Add<\/strong> button on the &#8220;Then that&#8221; menu to select what happens when the previous event is triggered.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"583\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-5.png?resize=750%2C583&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"IFTTT Create your applet create your own\" class=\"wp-image-106791\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-5.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-5.png?resize=300%2C233&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p><strong>7)<\/strong> Search for <strong>email<\/strong> and select the email option.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"689\" height=\"450\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-6.png?resize=689%2C450&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"IFTTT Create your applet choose a service email\" class=\"wp-image-106792\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-6.png?w=689&amp;quality=100&amp;strip=all&amp;ssl=1 689w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-6.png?resize=300%2C196&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 689px) 100vw, 689px\" \/><\/figure><\/div>\n\n\n\n<p><strong>8)<\/strong> Click on <strong>Send me an email<\/strong>.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"471\" height=\"667\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-7.png?resize=471%2C667&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"IFTTT Create your applet choose an action\" class=\"wp-image-106793\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-7.png?w=471&amp;quality=100&amp;strip=all&amp;ssl=1 471w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-7.png?resize=212%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 212w\" sizes=\"(max-width: 471px) 100vw, 471px\" \/><\/figure><\/div>\n\n\n\n<p><strong>9)<\/strong> Then, write the email subject and body. You can leave the default message or change it to whatever you want. The <span class=\"rnthl rntliteral\">{{EventName}}<\/span> is a placeholder for the event name, in this case, it&#8217;s <span class=\"rnthl rntliteral\">door_status<\/span>. The <span class=\"rnthl rntliteral\">{{OccuredAt}}<\/span> is a placeholder for the timestamp of when the event was triggered. The <span class=\"rnthl rntliteral\">{{Value1}}<\/span> is a placeholder for the actual door status. So, you can play with those placeholders to write your own message. When you&#8217;re done, click on <strong>Create action<\/strong>.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"557\" height=\"878\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-8.png?resize=557%2C878&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"IFTTT Create your applet eventName set action fields\" class=\"wp-image-106794\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-8.png?w=557&amp;quality=100&amp;strip=all&amp;ssl=1 557w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-8.png?resize=190%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 190w\" sizes=\"(max-width: 557px) 100vw, 557px\" \/><\/figure><\/div>\n\n\n\n<p><strong>10)<\/strong> Now, you can click on <strong>Continue<\/strong>.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"739\" height=\"795\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-9.png?resize=739%2C795&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"IFTTT Create your applet create your own\" class=\"wp-image-106795\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-9.png?w=739&amp;quality=100&amp;strip=all&amp;ssl=1 739w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-9.png?resize=279%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 279w\" sizes=\"(max-width: 739px) 100vw, 739px\" \/><\/figure><\/div>\n\n\n\n<p><strong>11)<\/strong> Finally, click on <strong>Finish<\/strong>.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"677\" height=\"613\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-10-f.png?resize=677%2C613&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"IFTTT Create your applet review and finish\" class=\"wp-image-106846\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-10-f.png?w=677&amp;quality=100&amp;strip=all&amp;ssl=1 677w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-10-f.png?resize=300%2C272&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 677px) 100vw, 677px\" \/><\/figure><\/div>\n\n\n\n<p><strong>12)<\/strong> You&#8217;ll be redirected to a similar page\u2014as shown below.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"463\" height=\"669\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-11-f.png?resize=463%2C669&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"IFTTT Create your applet connected\" class=\"wp-image-106847\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-11-f.png?w=463&amp;quality=100&amp;strip=all&amp;ssl=1 463w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Create-applet-email-step-11-f.png?resize=208%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 208w\" sizes=\"(max-width: 463px) 100vw, 463px\" \/><\/figure><\/div>\n\n\n\n<p>Your Applet was successfully created. Now, let&#8217;s test it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"test-applet\">Testing your Applet<\/h2>\n\n\n\n<p>Go to this URL: <a href=\"https:\/\/ifttt.com\/maker_webhooks\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/ifttt.com\/maker_webhooks<\/a>&nbsp;and open the &#8220;<strong>Documentation<\/strong>&#8221; tab.<\/p>\n\n\n\n<p>You&#8217;ll access a web page where you can trigger an event to test it and get access to your API key (highlighted in red). Save your API key to a safe place because you&#8217;ll need it later.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"533\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/IFTTT-Trigger-Event-1.png?resize=750%2C533&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"IFTTT testing your applet \" class=\"wp-image-106801\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/IFTTT-Trigger-Event-1.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/IFTTT-Trigger-Event-1.png?resize=300%2C213&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>Now, let&#8217;s trigger the event to test it. In the <span class=\"rnthl rntliteral\">{event}<\/span> placeholder, write the event you created previously. In our case, it is <strong>door_status<\/strong>. Additionally, add a value in the <span class=\"rnthl rntliteral\">value1<\/span> field, for example <strong>open<\/strong>. Then, click the <strong>Test It<\/strong> button. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"663\" height=\"511\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/IFTTT-Trigger-Event-Testing-Applet.png?resize=663%2C511&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"IFTTT testing your applet\" class=\"wp-image-106803\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/IFTTT-Trigger-Event-Testing-Applet.png?w=663&amp;quality=100&amp;strip=all&amp;ssl=1 663w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/IFTTT-Trigger-Event-Testing-Applet.png?resize=300%2C231&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 663px) 100vw, 663px\" \/><\/figure><\/div>\n\n\n\n<p>You should get a success message saying &#8220;Event has been triggered&#8221; and you should get an email in your inbox informing you that the event has been triggered.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"314\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Received-Email-IFTTT-Event-Triggered.png?resize=750%2C314&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"IFTTT Applet tested successfully\" class=\"wp-image-106804\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Received-Email-IFTTT-Event-Triggered.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Received-Email-IFTTT-Event-Triggered.png?resize=300%2C126&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>If you received the email, your Applet is working as expected. You can proceed to the next section. We&#8217;ll program the ESP8266 to trigger your Applet when the door changes state. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Parts List<\/h2>\n\n\n\n<p>Here&#8217;s the hardware that you need to complete&nbsp;this project:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/makeradvisor.com\/tools\/esp8266-esp-12e-nodemcu-wi-fi-development-board\/\" target=\"_blank\" rel=\"noreferrer noopener\">ESP8266<\/a> &#8211; read <a href=\"https:\/\/makeradvisor.com\/best-esp8266-wi-fi-development-board\/\" target=\"_blank\" rel=\"noreferrer noopener\">Best ESP8266 Wi-Fi Development Boards<\/a><\/li><li><a href=\"https:\/\/makeradvisor.com\/tools\/magnetic-reed-switch\/\" target=\"_blank\" rel=\"noreferrer noopener\">1\u00d7 Magnetic Reed Switch&nbsp;<\/a><\/li><li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noreferrer noopener\">1\u00d7 10k\u03a9 resistor<\/a><\/li><li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noreferrer noopener\">1\u00d7 breadboard<\/a><\/li><li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noreferrer noopener\">Jumper wires<\/a><\/li><\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Schematic \u2013 ESP8266 NodeMCU with Reed Switch<\/h2>\n\n\n\n<p>We wired the reed switch to <span class=\"rnthl rntcgreen\">GPIO 4<\/span> (D2), but you can connect it to any suitable GPIO.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"558\" height=\"444\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/ESP8266-Reed-Switch-door-sensor-circuit.png?resize=558%2C444&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Schematic ESP8266 NodeMCU with Reed Switch wiring circuit diagram\" class=\"wp-image-106876\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/ESP8266-Reed-Switch-door-sensor-circuit.png?w=558&amp;quality=100&amp;strip=all&amp;ssl=1 558w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/ESP8266-Reed-Switch-door-sensor-circuit.png?resize=300%2C239&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 558px) 100vw, 558px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Code<\/h2>\n\n\n\n<p>Copy the sketch below to your Arduino IDE. Replace the SSID, password, and the IFTTT API Key with your own credentials.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*********\n  Rui Santos &amp; Sara Santos - Random Nerd Tutorials\n  Complete project details at https:\/\/RandomNerdTutorials.com\/door-status-monitor-using-the-esp8266\/\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.\n  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n*********\/\n\n#include &lt;ESP8266WiFi.h&gt;\n\n\/\/ Set GPIOs for LED and reedswitch\nconst int reedSwitch = 4;\nconst int led = 2; \/\/optional\n\n\/\/ Detects whenever the door changed state\nbool changeState = false;\n\n\/\/ Holds reedswitch state (1=opened, 0=close)\nbool state;\nString doorState;\n\n\/\/ Auxiliary variables (it will only detect changes that are 1500 milliseconds apart)\nunsigned long previousMillis = 0; \nconst long interval = 1500;\n\nconst char* ssid = &quot;REPLACE_WITH_YOUR_SSID&quot;;\nconst char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;\nconst char* host = &quot;maker.ifttt.com&quot;;\nconst char* apiKey = &quot;REPLACE_WITH_YOUR_IFTTT_API_KEY&quot;;\n\n\/\/ Runs whenever the reedswitch changes state\nICACHE_RAM_ATTR void changeDoorStatus() {\n  Serial.println(&quot;State changed&quot;);\n  changeState = true;\n}\n\nvoid setup() {\n  \/\/ Serial port for debugging purposes\n  Serial.begin(115200);\n\n  \/\/ Read the current door state\n  pinMode(reedSwitch, INPUT_PULLUP);\n  state = digitalRead(reedSwitch);\n\n  \/\/ Set LED state to match door state\n  pinMode(led, OUTPUT);\n  digitalWrite(led, state);\n  \n  \/\/ Set the reedswitch pin as interrupt, assign interrupt function and set CHANGE mode\n  attachInterrupt(digitalPinToInterrupt(reedSwitch), changeDoorStatus, CHANGE);\n\n  \/\/ Connect to Wi-Fi\n  WiFi.begin(ssid, password);\n  while (WiFi.status() != WL_CONNECTED) {\n    delay(500);\n    Serial.print(&quot;.&quot;);\n  }\n  Serial.println(&quot;&quot;);\n  Serial.println(&quot;WiFi connected&quot;);  \n}\n\nvoid loop() {\n  if (changeState){\n    unsigned long currentMillis = millis();\n    if(currentMillis - previousMillis &gt;= interval) {\n      previousMillis = currentMillis;\n      \/\/ If a state has occurred, invert the current door state   \n      state = !state;\n      if(state) {\n        doorState = &quot;closed&quot;;\n      }\n      else{\n        doorState = &quot;open&quot;;\n      }\n      digitalWrite(led, state);\n      changeState = false;\n      Serial.println(state);\n      Serial.println(doorState);\n        \n      \/\/Send email\n      Serial.print(&quot;connecting to &quot;);\n      Serial.println(host);\n      WiFiClient client;\n      const int httpPort = 80;\n      if (!client.connect(host, httpPort)) {\n        Serial.println(&quot;connection failed&quot;);\n        return;\n      }\n    \n      String url = &quot;\/trigger\/door_status\/with\/key\/&quot;;\n      url += apiKey;\n          \n      Serial.print(&quot;Requesting URL: &quot;);\n      Serial.println(url);\n      client.print(String(&quot;POST &quot;) + url + &quot; HTTP\/1.1\\r\\n&quot; +\n                          &quot;Host: &quot; + host + &quot;\\r\\n&quot; + \n                          &quot;Content-Type: application\/x-www-form-urlencoded\\r\\n&quot; + \n                          &quot;Content-Length: 13\\r\\n\\r\\n&quot; +\n                          &quot;value1=&quot; + doorState + &quot;\\r\\n&quot;);\n    }  \n  }\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Door_Status_Monitor_using_the_ESP8266.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>You must have the ESP8266 board add-on installed in your Arduino IDE. If you don&#8217;t, follow the next tutorial:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/how-to-install-esp8266-board-arduino-ide\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Install the ESP8266 Board in Arduino IDE<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How the Code Works<\/h2>\n\n\n\n<p>Continue reading to learn how the code works, or proceed to the <a href=\"#demonstration\">Demonstration <\/a>section.<\/p>\n\n\n\n<p>First, you need to include the <span class=\"rnthl rntliteral\">ESP8266WiFi<\/span> library so that the ESP8266 can connect to your network to communicate with the IFTTT services.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;ESP8266WiFi.h&gt;<\/code><\/pre>\n\n\n\n<p>Set the GPIOs for the reed switch and LED (the on-board LED is GPIO 2). We&#8217;ll light up the on-board LED when the door is open.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const int reedSwitch = 4;\nconst int led = 2; \/\/optional<\/code><\/pre>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">changeState<\/span> boolean variable indicates whether the door has changed state.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>bool changeState = false;<\/code><\/pre>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">state<\/span> variable will hold the reed switch state and the <span class=\"rnthl rntliteral\">doorState<\/span>, as the name suggests, will hold the door state\u2014closed or opened.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>bool state;\nString doorState;<\/code><\/pre>\n\n\n\n<p>The following timer variables allow us to debounce the switch. Only changes that have occurred with at least 1500 milliseconds between them will be considered.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>unsigned long previousMillis = 0; \nconst long interval = 1500;<\/code><\/pre>\n\n\n\n<p>Insert your SSID and password in the following variables so that the ESP8266 can connect to the internet.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char* ssid = \"REPLACE_WITH_YOUR_SSID\";\nconst char* password = \"REPLACE_WITH_YOUR_PASSWORD\";<\/code><\/pre>\n\n\n\n<p>Insert your own IFTTT API key on the <span class=\"rnthl rntliteral\">apiKey<\/span> variable\u2014the one you&#8217;ve gotten in <a href=\"#test-applet\">this step<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char* apiKey = \"REPLACE_WITH_YOUR_IFTTT_API_KEY\";<\/code><\/pre>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">changeDoorStatus()<\/span> function will run whenever a change is detected on the door state. This function simply changes the <span class=\"rnthl rntliteral\">changeState<\/span> variable to <span class=\"rnthl rntliteral\">true<\/span>. Then, in the <span class=\"rnthl rntliteral\">loop()<\/span> we&#8217;ll handle what happens when the state changes (invert the previous door state and send an email).<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>ICACHE_RAM_ATTR void changeDoorStatus() {\n  Serial.println(\"State changed\");\n  changeState = true;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">setup()<\/h3>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, initialize the Serial Monitor for debugging purposes:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.begin(115200);<\/code><\/pre>\n\n\n\n<p>Set the reed switch as an <span class=\"rnthl rntliteral\">INPUT<\/span>. And save the current state when the ESP8266 first starts.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>pinMode(reedSwitch, INPUT_PULLUP);\nstate = digitalRead(reedSwitch);<\/code><\/pre>\n\n\n\n<p>Set the LED as an <span class=\"rnthl rntliteral\">OUTPUT<\/span> and set its state to match the reed switch state (circuit closed and LED off; circuit opened and LED on).<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>pinMode(led, OUTPUT);\ndigitalWrite(led, state);<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>door closed &#8211;&gt; the ESP8266 reads a HIGH signal &#8211;&gt; turn off on-board LED (send a HIGH signal*)<\/li><li>door open &#8211;&gt; the ESP8266 reads a LOW signal &#8211;&gt; turn on on-board LED (send a LOW signal*)<\/li><\/ul>\n\n\n\n<p>The ESP8266 on-board LED works with inverted logic\u2014send a HIGH signal to turn it off and a LOW signal to turn it on.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Setting an interrupt<\/h4>\n\n\n\n<p>Set the reed switch as an interrupt.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>attachInterrupt(digitalPinToInterrupt(reedSwitch), changeDoorStatus, CHANGE);<\/code><\/pre>\n\n\n\n<p>To set an interrupt in the Arduino IDE, you use the&nbsp;<span class=\"rnthl rntliteral\">attachInterrupt()<\/span>&nbsp;function, which accepts as arguments: the GPIO interrupt pin, the name of the function to be executed, and mode.<\/p>\n\n\n\n<p>The first argument is a GPIO interrupt. You should use&nbsp;<span class=\"rnthl rntliteral\">digitalPinToInterrupt(GPIO)<\/span>&nbsp;to set the actual GPIO as an interrupt pin.<\/p>\n\n\n\n<p>The second argument of the&nbsp;<span class=\"rnthl rntliteral\">attachInterrupt()<\/span>&nbsp;function is the name of the function that will be called every time the interrupt is triggered \u2013 the interrupt service routine (ISR). In this case, it is the <span class=\"rnthl rntliteral\">changeDoorStatus<\/span> function.<\/p>\n\n\n\n<p>The ISR function should be as simple as possible, so the processor gets back to the execution of the main program quickly.<\/p>\n\n\n\n<p>The third argument is the mode. We set it to <span class=\"rnthl rntliteral\">CHANGE<\/span> to trigger the interrupt whenever the pin changes value \u2013 for example from HIGH to LOW or LOW to HIGH.<\/p>\n\n\n\n<p>To learn more about interrupts with the ESP8266, read the following tutorial:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/interrupts-timers-esp8266-arduino-ide-nodemcu\/\">ESP8266 Interrupts and Timers using Arduino IDE (NodeMCU)<\/a><\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Initialize Wi-Fi<\/h4>\n\n\n\n<p>The following lines connect the ESP8266 to Wi-Fi.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>WiFi.begin(ssid, password);\nwhile (WiFi.status() != WL_CONNECTED) {\n  delay(500);\n  Serial.print(\".\");\n}\nSerial.println(\"\");\nSerial.println(\"WiFi connected\");  <\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">loop()<\/h3>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">loop()<\/span> we&#8217;ll read the <span class=\"rnthl rntliteral\">changeState<\/span> variable and if a change has occurred, we&#8217;ll send an email using IFTTT.<\/p>\n\n\n\n<p>First, check if a change occurred:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if (changeState){<\/code><\/pre>\n\n\n\n<p>Then, check if at least 1500 milliseconds have passed since the last state change.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if(currentMillis - previousMillis &gt;= interval) {<\/code><\/pre>\n\n\n\n<p>If that&#8217;s true, reset the timer and invert the current switch state:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>state = !state;<\/code><\/pre>\n\n\n\n<p>If the reed switch state is <span class=\"rnthl rntliteral\">1<\/span>(true), the door is closed. So, we change the <span class=\"rnthl rntliteral\">doorState<\/span> variable to <span class=\"rnthl rntliteral\">closed<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if(state) {\n  doorState = \"closed\";\n}<\/code><\/pre>\n\n\n\n<p>If it&#8217;s <span class=\"rnthl rntliteral\">0<\/span>(false), the door is opened. <\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>else{\n  doorState = \"open\";\n}<\/code><\/pre>\n\n\n\n<p>Set the LED state accordingly and print the door state in the Serial Monitor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>digitalWrite(led, state);\nchangeState = false;\nSerial.println(state);\nSerial.println(doorState);        <\/code><\/pre>\n\n\n\n<p>Finally, the following lines make a request to IFTTT with the current door status on the event (<span class=\"rnthl rntliteral\">door_status<\/span>) that we created previously.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Send email\nSerial.print(\"connecting to \");\nSerial.println(host);\nWiFiClient client;\nconst int httpPort = 80;\nif (!client.connect(host, httpPort)) {\n  Serial.println(\"connection failed\");\n  return;\n}\n\nString url = \"\/trigger\/door_status\/with\/key\/\";\nurl += apiKey;\n          \nSerial.print(\"Requesting URL: \");\nSerial.println(url);\nclient.print(String(\"POST \") + url + \" HTTP\/1.1\\r\\n\" +\n               \"Host: \" + host + \"\\r\\n\" + \n               \"Content-Type: application\/x-www-form-urlencoded\\r\\n\" + \n               \"Content-Length: 13\\r\\n\\r\\n\" +\n               \"value1=\" + doorState + \"\\r\\n\");<\/code><\/pre>\n\n\n\n<p>When the IFTTT receives this request, it will trigger the action to send an email.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"demonstration\">Demonstration<\/h2>\n\n\n\n<p>After modifying the sketch to include your network credentials and API key, upload it to your ESP8266. Go to <strong>Tools <\/strong>&gt; <strong>Board <\/strong>and select your ESP8266 board. Then, go to <strong>Tools <\/strong>&gt; <strong>Port <\/strong>and select the COM port the ESP8266 is connected to.<\/p>\n\n\n\n<p>Open the Serial Monitor at a baud rate of 115200 to check if the changes are detected and if the ESP8266 can connect to IFTTT.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"794\" height=\"445\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/ESP8266-Connect-IFTTT-Door-Change-State.png?resize=794%2C445&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Testing ifttt with ESP8266 NodeMCU\" class=\"wp-image-106857\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/ESP8266-Connect-IFTTT-Door-Change-State.png?w=794&amp;quality=100&amp;strip=all&amp;ssl=1 794w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/ESP8266-Connect-IFTTT-Door-Change-State.png?resize=300%2C168&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/ESP8266-Connect-IFTTT-Door-Change-State.png?resize=768%2C430&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 794px) 100vw, 794px\" \/><\/figure><\/div>\n\n\n\n<p>For prototyping\/testing you can apply&nbsp;the magnetic reed switch to your door using Velcro.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"312\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/02\/esp8266-featured-image-e1456180240355.png?resize=600%2C312&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Testing ifttt with ESP8266 NodeMCU\" class=\"wp-image-18055\"\/><\/figure><\/div>\n\n\n\n<p>Now when someone\u00a0opens\/closes your door you get notified via email.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"810\" height=\"336\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Received-Email-IFTTT-Event-Triggered-Door-Closed.png?resize=810%2C336&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Door Status Received Email IFTTT ESP8266 NodeMCU\" class=\"wp-image-106853\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Received-Email-IFTTT-Event-Triggered-Door-Closed.png?w=810&amp;quality=100&amp;strip=all&amp;ssl=1 810w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Received-Email-IFTTT-Event-Triggered-Door-Closed.png?resize=300%2C124&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Received-Email-IFTTT-Event-Triggered-Door-Closed.png?resize=768%2C319&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 810px) 100vw, 810px\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Watch the video demonstration<\/h3>\n\n\n\n<p>We recorded this video several years ago (I&#8217;m sorry for the bad quality).<\/p>\n\n\n<p style=\"text-align:center\"><iframe width=\"720\" height=\"405\" src=\"https:\/\/www.youtube.com\/embed\/yY0DK8fe04w?rel=0\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial you&#8217;ve learned how to trigger an event when the reed switch changes state. This can be useful to detect if a door, window, or drawer was opened or closed. You&#8217;ve also learned how to use IFTTT to send an email when an event is triggered.<\/p>\n\n\n\n<p>Instead of sending an email, you may want to <a href=\"https:\/\/randomnerdtutorials.com\/telegram-esp8266-nodemcu-motion-detection-arduino\/\">send a message to Telegram<\/a>, for example.<\/p>\n\n\n\n<p>We hope you&#8217;ve found this tutorial useful. If you want to learn more about the ESP8266 board, check out our resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/home-automation-using-esp8266\/\">Home Automation Using ESP8266<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/build-web-servers-esp32-esp8266-ebook\/\">Build Web Servers with ESP32 and ESP8266 eBook (2nd Edition)<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp8266\/\">More ESP8266 Projects and Tutorials\u2026<\/a><\/li><\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this project,&nbsp;you&#8217;re going to monitor the status of a&nbsp;door using an&nbsp;ESP8266 NodeMCU board and a magnetic reed switch. You&#8217;ll receive an email notification whenever the door changes state: opened &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP8266 NodeMCU Door Status Monitor with Email Notifications (IFTTT)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/door-status-monitor-using-the-esp8266\/#more-18043\" aria-label=\"Read more about ESP8266 NodeMCU Door Status Monitor with Email Notifications (IFTTT)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":106860,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[245,214,265,246,300,240,220,264,218],"tags":[],"class_list":["post-18043","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino-ide","category-esp8266","category-esp8266-project","category-esp8266-arduino-ide","category-0-esp8266","category-esp8266-projects","category-http-client","category-project","category-web-server"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/ESP8266-Door-status-monitor-thumbnail.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/18043","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=18043"}],"version-history":[{"count":12,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/18043\/revisions"}],"predecessor-version":[{"id":106952,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/18043\/revisions\/106952"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/106860"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=18043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=18043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=18043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}