Send Email Alerts With Arduino (IoT)

by c26ab1 in Circuits > Arduino

3284 Views, 9 Favorites, 0 Comments

Send Email Alerts With Arduino (IoT)

instructablesHead.png

In this Instructable we will build a circuit with an esp8266 nodeMCU to send email alerts based on sensor data.

Products to keep your home safe are way more expensive than they should be. The components they use are inexpensive and the code to make them work is openly accessible. That is why I decided to make my own safe home circuit. It uses a temperature sensor, and when the temperature is too high, you get an email alert.

The temperature sensor can be replaced with other sensors that have more critical data, like a carbon monoxide sensor.

Supplies

Prepare Google Account

The emails we send will initiate through the NodeMCU, but send through your google account. To allow this to happen we have to be able to log into your Google account through c++. This means we have to generate a special app password for your google account. Follow these simple instructions to do that:

  • Go to google.com and sign in
  • Click the nine box array menu in the top right
  • Click account
  • On the left side menu, click security
  • Under "Signing in to Google" make sure you have two step verification turned on, then click App Passwords
  • Click select app and pick "other (custom name)"
  • Name it whatever you would like, c++ makes sense for example, but the name does not matter, it is simply for organization
  • Click generate, and copy and note down the custom 16 letter password it gives you, we will use this in our code

Write the Code

Download the following code and open it in Arduino IDE. Make sure to read the comments because they will tell you what filler code to replace with your own credentials. Also make sure to install the libraries (lines 1-4) that you don't have.

Set Up Esp8266 NodeMCU

If you have an esp8266 NodeMCU which you have not set up yet, follow this Instructable first to set it up and then come back for step 2.

Create Circuit

IMG_5533.jpg

Attach your esp8266 nodeMCU to a breadboard. Connect the left pin (when the flat side is facing you) of the tmp36 temperature sensor to 3.3v, the center pin to A0, and the right pin to ground.

Run the Code

IMG_5535.jpg

Connect with the esp8266 to your computer with a micro usb and select the port that you are using in Arduino IDE. Upload the code to the board (this will take around 30 seconds because the file is large).

Open the serial monitor to see the WiFi connection status and temperature. Once the serial monitor prints this message: "Message sent successfully" you should receive an email with the temperature data.

Warm up the temperature sensor by placing your fingers on it. Watch the temperature in the serial monitor go up. Once it reaches 81 it will send you an emergency email. Of course 81 degrees fahrenheit is not an emergency, this is just to display the capability of emailing when a sensor is at a certain point. If you are interested in using this to receive an email in a real emergency you can change the temperature on line 108.