Summer can be a real bummer especially when the temperature can escalates to a dangerously high levels. Sometimes it is critical to monitor the temperature levels frequently and intervene when necessary. However this form of manual monitoring can be easily automated using a simple IoT service.
Today I will share two unique features of the ESPresso Lite V2 board that makes it useful for anyone who wants to build an alert system that can send a push notification directly to your smartphone without complicated programming. At the same time, you can conserve power by making the board asleep 99% of the time. We will be using a digital humidity and temperature sensor, the DHT22 to determine the ambient temperature. Once the temperature reached a certain pre-determined high threshold, it will make a REST API call that push a notification to your smartphone, alerting you of the high temperature or humidity level.
1. Temperature & humidity sensing as an exampleFor this project, we will use the DHT22 sensor to sense the ambient temperature and humidity levels. This sensor can be plugged in directly into the header provided on the ESPresso Lite V2 board without the need for jumper wires. Similarly for the OLED display as well.
2. Setting up push notificationIn order to send a push notification to your smartphone, you will need to set up a FREE espert.io cloud account so that a 16-digit smartphone API key can be generated and used in the attached Arduino sketch below.
The step-by-step tutorial to obtain the smartphone key (which involves creating an espert.io cloud account, downloading the Espert IoT app and navigating & testing the notification services) is available here.
3. Copy, modify and upload the Arduino sketch below#include <ESPert.h>
ESPert espert;
const char *host = "www.espert.io";
String smartphone_key = "56305xxxx6000"; //replace with your smartphone key
int temperature = 0;
int humidity = 0;
int temp_threshold = 35; //set temp threshold to 35C
int hum_threshold = 80; // set humidity threshold to 80%
const int sleepTimeS = 600; //wakes up every 10 mins
void setup()
{
espert.init();
espert.dht.init();
espert.oled.init();
delay(2000);
espert.oled.clear();
espert.oled.println(espert.info.getId());
espert.oled.println();
int mode = espert.wifi.init();
if (mode == ESPERT_WIFI_MODE_CONNECT)
{
espert.println(">>> WiFi mode: connected.");
espert.oled.println("WiFi: connected.");
espert.oled.print("IP..: ");
espert.oled.println(espert.wifi.getLocalIP());
}
else if (mode == ESPERT_WIFI_MODE_DISCONNECT)
{
espert.println(">>> WiFi mode: disconnected.");
espert.oled.println("WiFi: not connected.");
}
else if (mode == ESPERT_WIFI_MODE_SMARTCONFIG)
{
espert.println(">>> WiFi mode: smart config.");
}
else if (mode == ESPERT_WIFI_MODE_SETTINGAP)
{
espert.println(">>> WiFi mode: access point.");
}
}
void loop()
{
espert.loop();
float t = espert.dht.getTemperature();
float h = espert.dht.getHumidity();
if(!isnan(t) && !isnan(h))
{
temperature = t;
humidity = h;
}
if (t > temp_threshold || h > hum_threshold)
{
String message = "Warning! Temperature now is " + (String)(temperature) + "C. Humidity now is " + (String)(humidity) + "%%";
message.replace(String(" "), String("%20"));
String path = "/MySmartphone/send?key=" + smartphone_key + "&message=" + message;
espert.println(">>" + espert.wifi.getHTTP(host, path.c_str()) + "<<");
}
delay(5000);
espert.oled.clear();
ESP.deepSleep(sleepTimeS * 1000000); //goes to deep sleep
}
Based on the Arduino sketch above, the ESPresso Lite V2 board will wake up every 10 minutes (deep sleep for 600 seconds). It will then connected to the Internet via a local WI-Fi router, obtain and transmit the temperature and humidity sensor data to the 'cloud' and goes back to sleep again. If the data obtained is above the pre-set values, it will trigger the push notification to your smartphone.
Comments