top of page
Writer's pictureRamesh G

IoT Flood Monitoring and Email, SMS alert System

Updated: Jul 2, 2021



Here to learn how to build an IoT Based Flood Monitoring and Email, SMS alert System using Ultrasonic, NodeMCU ESP8266 12E, myDevices Cayenne. In more detail, this IoT tutorial discovers how to use an ESP8266 to send data to Cayenne using the MQTT protocol.


Abstract: Flood is one of the natural disasters that cannot be avoided. It happens too fast and affected so many lives and properties. Before this, most of the existing system that has been developed are only focus on certain areas. Other than that, majority of the public cannot monitor and have no idea when the flood going to be happened since they do not have any information and data about the weather condition. This system is suitable for cities and village areas. Furthermore, if the public has an internet access, they can monitor what is happening and predict if there is any upcoming flood at the web server. This project will update the water level at the web server and the system will issue an alert signal to the citizens for evacuation so that fast necessary actions can be taken.

This is a complete step-by-step tutorial on building an IoT system using Cayenne and ESP.

On the other hand, Cayenne is an IoT cloud platform that provides several cloud services, such as:

  • Data visualization

  • IoT cloud

  • Alerts

  • Scheduling Events

We will focus our attention on data visualization and on the IoT cloud services.

Cayenne IoT Platform accelerates the development of IoT-based solutions, including quick design, prototyping and other commercialized projects. It is a drag-and-drop IoT project builder that can help developers build complete, ready-to-use IoT solutions with little to no coding.

Cayenne IoT Platform contains a vast catalogue of certified IoT-ready devices and connectivity options. This allows users to easily add any device to the library utilizing MQTT API. All devices in Cayenne are interoperable and benefit from features such as rules engine, asset tracking, remote monitoring and control, and tools to visualize real-time and historical data.

MQTT is a lightweight messaging protocol for sensors and mobile devices.


Circuit Diagram




Components Required

  • ESP8266 NodeMCU

  • Ultrasonic Sensor

  • LEDs (Red & Green)

  • Breadboard

  • Jumpers

NodeMCU

NodeMCU ESP8266-12E MCU is a development board with one analogue and many general-purpose input output (GPIO) pins. It has 4MB flash memory, and can operate at a default clock frequency of 80MHz. In this project, digital pin D1 of NodeMCU is used to read Data of Dht11 temperature sensor.


Ultrasonic:

The HC-SR04 ultrasonic module is a module that can provide non-contact measurement within the range of 2cm to 400cm with ranging accuracy that can reach 3mm. It works on the principle of echolocation.

The ultrasonic sensor as a trigger and an echo pin. The arduino provides a high signal of 10microseconds to this pin. After the HC-SR04 is triggered, it sends out eight 40Khz sound waves to the surface of the water. On getting to the surface of the water, the wave is echoed back to the sensor and the ESP8266 reads the echo pin to determine time spent between triggering and receiving of the echo. Since we know that the speed of sound is around 340m/s then we can calculate the distance using;

Distance = (time/2)*speed of sound


Ultrasonic HC-SR04 wiring to ESP8266

Ultrasonic HC-SR04 ESP8266

Vcc Pin Vin Pin

Trig Pin D1 (GPIO 5)

Echo Pin D2 (GPIO 4)

GND Pin GND

Installing the ESP8266_Arduino_Library

To get readings from the Ultrasonic HC-SR04 sensor module you need to have the next library installed:


Download the Cayenne-MQTT-ESP-master library from this link.

Click on Add ZIP Library and add Cayenne-MQTT-ESP-master zip file, or directly copy the folder (Cayenne-MQTT-ESP-master) and paste it in Libraries folder of Arduino IDE.


After installing the library, go to your Arduino IDE. Make sure you have the Nodemcu 1.0 ESP-12E board selected, and then, Copy and Paste code in Arduino IDE.


Subscribe and Download code.


Arduino Code

#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space

#include <Ultrasonic.h>

#include <ESP8266WiFi.h>


Ultrasonic ultrasonic(D1, D2);

const int AlertLED = D3;

#define NormalLED D4


int distance;

int val = 0;


#include <CayenneMQTTESP8266.h>


char ssid[] = "TP-Link_3200"; // your SSID

char password[]="9500112137"; // your WIFi password


char username[] = "2031dd30-5414-11eb-b767-3f1a8f1211ba";

char mqtt_password[] = "f2ce829d98df3a768328ac6936eae9fd47d28289";

char client_id[] = "b15f5e30-5ba9-11eb-b767-3f1a8f1211ba";



void setup() {

Serial.begin(9600);

Serial.print("Setup");


Cayenne.begin(username,mqtt_password,client_id,ssid,password);

pinMode(NormalLED, OUTPUT);

pinMode(AlertLED, OUTPUT);

digitalWrite(NormalLED, LOW);

digitalWrite(AlertLED, LOW);

}


void loop()

{


//Run Cayenne Functions


Cayenne.loop();


}

CAYENNE_OUT(V0){

do {

distance = ultrasonic.read();

delay(2000);


} while (isnan(distance));

Serial.print("Distance in CM: ");

Serial.println(distance);

if (distance <= 3)

{

digitalWrite(D3, HIGH);

digitalWrite(D4, LOW);

}

else

{

digitalWrite(D4, HIGH);

digitalWrite(D3, LOW);

}

Cayenne.virtualWrite(V0, distance);

}

CAYENNE_OUT(V1){

Serial.print(digitalRead(D3));

Cayenne.virtualWrite(V1, digitalRead(D3));

}


Result:

Water drop in bowl raises, the flood alert RED LED to glow and Normal flood condition Green LED OFF.


Hardware interfacing with Cayenne IoT platform

To interface the circuit with the IoT platform, open this link on any browser.

Refer previous tutorial for more deatil about cayenne


Click on Sign Up. Fill all the fields and click on Get Started

Click on Add new and then Device/Widget in Settings, Add New Device here and select Generic ESP8266 for in this project.

Configure device Generic ESP8266, MQTT username, password and client ID from Create App

Paste these respective details under username, password and client ID in Arduino source code , along with your Wi-Fi name and password.

After successfully compiling and uploading the code to NodeMCU, You will see ESP8266 connected to Wi-Fi. After the connection is established, the previous page is automatically updated on Cayenne. A new dashboard opens in the browser. Cayenne generates an ID and a device icon for your device.

Click on Custom Widgets and then value, and populate all fields . The channel number should be 1. (Make sure the channel number is same as in code.) Now, click on Add Widget.

When a connection is made, sensor data gets uploaded to Cayenne. Distance and digital output LED state data on Cayenne.

You can get a graphical representation of flood monitor data by clicking on the Graph icon.

You can set Trigger alert using if and then condition, and add Mobile number and email for receiving alert message.

You can set Trigger alert ON/OFF

If Once sensor data gets Reached to Threshold then digital output LED state data to Cayenne.

then Flood alert notify value changed to 1.00.

You can get a graphical representation of flood Alert data by clicking on the Graph icon.

And also Trigger send alert message to Email.


And Trigger send alert message to Mobile.



2,030 views0 comments

Comments


bottom of page