Peringatan dini terhadap bencana banjir via SMS, pada daerah rawan banjir sangat diperlukan perangkat yang menginformasikan kondisi keamanan kepada warga dearah tersebut. Hal ini untuk meminimalisir korban dan kerugian. Dengan adanya peringatan dini terhadap banjir, warga lebih siap untuk mengantisipasinya.
Sensor ultrasonik mengukur ketinggian permukaan air, pada saat air sudah melewati batas, maka alat ini akan mengirimkan pesan SMS. SMS yang dikirim berupa ketinggian permukaan air dan status banjir oleh modem SMS Getway. Arduino UNO sebagai pengolah sistem.
Kebutuhan Hardware
- Sensor Ultrasonic HC-SR04
- Modem SMS Getway (SIM900A)
- Modul Serial RS232
- Modul LCD 2x16 atau 20x4 (dengan koneksi i2c)
- Modul Arduino UNO
- Power supply +5Volt
Ultrasonic Sensor | Source
SIM900A | Source
Diagram Blok
Schematic
Jika menggunakan SIM900A, maka tidak perlu rangkaian RS232, langsung saja koneksikan ke Arduino.
Arduino - LCD 16x2
Arduino LCD 20x4
Jika menggunakan LCD 20x4 dan koneksi I2C (I Square C) maka wiringya adalah sebagai berikut
Selengkapnya tentang koneksi I2C --> Project V - 14
Arduino - Ultrasonic Sensor
Arduino - Wavecom GSM Module
#include <LiquidCrystal.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
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);
}
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
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 ");
}
Cara Kerja Alat
1. Koneksikan antara sistem Arduino dengan peripheral lain seperti pada rangkaian (skematik).
2. Pasang power supply (adaptor 5 V) dan hidupkan (colokkan ke sumber PLN 220V) sehingga
lampu LED indikator nyala, LCD juga nyala.
3. Ketika pertama kali dihidupkan.
4. Ketika ada perubahan pada jarak tertentu, maka status akan berubah
5. Secara otomatis akan mengirimkan pesan status tersebut melalui SMS ke nomer yang telah
ditentukan.
Diagram pemasangan sensor ultrasonik
Video untuk Project II - 13. Sistem Peringatan Dini Bencana Banjir dengan SMS Berbasis Arduino
KONTAK KAMI 085743320570 (adi sanjaya)
No comments:
Post a Comment