Arduino - Door Open - Send Email Notification
Arduino - Door Open - Send Email Notification
5
Project description
We are going to learn how to use Arduino to send a notification to you via email when someone opens your door. We will use Arduino, door sensor, and Ethernet Shield. You can also use any other Ethernet or WiFi shield by making a small modification in the Arduino code.

Hardware Required
About Door Sensor and Sending Email
If you do not know about the door sensor (pinout, how it works, how to program ...) and how to send email from Arduino, learn about them in the following tutorials:
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
What we need to do
We need to do to main tasks:
How it works
When the door is opened:
The email address, email subject, and email content are specified when we create the IFTTT Applet.
How To Create an IFTTT Applet













Someone opened your door!
Take care!
Arduino Uno


Now you succeeded to create an IFTTT Applet for your Arduino. The next step is to get the IFTTT Webhooks key, which is used to authenticate and identify your Arduino.


Now, We just need to write Arduino code that makes an HTTP request to the below URL:
※ NOTE THAT:
Before writing Arduino code, We can test the IFTTT Applet by doing:

Arduino Code
/*
* Created by ArduinoGetStarted.com
*
* This example code is in the public domain
*
* Tutorial page: https://arduinogetstarted.com/tutorials/arduino-door-open-send-email-notification
*/
#include <SPI.h>
#include <Ethernet.h>
#include <ezButton.h>
ezButton doorSensor(13); // create ezButton object that attach to pin 13, which connected to door sensor's pin
// replace the MAC address below by the MAC address printed on a sticker on the Arduino Shield 2
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetClient client;
int HTTP_PORT = 80;
String HTTP_METHOD = "GET";
char HOST_NAME[] = "maker.ifttt.com";
String PATH_NAME = "/trigger/send-email/with/key/XXXXXXXXXXXXXXXXXXXXX"; // change your Webhooks key
void setup() {
Serial.begin(9600);
Serial.println("DOOR MONITORING via EMAIL STARTED!");
// initialize the Ethernet shield using DHCP:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to obtaining an IP address using DHCP");
while (true);
}
doorSensor.setDebounceTime(50); // set debounce time to 50 milliseconds
}
void loop() {
doorSensor.loop(); // MUST call the loop() function first
if (doorSensor.isReleased()) { // LOW to HIGH
Serial.println("The door is opened!");
Serial.println("Arduino is sending email");
sendEmail();
}
}
void sendEmail() {
// connect to IFTTT server on port 80:
if (client.connect(HOST_NAME, HTTP_PORT)) {
// if connected:
Serial.println("Connected to server");
// make a HTTP request:
// send HTTP header
client.println("GET " + PATH_NAME + " HTTP/1.1");
client.println("Host: " + String(HOST_NAME));
client.println("Connection: close");
client.println(); // end HTTP header
while (client.connected()) {
if (client.available()) {
// read an incoming byte from the server and print it to serial monitor:
char c = client.read();
Serial.print(c);
}
}
// the server's disconnected, stop the client:
client.stop();
Serial.println();
Serial.println("disconnected");
} else {// if not connected:
Serial.println("connection failed");
}
}
Quick Steps


Code Explanation
Read the line-by-line explanation in comment lines of source code!