Vaibhav Shanbhag
Published

IoT Based Flood Monitoring And Alerting System

It senses the appropriate water-level distance and sends Sms/Email alerts when the water-level crosses the intermediate level or max level

IntermediateFull instructions provided4 hours26,146
IoT Based Flood Monitoring And Alerting System

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
5 mm LED: Green
5 mm LED: Green
×1
5 mm LED: Orange
×1
5 mm LED: Red
5 mm LED: Red
×1
Buzzer
Buzzer
×1
RGB Backlight LCD - 16x2
Adafruit RGB Backlight LCD - 16x2
×1
Temperature Sensor
Temperature Sensor
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×15
Male/Male Jumper Wires
×10
Female/Female Jumper Wires
Female/Female Jumper Wires
×5
9V battery (generic)
9V battery (generic)
×1
USB-A to B Cable
USB-A to B Cable
×1

Software apps and online services

Arduino IDE
Arduino IDE
Python 3.7 IDLE
Bolt IoT Android App
Bolt IoT Android App
Bolt Cloud
Bolt IoT Bolt Cloud
SMS Messaging API
Twilio SMS Messaging API
Mailgun - EMAIL Messaging API

Hand tools and fabrication machines

Tape, Electrical
Tape, Electrical
Cello Tape

Story

Read more

Schematics

Schematics Diagram of the Project

Code

Code for Arduino

Arduino
//IOT Based Flood Monitoring And Alerting System.
#include<LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7);
   
const int in=8;
const int out=9;
const int green=10;
const int orange=11;
const int red=12;
const int buzz=13;

void setup(){
Serial.begin(9600);
lcd.begin(16,2);
pinMode(in, INPUT);
pinMode(out, OUTPUT);
pinMode(green, OUTPUT);
pinMode(orange, OUTPUT);
pinMode(red, OUTPUT);
pinMode(buzz, OUTPUT);
digitalWrite(green,LOW);
digitalWrite(orange,LOW);
digitalWrite(red,LOW);
digitalWrite(buzz,LOW);
lcd.setCursor(0,0);
lcd.print("Flood Monitoring");
lcd.setCursor(0,1);
lcd.print("Alerting System");
delay(5000);
lcd.clear();
}

void loop()
{
long dur;
long dist;
long per;
digitalWrite(out,LOW);
delayMicroseconds(2);
digitalWrite(out,HIGH);
delayMicroseconds(10);
digitalWrite(out,LOW);
dur=pulseIn(in,HIGH);
dist=(dur*0.034)/2;
per=map(dist,10.5,2,0,100);
#map function is used to convert the distance into percentage.
if(per<0)
{
  per=0;
}
if(per>100)
{
  per=100;
}
Serial.println(String(per));
lcd.setCursor(0,0);
lcd.print("Water Level:");
lcd.print(String(per));
lcd.print("%  ");
if(per>=80)       #MAX Level of Water--Red Alert!
{
  lcd.setCursor(0,1);
  lcd.print("Red Alert!   ");
  digitalWrite(red,HIGH);
  digitalWrite(green,LOW);
  digitalWrite(orange,LOW);
  digitalWrite(buzz,HIGH);
  delay(2000);
  digitalWrite(buzz,LOW);
  delay(2000);
  digitalWrite(buzz,HIGH);
  delay(2000);
  digitalWrite(buzz,LOW);
  delay(2000);
    
}
else if(per>=55)    #Intermedite Level of Water--Orange Alert!
{
  lcd.setCursor(0,1);
  lcd.print("Orange Alert!  ");
  digitalWrite(orange,HIGH);
  digitalWrite(red,LOW);
  digitalWrite(green,LOW);
  digitalWrite(buzz,HIGH);
  delay(3000);
  digitalWrite(buzz,LOW);
  delay(3000);
  
}else          #MIN/NORMAL level of Water--Green Alert!
{
 lcd.setCursor(0,1);
 lcd.print("Green Alert!  ");
 digitalWrite(green,HIGH); 
 digitalWrite(orange,LOW);
 digitalWrite(red,LOW);
 digitalWrite(buzz,LOW);
}

delay(15000);
}

Code for conf.py

Python
#twillo details for sending alert sms
SID = 'You can find SID in your Twilio Dashboard' 
AUTH_TOKEN = 'You can find  on your Twilio Dashboard' 
FROM_NUMBER = 'This is the no. generated by Twilio. You can find this on your Twilio Dashboard'
TO_NUMBER = 'This is your number. Make sure you are adding +91 in beginning'

#bolt iot details
API_KEY = 'XXXXXXXXX'  #This is your Bolt cloud API 
Key.  
DEVICE_ID = 'BOLTXXXXXXXXX' #This is the ID of your Bolt device.

#mailgun details for sending alert E-mails
MAILGUN_API_KEY = 'This is the private API key which you can find on your Mailgun Dashboard' 
SANDBOX_URL= 'You can find this on your Mailgun Dashboard' 
SENDER_EMAIL = 'test@ + SANDBOX_URL' # No need to modify this. The sandbox URL is of the format test@YOUR_SANDBOX_URL
RECIPIENT_EMAIL = 'Enter your Email ID Here'

Code for main.py

Python
import conf
from boltiot import Sms, Email, Bolt
import json, time

intermediate_value = 55
max_value = 80


mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
mailer = Email(conf.MAILGUN_API_KEY, conf.SANDBOX_URL, conf.SENDER_EMAIL, conf.RECIPIENT_EMAIL)


def twillo_message(message):
  try:
     print("Making request to Twilio to send a SMS")
     response = sms.send_sms(message)
     print("Response received from Twilio is: " + str(response))
     print("Status of SMS at Twilio is :" + str(response.status))
  except Exception as e:
     print("Below are the details")
     print(e)

def mailgun_message(head,message_1):
  try:
     print("Making request to Mailgun to send an email")
     response = mailer.send_email(head,message_1)
     print("Response received from Mailgun is: " + response.text)
  except Exception as e:
     print("Below are the details")
     print(e)
     
while True:
    print ("Reading Water-Level Value")
    response_1 = mybolt.serialRead('10')
    response = mybolt.analogRead('A0')
    data_1 = json.loads(response_1)
    data = json.loads(response) 
    Water_level = data_1['value'].rstrip()
    print("Water Level value is: " + str(Water_level) + "%")
    sensor_value = int(data['value'])
    temp = (100*sensor_value)/1024
    temp_value = round(temp,2)
    print("Temperature is: " + str(temp_value) + "°C")
    try: 
 
        if int(Water_level) >= intermediate_value:
            message ="Orange Alert!. Water level is increased by " +str(Water_level) + "% at your place. Please be Safe. The current Temperature is " + str(temp_value) + "°C."
            head="Orange Alert"
            message_1="Water level is increased by " + str(Water_level) + "% at your place. Please be Safe. The current Temperature is " + str(temp_value) + "°C."
            twillo_message(message)
            mailgun_message(head,message_1)

        if int(Water_level) >= max_value:
           message ="Red Alert!. Water level is increased by " + str(Water_level) + "% at your place. Please Don't move out of the house. The Current Temperature is " + str(temp_value) + "°C"
           head="Red Alert!"
           message_1="Water level is increased by " + str(Water_level) + "% at your place. Please Don't move out of the house. The Current Temperature is " + str(temp_value) + "°C."
           twillo_message(message)
           mailgun_message(head,message_1)

    except Exception as e: 
        print ("Error occured: Below are the details")
        print (e)
    time.sleep(15)

Credits

Vaibhav Shanbhag

Vaibhav Shanbhag

1 project • 4 followers

Comments