Translate

Membuat Alat Monitoring Jarak Menggunakan HC-SRF04 dan OUTPUT SMS GATEWAY - ALARM INDIKATOR

Membuat Alat Monitoring Jarak Menggunakan HC-SRF04 dan OUTPUT SMS GATEWAY - ALARM INDIKATOR


       Pada tengah malam ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang fungsinya yaitu untuk memonitor jarak benda atau jarak air / ketinggian level air menggunakan sensor ultrasonik HC-SRF04 dengan output sms, alarm buzzer dan indikator led, selain itu ada sebuah motor yang digunakan untuk membuka palang pintu air saat air telah mencapai level tertentu, kemudian akan menutup kembali saat mencapai level yang telah di setting sebelumnya. untuk lebih jelasnya berikut adalah skema dan programnya.





a. Arduino Mega






b. Modul SMS SIM800L





c. Buck Converter Modul





d. Sensor HC-SRF04





e. Motor Driver L298






f. Program Arduino IDE

//vcc sim800l adalah 4.0 volt
// hubungkan RX-TX di pin 50 dan 51

#include "SIM900.h"
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>

#define trigPin 8
#define echoPin 9

#include "sms.h"
SMSGSM sms;

LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

long duration, distance;

const int btset = A7;
const int btup = A6;
const int btdown = A5;
const int btsimpan = A4 ;

int mtr1 = 10;
int mtr2 = 11;
int kecepatan = 12;

int level1;
int level2;
int level3;

int btsetx;
int btupx;
int btdownx;
int btsimpanx;

int ledmerah = A2;
int ledkuning = A1;
int ledhijau = A0;
int buzzer = A3;

int simpanlevel1;
int simpanlevel2;
int simpanlevel3;

int mark = 0;
int markx = 0;

int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];


void setup() {
     //Serial connection.
     Serial.begin(9600);
     Serial.println("GSM Shield testing.");
     //Start configuration of shield with baudrate.
     //For http uses is raccomanded to use 4800 or slower.
     if (gsm.begin(2400)) {
          Serial.println("\nstatus=READY");
          started=true;
     } else Serial.println("\nstatus=IDLE");

     if(started) {
          //Enable this two lines if you want to send an SMS.
          if (sms.SendSMS("085348017819", "ALAT READY"))
          Serial.println("\nSMS sent OK");
          if (sms.SendSMS("082157306006", "ALAT READY"))
          Serial.println("\nSMS sent OK");
     }

  digitalWrite(A3,HIGH);
 
  lcd.begin(16, 2);
  lcd.clear();
  lcd.noCursor();
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(btset, INPUT);
  pinMode(btup, INPUT);
  pinMode(btdown, INPUT);
  pinMode(btsimpan, INPUT);
  digitalWrite(btset,HIGH);
  digitalWrite(btup,HIGH);
  digitalWrite(btdown,HIGH);
  digitalWrite(btsimpan,HIGH);
  pinMode(ledmerah, OUTPUT);
  pinMode(ledkuning, OUTPUT);
  pinMode(ledhijau, OUTPUT);
  pinMode(buzzer, OUTPUT);
 
 
}

void loop() {

mark = 0;

btsetx = digitalRead(btset);
btsimpanx = digitalRead(btsimpan);

if(btsetx == 0){
  delay(200);
  lcd.clear(); 
  setting2();
  delay(1000);
  setting3();
  delay(1000);

  }

if(btsimpanx == 0){
  delay(200);
  lcd.clear(); 
  showlevel(); 
  }

  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
 
  lcd.setCursor(0, 0);
  lcd.print("Level= ");
  lcd.print(distance);
  lcd.setCursor(0, 1);
  lcd.print("SET       SIMPAN");


if((simpanlevel1 == 0)&&(simpanlevel2 == 0)&&(simpanlevel3 == 0)&&(mark == 0)){
  digitalWrite(ledmerah,LOW);
  digitalWrite(ledkuning,LOW);
  digitalWrite(ledhijau,LOW);
  digitalWrite(buzzer,HIGH);
  mark = 1;
}


if((distance <= simpanlevel3)&&(mark == 0)){
  digitalWrite(ledmerah,HIGH); 
  digitalWrite(ledkuning,LOW);
  digitalWrite(ledhijau,LOW);
  digitalWrite(buzzer,LOW);

if(markx == 0){

  if (sms.SendSMS("085348017819", "KONDISI BAHAYA"));
  if (sms.SendSMS("082157306006", "KONDISI BAHAYA"));
  delay(3000);
 
  digitalWrite(mtr1,HIGH);
  digitalWrite(mtr2,LOW);
  analogWrite(kecepatan,250);

  delay(3000);

  digitalWrite(mtr1,LOW);
  digitalWrite(mtr2,LOW);
  analogWrite(kecepatan,0);
  markx =1;
}

}


if((distance > simpanlevel3)&&(distance <= simpanlevel2)&&(mark == 0)){
  digitalWrite(ledmerah,LOW); 
  digitalWrite(ledkuning,HIGH);
  digitalWrite(ledhijau,LOW);
  digitalWrite(buzzer,HIGH);
//  mark = 1; 
}



if((distance > simpanlevel2)&&(mark == 0)){
  digitalWrite(ledmerah,LOW); 
  digitalWrite(ledkuning,LOW);
  digitalWrite(ledhijau,HIGH);
  digitalWrite(buzzer,HIGH);

if(markx == 1){

  if (sms.SendSMS("085348017819", "KONDISI AMAN"));
  if (sms.SendSMS("082157306006", "KONDISI AMAN"));
  delay(3000);
  digitalWrite(mtr1,LOW);
  digitalWrite(mtr2,HIGH);
  analogWrite(kecepatan,250);

  delay(3000);

  digitalWrite(mtr1,LOW);
  digitalWrite(mtr2,LOW);
  analogWrite(kecepatan,0);
  markx = 0;
}


}


delay(1000);
lcd.clear(); 

 
}





void setting2(){
 
  lcd.setCursor(0, 0);
  lcd.print("batas level 2 ");
  lcd.setCursor(0, 1);
  lcd.print("nilai= "); 
  lcd.print(level2);

  btupx = digitalRead(btup);
  btdownx = digitalRead(btdown);
  btsimpanx = digitalRead(btsimpan);
 
  if(btupx == 0){
  delay(200);
  level2++;
  }
 
  if(btdownx == 0){
  delay(200);
  level2--;
  }

  if(btsimpanx == 0){
  delay(200);
  simpanlevel2 = level2;
  lcd.clear();
  return;
  }

setting2();
 
}




void setting3(){
 
  lcd.setCursor(0, 0);
  lcd.print("batas level 3 ");
  lcd.setCursor(0, 1);
  lcd.print("nilai= "); 
  lcd.print(level3);

  btupx = digitalRead(btup);
  btdownx = digitalRead(btdown);
  btsimpanx = digitalRead(btsimpan);
 
  if(btupx == 0){
  delay(200);
  level3++;
  }
 
  if(btdownx == 0){
  delay(200);
  level3--;
  }

  if(btsimpanx == 0){
  delay(200);
  simpanlevel3 = level3;
  lcd.clear();
  return;
  }

setting3();
 
}




void showlevel(){
  lcd.setCursor(0, 0);
  lcd.print("LV3=");
  lcd.print(simpanlevel3);
 
  lcd.setCursor(0, 1);
  lcd.print("LV2=");
  lcd.print(simpanlevel2);

btsetx = digitalRead(btset);

if(btsetx == 0){
  delay(200);
  lcd.clear();
  return;
  }


showlevel();
}






g. VIDEO HASILNYA












No comments:

Post a Comment