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:
- You can also use any other Ethernet or WiFi shield.
- You can also use other temperature sensor such as LM35, DHT11, DHT22... For more detailed:
- Arduino - LM35 temperature sensor tutorial
- Arduino Uno R4 WiFi
- Arduino Uno/Mega with Ethernet Shield
- Arduino - DS18B20 Temperature Sensor tutorial
- Arduino - Send Email tutorial
- If using the Ethernet Shield, stack Ethernet Shield on Arduino Uno or Mega
- Connect the temperature sensor to Arduino as below writing diagram
- Wiring diagram with breadboard
- Wiring diagram with adapter (recommended)
- Real wiring diagram with adapter
- Create an Applet on the IFTTT website
- Write Arduino code that makes an HTTP request to the Applet when the temperature exceeds a threshold
- Arduino makes an HTTP request to IFTTT Applet we created,
- The IFTTT Applet will send an email to the email address.
- Create an IFTTT account and Login to IFTTT.
- Go to IFTTT Home page and click the Create button
- Click the Add button
- Search for Webhooks, and then click the Webhooks icon
- Click the Receive a web request icon
- Click the Connect button
- Type an event name. You can give any name you want and memorize it to use later. The event name is a part of URL that Arduino will make request to. In this tutorial, we use a name send-email. And then click Create trigger button
- Click the Add button to add the action
- Search for email, and then click the Email icon
- Click the Send me an email icon
- Click the Connnect button
- Input your email address and then click the Semd PIN button
- You will receive an email, get the PIN from email and input to Web UI to do verification
- After that the email subject and content editor appears
- You can give any subject and content for the email. The below are example
- Subject:
- Content:
- Click the Create Action button
- Click the Continue button
- Click the Finish button
- Visit IFTTT Webhooks page
- Click the Documentation button
- You will see the Webhooks key as below
- Copy and wire down your Webhooks to use on Arduino code.
- In the URL, the send-email is the event name we used:
- If you already used this name for another Applet, you can give it any other name.
- If you use another name, please replace the send-email by your event name
- Webhooks key is generated by IFTTT. Please keep it secret. You can change it by regenerating it on the IFTTT website.
- Open a web browser
- Copy the below link:
- Paste it on the address bar of the web browser
- Replace XXXXXXXXXXXXXXXXXXXXX with your Webhooks key.
- Press the enter key on your keyboard. You will see the browser display the message as below image.
- And you will receive an email.
- If using the Ethernet Shield, stack Ethernet Shield on Arduino
- Do wiring as above image
- Connect Arduino to PC via USB cable
- Open Arduino IDE, select the right board and port
- Navigate to the Libraries icon on the left bar of the Arduino IDE.
- Search “DallasTemperature”, then find the DallasTemperature library by Miles Burton.
- Click Install button to install DallasTemperature library.
- You will be asked to install the library dependency
- Click Install All button to install OneWire library.
- Copy the above code and open with Arduino IDE
- Click Upload button on Arduino IDE to upload code to Arduino
- Put the sensor on hot and cold water, or grasp the sensor by your hand
- You will receive an email notification as below
- The log on Serial Monitor as below:
The tutorial provides the Arduino code for two cases:
Hardware Required
Alternatively if using Ethernet:
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some links direct to products from our own brand, DIYables.
Buy Note: Many DS18B20 sensors on the market are low-quality. We highly recommend buying the sensor from the DIYables brand using the link above. We tested it, and it worked well.
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
This image is created using Fritzing. Click to enlarge image
This image is created using Fritzing. Click to enlarge image
This image is created using Fritzing. Click to enlarge image
We suggest purchasing a DS18B20 sensor that comes with a wiring adapter for easy connection. The adapter has a built-in resistor, eliminating the need for a separate one in the wiring.
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
Measured Time: {{OccurredAt}}
Take care of yourself!
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 for Arduino Uno R4 WiFi
Arduino Code for Arduino and Ethernet Shield
Quick Steps
Code Explanation
Read the line-by-line explanation in comment lines of source code!
Video Tutorial
We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.