Early warning of the flood disaster via SMS, in flood-prone areas is very necessary device that informs the security conditions to residents of the area. This is to minimize casualties and losses. With the early warning of the flood, residents are better prepared to anticipate it.
Ultrasonic sensors measure the height of the water surface, when the water is over the limit, then this tool will send SMS messages. SMS sent in the form of water level and flood status by Getway SMS modem. Arduino UNO as a system processor.
Hardware Requirement
- Arduino Uno Board
- Ultrasonic Sensor HC-SR04
- SIM900A GSM Module (you can also use Wavecom)
- RS232 Serial Modul
- LCD 16*2 or 20*4 (with i2c connection is recomended)
- Power supply +5 Volt
- Jumper
Ultrasonic Sensor | Source
Block Diagram
Schematic (GSM Module = Wavecom)
If using SIM900A, then no RS232 circuit, just connect to Arduino.
Arduino - LCD 16x2
Arduino LCD 20x4 Wiring
If using 20x4 LCD and I2C connection (I Square C) then the wiring table is as follows
Arduino - Wavecom GSM Module
If using SIM900A then its wiring is as follows
Arduino - Ultrasonic Sensor
Source Code --> Wavecom
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
LiquidCrystal lcd(2,3, 4, 5, 6, 7);
const int rxpin = 8;
const int txpin = 9;
SoftwareSerial gsm(rxpin, txpin);
const int TRIGPIN = 10;
const int ECHOPIN = 11;
String inString="";
//--------------ganti nomor penerima dengan nomor Anda
String noPenerima="085xxxxxxxxx";
unsigned int jarak, timer, Status;
char f1,f2,f3;
char str,f;
void setup(){
gsm.begin(9600);
pinMode(ECHOPIN, INPUT);
pinMode(TRIGPIN, OUTPUT);
lcd.begin(16, 2);
lcd.print("Tes Koneksi...");
delay(1000);
do{
gsm.println("AT");
getmodem();
}
while(inString == "OK");
lcd.clear();
lcd.print(" Koneksi OK ");
delay(1000);
lcd.clear();
lcd.print("Early Warning");
lcd.setCursor(0,1);
lcd.print("System banjir");
delay(2000);
}
//====================program utama
void loop(){
baca_sensor();
delay(10);
baca_sensor();
lcd.setCursor(0,0);
lcd.print("Jarak air:");
lcd.setCursor(0,1);
lcd.print("Status=");
lcd.setCursor(10,0);
lcd.print(jarak);
lcd.print("cm ");
if (jarak > 100) {
lcd.setCursor(7,1);
lcd.print("Aman ");
Status=1;
if (f1==1){
kirim_sms();
f1=0;
f2=0;
f3=0;
}
}
else if ((jarak < 90) && (jarak > 75)){
lcd.setCursor(7,1);
lcd.print("Waspada ");
if (f1==0){
Status=2;
kirim_sms();
}
f1=1;
f2=0;
f3=0;
}
else if ((jarak < 65) && (jarak > 50)){
lcd.setCursor(7,1);
lcd.print("Awas! ");
if (f2==0){
Status=3;
kirim_sms();
}
f1=0;
f2=1;
f3=0;
}
else if (jarak < 40){
lcd.setCursor(7,1);
lcd.print("Bahaya!!");
if (f3==0){
Status=4;
kirim_sms();
}
f1=0;
f2=0;
f3=1;
}
delay(4000);
}
//====================================baca data serial
void getmodem(){
f=1;
inString="";
while(f){
if(gsm.available()){
str=gsm.read();
switch (str){
case '\r': break;
case '\n':f=0; break;
default:inString+=(char)str;
}
}
}
}
//===================================baca sensor 1
void baca_sensor(){
digitalWrite(TRIGPIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGPIN, LOW);
timer = pulseIn(ECHOPIN, HIGH);
jarak= timer/58;
}
//====================================kirim SMS
void kirim_sms(){
gsm.print("AT+CMGS=");
gsm.println(noPenerima);
delay(1000);
gsm.print("Jarak:");
gsm.print(jarak);
switch (Status){
case 1: gsm.print("cm, Status= Aman");break;
case 2: gsm.print("cm, Status= Waspada");break;
case 3: gsm.print("cm, Status= Awas!");break;
case 4: gsm.print("cm, Status= Bahaya!!");break;
}
gsm.write((byte)26);
gsm.println();
lcd.clear();
lcd.print("Kirim SMS....");
delay(2000);
}
#include <SoftwareSerial.h>
LiquidCrystal lcd(2,3, 4, 5, 6, 7);
const int rxpin = 8;
const int txpin = 9;
SoftwareSerial gsm(rxpin, txpin);
const int TRIGPIN = 10;
const int ECHOPIN = 11;
String inString="";
//--------------ganti nomor penerima dengan nomor Anda
String noPenerima="085xxxxxxxxx";
unsigned int jarak, timer, Status;
char f1,f2,f3;
char str,f;
void setup(){
gsm.begin(9600);
pinMode(ECHOPIN, INPUT);
pinMode(TRIGPIN, OUTPUT);
lcd.begin(16, 2);
lcd.print("Tes Koneksi...");
delay(1000);
do{
gsm.println("AT");
getmodem();
}
while(inString == "OK");
lcd.clear();
lcd.print(" Koneksi OK ");
delay(1000);
lcd.clear();
lcd.print("Early Warning");
lcd.setCursor(0,1);
lcd.print("System banjir");
delay(2000);
}
//====================program utama
void loop(){
baca_sensor();
delay(10);
baca_sensor();
lcd.setCursor(0,0);
lcd.print("Jarak air:");
lcd.setCursor(0,1);
lcd.print("Status=");
lcd.setCursor(10,0);
lcd.print(jarak);
lcd.print("cm ");
if (jarak > 100) {
lcd.setCursor(7,1);
lcd.print("Aman ");
Status=1;
if (f1==1){
kirim_sms();
f1=0;
f2=0;
f3=0;
}
}
else if ((jarak < 90) && (jarak > 75)){
lcd.setCursor(7,1);
lcd.print("Waspada ");
if (f1==0){
Status=2;
kirim_sms();
}
f1=1;
f2=0;
f3=0;
}
else if ((jarak < 65) && (jarak > 50)){
lcd.setCursor(7,1);
lcd.print("Awas! ");
if (f2==0){
Status=3;
kirim_sms();
}
f1=0;
f2=1;
f3=0;
}
else if (jarak < 40){
lcd.setCursor(7,1);
lcd.print("Bahaya!!");
if (f3==0){
Status=4;
kirim_sms();
}
f1=0;
f2=0;
f3=1;
}
delay(4000);
}
//====================================baca data serial
void getmodem(){
f=1;
inString="";
while(f){
if(gsm.available()){
str=gsm.read();
switch (str){
case '\r': break;
case '\n':f=0; break;
default:inString+=(char)str;
}
}
}
}
//===================================baca sensor 1
void baca_sensor(){
digitalWrite(TRIGPIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGPIN, LOW);
timer = pulseIn(ECHOPIN, HIGH);
jarak= timer/58;
}
//====================================kirim SMS
void kirim_sms(){
gsm.print("AT+CMGS=");
gsm.println(noPenerima);
delay(1000);
gsm.print("Jarak:");
gsm.print(jarak);
switch (Status){
case 1: gsm.print("cm, Status= Aman");break;
case 2: gsm.print("cm, Status= Waspada");break;
case 3: gsm.print("cm, Status= Awas!");break;
case 4: gsm.print("cm, Status= Bahaya!!");break;
}
gsm.write((byte)26);
gsm.println();
lcd.clear();
lcd.print("Kirim SMS....");
delay(2000);
}
Coding --> Sim900A (Recomended)
#include <LiquidCrystal_I2C.h>
#include <GPRS_Shield_Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x3F, 20, 4);
#define PIN_TX 9
#define PIN_RX 8
#define BAUDRATE 9600
#define PHONE_NUMBER "085640207374"// sesuaikan
#define MESSAGE_TRUE "Format salah"
const int TRIGPIN = 10;
const int ECHOPIN = 11;
unsigned int jarak, timer, Status;
String aman = "Status : Safe";
String waspada = "Status : Alert 1";
String awas = "Status : Alert 2";
String bahaya = "Status : Alert 3";
String pesan;
char f1, f2, f3;
char str, f;
#define MESSAGE_LENGTH 160
char message[MESSAGE_LENGTH];
int messageIndex = 0;
char data[50];
char phone[16];
char datetime[24];
GPRS gprsTest(PIN_TX, PIN_RX, BAUDRATE); //RX,TX,BaudRate
void setup() {
pinMode(ECHOPIN, INPUT);
pinMode(TRIGPIN, OUTPUT);
lcd.begin();
lcd.setCursor(0, 0);
lcd.println("Initialization....");
delay(1000);
while (!gprsTest.init()) {
delay(1000);
lcd.print("init error\r\n");
}
lcd.println("gprs init success");
//define phone number and text
lcd.setCursor(0, 1);
lcd.print(" OK ");
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Early Warning ");
lcd.setCursor(0, 1);
lcd.print(" flood detect ");
delay(2000);
}
//====================program utama
void loop() {
baca_sensor();
delay(10);
baca_sensor();
lcd.setCursor(0, 2);
lcd.print("Distance :");
lcd.setCursor(0, 3);
lcd.print("Status : ");
lcd.setCursor(12, 2);
lcd.print(jarak);
lcd.print("cm ");
if (jarak > 20) {
lcd.setCursor(10, 3);
lcd.print("Safe ");
Status = 1;
if (f1 == 1) {
kirim_sms();
f1 = 0;
f2 = 0;
f3 = 0;
}
}
else if ((jarak <= 20) && (jarak > 15)) {
lcd.setCursor(10, 3);
lcd.print("Alert 1 ! ");
if (f1 == 0) {
Status = 2;
kirim_sms();
}
f1 = 1;
f2 = 0;
f3 = 0;
}
else if ((jarak <= 15) && (jarak > 10)) {
lcd.setCursor(10, 3);
lcd.print("Alert 2 ! ");
if (f2 == 0) {
Status = 3;
kirim_sms();
}
f1 = 0;
f2 = 1;
f3 = 0;
}
else if (jarak <= 10) {
lcd.setCursor(10, 3);
lcd.print("Alert 3! ");
if (f3 == 0) {
Status = 4;
kirim_sms();
}
f1 = 0;
f2 = 0;
f3 = 1;
}
delay(4000);
}
//===================================baca sensor 1
void baca_sensor() {
digitalWrite(TRIGPIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGPIN, LOW);
timer = pulseIn(ECHOPIN, HIGH);
jarak = timer / 58;
}
//====================================kirim SMS
void kirim_sms() {
delay(1000);
switch (Status) {
case 1: pesan = aman; break;
case 2: pesan = waspada; break;
case 3: pesan = awas; break;
case 4: pesan = bahaya; break;
}
pesan.toCharArray(data, 50);
gprsTest.sendSMS(PHONE_NUMBER, data);
lcd.clear();
lcd.print("Sending SMS....");
delay(2000);
lcd.setCursor(0, 0);
lcd.print(" Early Warning ");
lcd.setCursor(0, 1);
lcd.print(" flood detect ");
}
#include <GPRS_Shield_Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x3F, 20, 4);
#define PIN_TX 9
#define PIN_RX 8
#define BAUDRATE 9600
#define PHONE_NUMBER "085640207374"// sesuaikan
#define MESSAGE_TRUE "Format salah"
const int TRIGPIN = 10;
const int ECHOPIN = 11;
unsigned int jarak, timer, Status;
String aman = "Status : Safe";
String waspada = "Status : Alert 1";
String awas = "Status : Alert 2";
String bahaya = "Status : Alert 3";
String pesan;
char f1, f2, f3;
char str, f;
#define MESSAGE_LENGTH 160
char message[MESSAGE_LENGTH];
int messageIndex = 0;
char data[50];
char phone[16];
char datetime[24];
GPRS gprsTest(PIN_TX, PIN_RX, BAUDRATE); //RX,TX,BaudRate
void setup() {
pinMode(ECHOPIN, INPUT);
pinMode(TRIGPIN, OUTPUT);
lcd.begin();
lcd.setCursor(0, 0);
lcd.println("Initialization....");
delay(1000);
while (!gprsTest.init()) {
delay(1000);
lcd.print("init error\r\n");
}
lcd.println("gprs init success");
//define phone number and text
lcd.setCursor(0, 1);
lcd.print(" OK ");
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Early Warning ");
lcd.setCursor(0, 1);
lcd.print(" flood detect ");
delay(2000);
}
//====================program utama
void loop() {
baca_sensor();
delay(10);
baca_sensor();
lcd.setCursor(0, 2);
lcd.print("Distance :");
lcd.setCursor(0, 3);
lcd.print("Status : ");
lcd.setCursor(12, 2);
lcd.print(jarak);
lcd.print("cm ");
if (jarak > 20) {
lcd.setCursor(10, 3);
lcd.print("Safe ");
Status = 1;
if (f1 == 1) {
kirim_sms();
f1 = 0;
f2 = 0;
f3 = 0;
}
}
else if ((jarak <= 20) && (jarak > 15)) {
lcd.setCursor(10, 3);
lcd.print("Alert 1 ! ");
if (f1 == 0) {
Status = 2;
kirim_sms();
}
f1 = 1;
f2 = 0;
f3 = 0;
}
else if ((jarak <= 15) && (jarak > 10)) {
lcd.setCursor(10, 3);
lcd.print("Alert 2 ! ");
if (f2 == 0) {
Status = 3;
kirim_sms();
}
f1 = 0;
f2 = 1;
f3 = 0;
}
else if (jarak <= 10) {
lcd.setCursor(10, 3);
lcd.print("Alert 3! ");
if (f3 == 0) {
Status = 4;
kirim_sms();
}
f1 = 0;
f2 = 0;
f3 = 1;
}
delay(4000);
}
//===================================baca sensor 1
void baca_sensor() {
digitalWrite(TRIGPIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGPIN, LOW);
timer = pulseIn(ECHOPIN, HIGH);
jarak = timer / 58;
}
//====================================kirim SMS
void kirim_sms() {
delay(1000);
switch (Status) {
case 1: pesan = aman; break;
case 2: pesan = waspada; break;
case 3: pesan = awas; break;
case 4: pesan = bahaya; break;
}
pesan.toCharArray(data, 50);
gprsTest.sendSMS(PHONE_NUMBER, data);
lcd.clear();
lcd.print("Sending SMS....");
delay(2000);
lcd.setCursor(0, 0);
lcd.print(" Early Warning ");
lcd.setCursor(0, 1);
lcd.print(" flood detect ");
}
How it Works
1. Connect the Arduino with Peripherals needed.
2. Plug in the Power Source on the device.
3. Add some library if needed
4. Compile and upload the script program5. First, Modem will initialize and it takes about 3 seconds
4. When there is a change at a certain distance, the status will change
Ultrasonic sensor Installation
Video for Project II - 13. Flood Early Warning System with SMS Based on Arduino
Required file
Hi,
ReplyDeleteKindly advise what means to controlling 2 channel Relay Using SMS??
The 2 channel representative 2 different location/area??
sir how i can build this i have the part arduino MEGA, SIM900, 16lcd, HC-SR04, and RS232 can you send me a how i can build without RS232 just connect to arduino? thankyou i will wait your reply to my email. Thankyou
ReplyDelete