Everything about Internet of Things and more

Blynk Email and Push Notifications tutorial – ESP8266 Arduino Example

Gearbest  promotion

In this quick tutorial we are going to learn how to send emails and push notifications from the WiFi ESP8266 module, or any other IoT device, using Blynk Email and Push Notification APIs. For this demonstration we are going to build a simple thermometer project and then setup temperature Alarm points. Whenever the alarms will trigger, an email and a push notification will be sent.

Project difficulty

This project requires low to medium programming knowledge and medium electronics knowledge. To complete this project you will spend minimum 20 minutes.

Required materials and hardware

Blynk Email and Notification - ESP8266 Example (1)

IoT Blynk Email and Push Notifications – Arduino example using ESP8266

At this time, from what I found, the simplest method to send Emails from a ESP8266 WiFi module is by using IoT Blynk platform. By calling Blynk APIs in Arduino code, we can achieve this very simple and fast. If this is your first time when hearing about ESP8266 modules you should first checkout this ESP8266 tutorial. Also if you are into IoT but you never used Blynk read here a complete Blynk tutorial with video examples.

Project setup – step by step

  1. Setup your hardware project following the hookup sketch below (skip this, if you already have a working IoT test environment)
  2. Download and install the Blynk app on your smartphone – Android, IOS
  3. Setup a new Blynk Project on your smartphone – see here how create a Blynk project
  4. Add Email and Notification Widgets on your Blynk project (see images below)
  5. Get the Authorization Token from the Blynk Project
  6. Open Arduino IDE and paste my DHT22 Thermometer sketch example
  7. Upload the sketch into your ESP8266 Module

In the image below you can see Blynk Email and Push Notification Widgets in the widget box, and also dragged on the dashboard. The Email Widgets gives you the possibility to overwrite the email address from the application.

Blynk Email and Notification - ESP8266 Example (2)

The Arduino code is pretty simple. The Arduino example below is made for a prototype using ESP8266 version 01 and DHT22 Temperature and Humidity sensor. The DHT22 is hooked on the GPIO02 and defined as DHTPIN 2. The readings are made in a loop interval of 2,5 seconds, as the DHT22 requires at least 2 seconds to refresh the measurements. Have a look over this code and after that we will continue the explaining:

/* Blynk EMAIL and NOTIFICATION
 * ESP8266 example
 * www.geekstips.com
*/
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "****************************";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*************";
char pass[] = "*************";

#define DHTPIN 2          // What digital pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11     // DHT 11
#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301
int alarmPin = 4;
int led1 = 16;
int led2 = 14;
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;

void sendSensor(){
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Serial.println(t);
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);

  // SETUP the ALARM Trigger and Send EMAIL 
  // and PUSH Notification

  if(t > 28){
    Blynk.email("vaduva.ionut.lucian@gmail.com", "ESP8266 Alert", "Temperature over 28C!");
    Blynk.notify("ESP8266 Alert - Temperature over 28C!");
  }
}

void setup(){
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  dht.begin();
  timer.setInterval(2500L, sendSensor);
}

void loop(){
  Blynk.run();
  timer.run();
}

Nothing so new, nothing so hard. As I promise you, to achieve our goal we just need to add only two new lines:

//Blynk API call for EMAIL sending
Blynk.email("vaduva.ionut.lucian@gmail.com", "ESP8266 Alert", "Temperature over 28C!");
//Blynk API call for NOTIFICATION pushing
Blynk.notify("ESP8266 Alert - Temperature over 28C!");

As you can see in the example above, first line stands for calling the Blynk Email API. Execution is done with 3 parameters: email address, subject and body, pretty much familiar as in many programming languages.

Blynk Email limitation and downsides

Maximum allowed length is 120 symbols for all email + subject + message. However you can increase this limit if necessary by adding following commands to you sketch:

#define BLYNK_MAX_SENDBYTES XXX

Where XXX is desired max length of your email. For example for ESP you can set this to 1200 max length #define BLYNK_MAX_SENDBYTES 1200. Note that this line must be on top of any of the Blynk includes in your sketch.

The time limit between sending emails is minimum 15 seconds. In case you are using gmail you are limited with 500 mails per day (by google). Other providers may have similar limitations, so please be careful. The Blynk free cloud server gives you a maximum of 100 emails every day.

The second line obviously calls the Notification API which triggers Mobile OS specific notifications. The Blynk Push notification API offers two additional options as follows:

Blynk Push Notifications limitation and downsides

I think that, for most of you, the above limitations will not affect the project flow. Therefore, this is a great way to achieve emails and push notifications, having no costs whatsoever. Even at some point we need to pay a bit to extend the Blynk potential, considering the benefits I really have no problem paying.

If you want to find more about which are the best temperature sensors in Internet of Things projects, read this awesome comparison between DHT22 and DS18B20 sensors.

Hoping that this article inspired you, i kindly invite you share this articlesubscribe my YouTube channel and join the communities on social networks. Please feel free to comment or send suggestions / remarks so i can improve the content quality!

Gearbest  promotion

Share on: Facebook Twitter Google+

3 Replies to “Blynk Email and Push Notifications tutorial – ESP8266 Arduino Example”

  1. Maria Nurlela Dabukke says:

    Hi,
    May I know how much is voltage of the breadboard power supply?

    • Hello, the breadboard power supply provides both 5v and 3v3. For ESP you should use 3v3.

  2. Maria Nurlela Dabukke says:

    Hi,
    Where is I can found the complete circuit diagram?

    Thanks

Leave a Reply

Your email address will not be published.