Arduino- Temperature - Send Email Notification
Arduino- Temperature - Send Email Notification
We are going to learn how to use Arduino to send a notification to you via email when the temperature exceeds a threshold. We will use Arduino, the waterproof DS18B20 temperature sensor, and Ethernet Shield.
Alternatives: by making a small modification in the Arduino code:

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



What we need to do
We need to do to main tasks:
How it works
When the temperature exceeds a threshold:
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-temperature-send-email-notification
*/
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define TEMP_THRESHOLD 27 // °C
#define SENSOR_PIN 13 // Arduino pin connected to DS18B20 sensor's DQ pin
OneWire oneWire(SENSOR_PIN); // setup a oneWire instance
DallasTemperature DS18B20(&oneWire); // pass oneWire to DallasTemperature library
// 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
bool isSent = false;
void setup() {
Serial.begin(9600);
Serial.println("TEMPERATURE 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);
}
DS18B20.begin(); // initialize the sensor
}
void loop() {
DS18B20.requestTemperatures(); // send the command to get temperatures
float temperature = DS18B20.getTempCByIndex(0); // read temperature in Celsius
Serial.print("Temperature: ");
Serial.print(temperature); // print the temperature in Celsius
Serial.println("°C");
if (temperature >= TEMP_THRESHOLD) {
if (isSent == false) { // to make sure that Arduino does not send duplicated emails
sendEmail(temperature);
isSent = true;
}
} else {
isSent = false; // reset to send if the temperature exceeds threshold again
}
}
void sendEmail(float temperature) {
// 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:
String queryString = "?value1=" + String(temperature);
// send HTTP header
client.println("GET " + PATH_NAME + queryString + " 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!
