July 6, 2018

List Program Kontrol Mesin Air otomatis Berbasis Arduino

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <GSM.h>

#define PINNUMBER ""
// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;

LiquidCrystal_I2C lcd(0x3F,16,2);  // set the LCD address to 0x27 for a 20 chars and 4 line display

#define level_1   A3
#define level_2   A2
#define level_3   A1
#define level_4   A0
#define buzzer    12
#define selenoid   6
#define pompa      7.

int i,j;
char isi_SMS[13],c;
char senderNumber[20];
char pompa_on[13]="#POMPA ON@";
int level1, level2, level3, level4;
boolean flag_sms,flag_level1,flag_level4,pump_on;


void setup() {
  lcd.backlight(); lcd.init();
  Serial.begin(9600);
  // put your setup code here, to run once:
  pinMode(level_1,INPUT); digitalWrite(level_1,HIGH);
  pinMode(level_2,INPUT); digitalWrite(level_2,HIGH);
  pinMode(level_3,INPUT); digitalWrite(level_3,HIGH);
  pinMode(level_4,INPUT); digitalWrite(level_4,HIGH);
  pinMode(buzzer,OUTPUT);
  pinMode(pompa,OUTPUT); digitalWrite(pompa,HIGH);
  pinMode(selenoid,OUTPUT); digitalWrite(selenoid,HIGH);

  lcd.setCursor(0,0); lcd.print("READING GSM  ");
  boolean notConnected = true;
  while (notConnected)
  { if (gsmAccess.begin(PINNUMBER) == GSM_READY)
    notConnected = false;
    else
    { lcd.setCursor(0,0); lcd.print("GSM Not READY  ");
      Serial.println("GSM Not connected");
      delay(1000);
    }
  }
  lcd.setCursor(0,0); lcd.print("GSM READY.....  ");
  Serial.println("GSM initialized");
  delay(2000);
  lcd.setCursor(0,0); lcd.print(" PRESENTED By : ");
  lcd.setCursor(0,1); lcd.print("--LUNGGUK A.S.--");
  delay(2000); lcd.clear();
}

void baca_sensor() {
  level1=analogRead(level_1);
  level2=analogRead(level_2);
  level3=analogRead(level_3);
  level4=analogRead(level_4);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(sms.available())
  { //Serial.println("Message received from:");
    sms.remoteNumber(senderNumber, 20);
    lcd.setCursor(0,0); lcd.print(senderNumber);  
    i=0;
    while (c = sms.read()) {
      isi_SMS[i]=c;
      if(isi_SMS[i]=='@') goto lompat;
      //Serial.print(c);
      i++;
      if(i>120) {sms.flush(); goto selesai;}
    }
    lompat:
    lcd.setCursor(0,1); lcd.print(isi_SMS);
    sms.flush();
    delay(100);
    pump_on=0;
    for(j=0;j<i;j++)
    {  if(pompa_on[j]!=isi_SMS[j])  pump_on=1;  } 
    i=0;  
    lcd.clear();
    lcd.setCursor(0,0); lcd.print("PERINTAH-->");       
    if(pump_on==0) {
      digitalWrite(selenoid,LOW);
      digitalWrite(pompa,LOW);
      lcd.setCursor(0,0); lcd.print("SMS DIVERIFIKASI");
      lcd.setCursor(0,1); lcd.print("-POMPA AIR AKTIF-");
      delay(3000);
    }  
    else{lcd.setCursor(0,1); lcd.print("Format SMS SALAH"); kirim_sms_salah(); delay(3000); }
    selesai:
    for(j=0;j<12;j++) { isi_SMS[j]=' '; }
    //'''''''''''''''''''''''''''''''''''''''''''''
    sms.flush();
    delay(100);
    //("\nEND OF MESSAGE");
    sms.flush(); // Delete message from modem memory 
  }
  baca_sensor();
  
  if(level1>700 && level2>700 && level3>700 && level4>700) {
    lcd.setCursor(0,0); lcd.print("--Level Air  0--");
    if(flag_level1==0) { flag_level1=1; kirim_SMS_Level_1(); }
  }
  else if(level1<700 && level2>700 && level3>700 && level4>700) { lcd.setCursor(0,0); lcd.print("--Level Air  1--"); flag_level4=0; }
  else if(level1<700 && level2<700 && level3>700 && level4>700) { lcd.setCursor(0,0); lcd.print("--Level Air  2--"); flag_level1=0; flag_level4=0; }
  else if(level1<700 && level2<700 && level3<700 && level4>700) { lcd.setCursor(0,0); lcd.print("--Level Air  3--"); flag_level1=0; }
  else if(level1<700 && level2<700 && level3<700 && level4<700) {
    lcd.setCursor(0,0); lcd.print("--Level Air  4--");
    flag_level1=0;
    digitalWrite(selenoid,HIGH);
    digitalWrite(pompa,HIGH);
    digitalWrite(buzzer,HIGH); delay(100);
    digitalWrite(buzzer,LOW); delay(100);
    if(flag_level4==0) { flag_level4=1; kirim_SMS_Level_4(); }
  } 
}

void kirim_SMS_Level_1() {
  // send the message
  sms.beginSMS("082304063142");
  sms.print("Bak Air Kosong. Balas \"#POMPA ON@\" Untuk Mengisi Bak Air...");
  sms.endSMS();
  lcd.setCursor(0,1); lcd.print("--MENGIRIM SMS--");
  delay(2000);
}
void kirim_SMS_Level_4() {
  // send the message
  sms.beginSMS("082304063142");
  sms.print("Bak Air Sudah Penuh. Proses Pengisian Air Selesai...");
  sms.endSMS();
}
void kirim_sms_salah() {
  // send the message
  sms.beginSMS("082304063142");
  sms.print("Format SMS Salah Booos");
  sms.endSMS();
}

0 komentar:

Post a Comment