Arduino GSM Shield ve Android Uygulama ile Toprak Sulama

Arduino GSM Shield ve Android Uygulama ile Toprak Sulama

Merhaba arkadaşlar.

Arduino ile yapmış olduğum devreyi Arduino GSM Shield ve Android uygulama ile kontrol edebilmekteyiz.Ayrıca sistem kendisi otomatik olarak referans değerlerine göre topraklara 3 farklı motordan su basmaktadır. 3 farklı ürün olacağından toprakların nem ihtiyaçları farklılık göstere bilir.

Her toprağın nem isteğini devre bulunan potlar ile belirleyerek sistemin kontrol etmesi sağlanmaktadır. Toprakların nem değerleri referans değerinin altına düşerse sistem otomatik olarak ilgili toprağa su pompalamaya başlayacaktır.

Ayrıca android uygulama ve telefonumuzda sms atarakta sisteme müdahale edebilmekteyiz.

Sms olarak;

#RAPOR yazıp gönderdiğimizde sistem bize geri dönüş yaparak o anki referans ve nem değerlerini mesaj atacaktır.

#POMPAbir yazıp gönderdiğimizde 1.pompa 5 sn çalışacak ve duracaktır. sistem bize 1 pompa acildi diye cevap atacaktır.

#POMPiki yazıp gönderdiğimizde 2.pompa 5 sn çalışacak ve duracaktır. sistem bize 2 pompa acildi diye cevap atacaktır.

#POMPucr yazıp gönderdiğimizde 3.pompa 5 sn çalışacak ve duracaktır. sistem bize 3 pompa acildi diye cevap atacaktır.

Android uygulamamız da ise toprak nem değerleri anlık olarak ekranımızda yazacaktır. Ayrıca 3 adet  buton sayesinde 3 adet pompayı 5 sn çalıştırma imkanı sunmaktadır.  Her butona basıldığında da sistem sms ile bize bilgilendirecektir.

 

  • Arduino uno
  • Arduino GSM Shield  (http://gsmkontrol.com/)
  • HC05 Bluetooth Modülü
  • Toprak nem sensörü
  • Su pompası
  • 10k pot
  • BC547
  • 7805

 

 

 

 

char dataIn = 'S'; // Durma fonksiyonu için karakter

#include <SoftwareSerial.h>
//                      TX, RX
SoftwareSerial mySerial(0, 1);

#include <LiquidCrystal.h>


//               (Rs, E, D4, D5, D6 ,D7)
LiquidCrystal lcd(13, 12, 11 , 10 , 9 , 8);

SoftwareSerial gsm(2, 3);
String smsMetni = "";
char gelen;
int veri = 21540;
String mesaj_bir = "";
String mesaj_iki = "";
String mesaj_uc = "";
String mesaj_bir_ref = "";
String mesaj_iki_ref = "";
String mesaj_uc_ref = "";
#define BEKLE 3

char determinant; //Program dongüsü için karakter
char det; //Program dongüsü için karakter
int sure = 0;
int bir_saksi = 0;
int iki_saksi = 0;
int uc_saksi = 0;

int bir_ref = 0;
int iki_ref = 0;
int uc_ref = 0;

int ref_bir = 0;
int ref_iki = 0;
int ref_uc = 0;

int GelenVeri = 0;

int alinan = 0;

#define bir_motor 4
#define iki_motor 5
#define uc_motor 6


void SMSgonder(String mesaj) {
  gsm.print("AT+CMGF=1\r");
  delay(100);
  gsm.println("AT+CMGS=\"+905531234567\"");// telefon numarasi degistir
  delay(100);
  gsm.println(mesaj);
  delay(100);
  gsm.println((char)26);
  delay(100);
  gsm.println();
  delay(100);
  gsm.println("AT+CMGD=1,4");
  delay(100);
  gsm.println("AT+CMGF=1");
  delay(100);
  gsm.println("AT+CNMI=1,2,0,0,0");
  delay(200);
  smsMetni = "";
}





void SMS() {
  lcd.setCursor (0, 0);
  lcd.print(" GSM. KOMUTUYLA ");

  lcd.setCursor (0, 1);
  lcd.print("RAPOR GONDERILDI");
  bir_saksi = analogRead(A0);
  int bir_top = map(bir_saksi , 0, 1023, 100, 0);


  iki_saksi = analogRead(A2);
  int iki_top = map(iki_saksi , 0, 1023, 100, 0);


  uc_saksi = analogRead(A4);
  int uc_top = map(uc_saksi , 0, 1023, 100, 0);

  bir_ref = analogRead(A1);
  int ref_bir = map(bir_ref , 0, 1023, 0, 100);


  iki_ref = analogRead(A3);
  int ref_iki = map(iki_ref , 0, 1023, 0, 100);


  uc_ref = analogRead(A5);
  int ref_uc = map(uc_ref , 0, 1023, 0, 100);



  mesaj_bir = bir_top;
  mesaj_iki = iki_top;
  mesaj_uc = uc_top;



  mesaj_bir_ref = ref_bir;
  mesaj_iki_ref = ref_iki;
  mesaj_uc_ref = ref_uc;


  delay(100);




  gsm.print("AT+CMGF=1\r");
  delay(100);
  gsm.println("AT+CMGS=\"+905531234567\"");// telefon numarasi degistir
  delay(100);
  gsm.print("1.BOLGE "); gsm.print(" NEM ="); gsm.print(mesaj_bir); gsm.print(" REF ="); gsm.println(mesaj_bir_ref);
  delay(100);
  gsm.print("2.BOLGE "); gsm.print(" NEM ="); gsm.print(mesaj_iki); gsm.print(" REF ="); gsm.println(mesaj_iki_ref);
  delay(100);
  gsm.print("3.BOLGE "); gsm.print(" NEM ="); gsm.print(mesaj_uc); gsm.print(" REF ="); gsm.println(mesaj_uc_ref);
  delay(100);
  gsm.println((char)26);
  delay(100);
  gsm.println();
  delay(100);
  gsm.println("AT+CMGD=1,4");
  delay(100);
  gsm.println("AT+CMGF=1");
  delay(100);
  gsm.println("AT+CNMI=1,2,0,0,0");
  delay(200);
  smsMetni = "";

  lcd.clear();
}

void smscoz() {
  while (gsm.available()) {
    delay(BEKLE);
    gelen = gsm.read();
    if (gelen == '#') {
      if (gsm.available()) {
        delay(BEKLE);

        gelen = gsm.read();
        if (gelen == 'R') {
          if (gsm.available()) {
            delay(BEKLE);

            gelen = gsm.read();
            if (gelen == 'A') {
              if (gsm.available()) {
                delay(BEKLE);

                gelen = gsm.read();
                if (gelen == 'P') {
                  if (gsm.available()) {
                    delay(BEKLE);

                    gelen = gsm.read();
                    if (gelen == 'O') {
                      if (gsm.available()) {
                        delay(BEKLE);
                        gelen = gsm.read();
                        if (gelen == 'R') {
                          if (gsm.available()) {
                            delay(BEKLE);
                            SMS();



                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
















        if (gelen == 'P') {
          if (gsm.available()) {
            delay(BEKLE);
            gelen = gsm.read();
            if (gelen == 'O') {
              if (gsm.available()) {
                delay(BEKLE);
                gelen = gsm.read();
                if (gelen == 'M') {
                  if (gsm.available()) {
                    delay(BEKLE);
                    gelen = gsm.read();
                    if (gelen == 'P') {
                      if (gsm.available()) {
                        delay(BEKLE);
                        gelen = gsm.read();
                        if (gelen == 'A') {
                          if (gsm.available()) {
                            delay(BEKLE);
                            gelen = gsm.read();
                            if (gelen == 'b') {
                              SMSgonder("Pompa Bir Acildi");





                              sure = 50;
                              for (int a = 0 ; a < 50 ; a++)
                              {
                                sure = sure - 1;
                                bir_saksi = analogRead(A0);
                                int bir_top = map(bir_saksi , 0, 1023, 100, 0);


                                iki_saksi = analogRead(A2);
                                int iki_top = map(iki_saksi , 0, 1023, 100, 0);


                                uc_saksi = analogRead(A4);
                                int uc_top = map(uc_saksi , 0, 1023, 100, 0);

                                Serial.print(bir_top);
                                Serial.print(",");
                                Serial.print(iki_top);
                                Serial.print(",");
                                Serial.println(uc_top);

                                digitalWrite(bir_motor, HIGH);

                                lcd.setCursor (0, 0);
                                lcd.print(" GSM. KOMUTUYLA ");

                                lcd.setCursor (0, 1);
                                lcd.print("1.POMPA AKTIF ");
                                if (sure > 9)
                                {
                                  lcd.setCursor (14, 1);
                                  lcd.print(sure);
                                }
                                if (sure < 10)
                                {
                                  lcd.setCursor (14, 1);
                                  lcd.print("0"); lcd.print(sure);
                                }
                                delay (100);
                              }
                              digitalWrite(bir_motor, LOW);
                              lcd.setCursor (7, 0);
                              lcd.print("|");
                              lcd.setCursor (7, 1);
                              lcd.print("|");

                              sure = sure - 1;
                              alinan = 0;
                            }



                            if (gelen == 'i') {
                              SMSgonder("Pompa Iki Acildi");


                              sure = 50;
                              for (int a = 0 ; a < 50 ; a++)
                              {

                                bir_saksi = analogRead(A0);
                                int bir_top = map(bir_saksi , 0, 1023, 100, 0);


                                iki_saksi = analogRead(A2);
                                int iki_top = map(iki_saksi , 0, 1023, 100, 0);


                                uc_saksi = analogRead(A4);
                                int uc_top = map(uc_saksi , 0, 1023, 100, 0);

                                Serial.print(bir_top);
                                Serial.print(",");
                                Serial.print(iki_top);
                                Serial.print(",");
                                Serial.println(uc_top);
                                digitalWrite(iki_motor, HIGH);

                                lcd.setCursor (0, 0);
                                lcd.print(" GSM. KOMUTUYLA ");

                                lcd.setCursor (0, 1);
                                lcd.print("2.POMPA AKTIF ");
                                if (sure > 9)
                                {
                                  lcd.setCursor (14, 1);
                                  lcd.print(sure);
                                }
                                if (sure < 10)
                                {
                                  lcd.setCursor (14, 1);
                                  lcd.print("0"); lcd.print(sure);
                                }
                                delay (100);
                                sure = sure - 1;


                              }
                              digitalWrite(iki_motor, LOW);

                              lcd.setCursor (11, 0);
                              lcd.print("|");

                              lcd.setCursor (11, 1);
                              lcd.print("|");
                              alinan = 0;



                            }
                            if (gelen == 'u') {
                              SMSgonder("Pompa UC Acildi");


                              sure = 50;
                              for (int a = 0 ; a < 50 ; a++)
                              {
                                bir_saksi = analogRead(A0);
                                int bir_top = map(bir_saksi , 0, 1023, 100, 0);


                                iki_saksi = analogRead(A2);
                                int iki_top = map(iki_saksi , 0, 1023, 100, 0);


                                uc_saksi = analogRead(A4);
                                int uc_top = map(uc_saksi , 0, 1023, 100, 0);

                                Serial.print(bir_top);
                                Serial.print(",");
                                Serial.print(iki_top);
                                Serial.print(",");
                                Serial.println(uc_top);

                                digitalWrite(uc_motor, HIGH);

                                lcd.setCursor (0, 0);
                                lcd.print(" GSM. KOMUTUYLA ");

                                lcd.setCursor (0, 1);
                                lcd.print("3.POMPA AKTIF ");
                                if (sure > 9)
                                {
                                  lcd.setCursor (14, 1);
                                  lcd.print(sure);
                                }
                                if (sure < 10)
                                {
                                  lcd.setCursor (14, 1);
                                  lcd.print("0"); lcd.print(sure);
                                }
                                delay (100);
                                sure = sure - 1;
                              }
                              digitalWrite(uc_motor, LOW);
                              lcd.setCursor (15, 0);
                              lcd.print("|");
                              lcd.setCursor (15, 1);
                              lcd.print("|");
                              alinan = 0;


                            }


                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}






void setup()
{
  lcd.begin(16, 2);
  Serial.begin(9600); //HC-07 bluetooth modülü için btu 9600
  //mySerial.begin(38400);


  pinMode(bir_motor, OUTPUT);
  pinMode(iki_motor, OUTPUT);
  pinMode(uc_motor, OUTPUT);
  lcd.setCursor (0, 0);
  lcd.println("GSM+ANDROID+OTO.");
  lcd.setCursor (0, 1);
  lcd.println(" TOPRAK SULAMA  ");
  delay(2000);

  lcd.setCursor (0, 0);
  lcd.println("SMS ATILACAK KOM");
  lcd.setCursor (0, 1);
  lcd.println("#RAPOR          ");
  delay(2000);
  lcd.setCursor (0, 1);
  lcd.println("#POMPAbir       ");
  delay(2000);
  lcd.setCursor (0, 1);
  lcd.println("#POMPAiki       ");
  delay(2000);


  lcd.setCursor (0, 1);
  lcd.println("#POMPAuc        ");
  delay(2000);

  lcd.setCursor (0, 1);
  lcd.println("POMPALAR 5sn ON  ");
  delay(2000);
  lcd.setCursor (0, 0);
  lcd.println("SEBEKEYE BAGLAN-");
  lcd.setCursor (0, 1);
  lcd.println("TI KURULUYOR    ");

  pinMode(7, OUTPUT);
  digitalWrite(7, HIGH);
  delay(3000);
  digitalWrite(7, LOW);
  gsm.begin(9600);
  delay(2000);
  gsm.println("AT+CMGF=1");
  delay(100);
  gsm.println("AT+CNMI=1,2,0,0,0");
  delay(100);
  gsm.println("AT+CMGD=1,4");
  delay(1000);
  SMSgonder("Cihaz ile baglanti kuruldu");
 delay(100);
 

  gsm.flush();


  delay(2000);
  lcd.clear();
}

void loop()
{



  if (Serial.available() > 0) {
    int GelenVeri = Serial.read();
    alinan = GelenVeri;

  }

  if (alinan ==  50)
  { SMSgonder("Pompa 1 Telefondan Acildi");
    sure = 50;
    for (int a = 0 ; a < 50 ; a++)
    {
      sure = sure - 1;
      bir_saksi = analogRead(A0);
      int bir_top = map(bir_saksi , 0, 1023, 100, 0);


      iki_saksi = analogRead(A2);
      int iki_top = map(iki_saksi , 0, 1023, 100, 0);


      uc_saksi = analogRead(A4);
      int uc_top = map(uc_saksi , 0, 1023, 100, 0);

      Serial.print(bir_top);
      Serial.print(",");
      Serial.print(iki_top);
      Serial.print(",");
      Serial.println(uc_top);

      digitalWrite(bir_motor, HIGH);

      lcd.setCursor (0, 0);
      lcd.print(" TEL. KOMUTUYLA ");

      lcd.setCursor (0, 1);
      lcd.print("1.POMPA AKTIF ");
      if (sure > 9)
      {
        lcd.setCursor (14, 1);
        lcd.print(sure);
      }
      if (sure < 10)
      {
        lcd.setCursor (14, 1);
        lcd.print("0"); lcd.print(sure);
      }
      delay (100);
    }
    digitalWrite(bir_motor, LOW);
    lcd.setCursor (7, 0);
    lcd.print("|");
    lcd.setCursor (7, 1);
    lcd.print("|");

    sure = sure - 1;
    alinan = 0;
  }

  if (alinan ==  51)
  { SMSgonder("Pompa 2 Telefondan Acildi");
    sure = 50;
    for (int a = 0 ; a < 50 ; a++)
    {

      bir_saksi = analogRead(A0);
      int bir_top = map(bir_saksi , 0, 1023, 100, 0);


      iki_saksi = analogRead(A2);
      int iki_top = map(iki_saksi , 0, 1023, 100, 0);


      uc_saksi = analogRead(A4);
      int uc_top = map(uc_saksi , 0, 1023, 100, 0);

      Serial.print(bir_top);
      Serial.print(",");
      Serial.print(iki_top);
      Serial.print(",");
      Serial.println(uc_top);
      digitalWrite(iki_motor, HIGH);

      lcd.setCursor (0, 0);
      lcd.print(" TEL. KOMUTUYLA ");

      lcd.setCursor (0, 1);
      lcd.print("2.POMPA AKTIF ");
      if (sure > 9)
      {
        lcd.setCursor (14, 1);
        lcd.print(sure);
      }
      if (sure < 10)
      {
        lcd.setCursor (14, 1);
        lcd.print("0"); lcd.print(sure);
      }
      delay (100);
      sure = sure - 1;


    }
    digitalWrite(iki_motor, LOW);

    lcd.setCursor (11, 0);
    lcd.print("|");

    lcd.setCursor (11, 1);
    lcd.print("|");
    alinan = 0;
  }


  if (alinan ==  52)
  { SMSgonder("Pompa 3 Telefondan Acildi");
    sure = 50;
    for (int a = 0 ; a < 50 ; a++)
    {
      bir_saksi = analogRead(A0);
      int bir_top = map(bir_saksi , 0, 1023, 100, 0);


      iki_saksi = analogRead(A2);
      int iki_top = map(iki_saksi , 0, 1023, 100, 0);


      uc_saksi = analogRead(A4);
      int uc_top = map(uc_saksi , 0, 1023, 100, 0);

      Serial.print(bir_top);
      Serial.print(",");
      Serial.print(iki_top);
      Serial.print(",");
      Serial.println(uc_top);

      digitalWrite(uc_motor, HIGH);

      lcd.setCursor (0, 0);
      lcd.print(" TEL. KOMUTUYLA ");

      lcd.setCursor (0, 1);
      lcd.print("3.POMPA AKTIF ");
      if (sure > 9)
      {
        lcd.setCursor (14, 1);
        lcd.print(sure);
      }
      if (sure < 10)
      {
        lcd.setCursor (14, 1);
        lcd.print("0"); lcd.print(sure);
      }
      delay (100);
      sure = sure - 1;
    }
    digitalWrite(uc_motor, LOW);
    lcd.setCursor (15, 0);
    lcd.print("|");
    lcd.setCursor (15, 1);
    lcd.print("|");
    alinan = 0;
  }








  bir_saksi = analogRead(A0);
  int bir_top = map(bir_saksi , 0, 1023, 100, 0);


  iki_saksi = analogRead(A2);
  int iki_top = map(iki_saksi , 0, 1023, 100, 0);


  uc_saksi = analogRead(A4);
  int uc_top = map(uc_saksi , 0, 1023, 100, 0);


  bir_ref = analogRead(A1);
  int ref_bir = map(bir_ref , 0, 1023, 0, 100);


  iki_ref = analogRead(A3);
  int ref_iki = map(iki_ref , 0, 1023, 0, 100);


  uc_ref = analogRead(A5);
  int ref_uc = map(uc_ref , 0, 1023, 0, 100);



  if (ref_bir > bir_top)
  {
    digitalWrite(bir_motor, HIGH);
    lcd.setCursor (7, 0);
    lcd.print("^");
    lcd.setCursor (7, 1);
    lcd.print("^");
  }
  if (ref_bir <= bir_top)
  {
    digitalWrite(bir_motor, LOW);
    lcd.setCursor (7, 0);
    lcd.print("|");
    lcd.setCursor (7, 1);
    lcd.print("|");
  }
  if (ref_iki > iki_top)
  {
    digitalWrite(iki_motor, HIGH);

    lcd.setCursor (11, 0);
    lcd.print("^");

    lcd.setCursor (11, 1);
    lcd.print("^");
  }
  if (ref_iki <= iki_top)
  {
    digitalWrite(iki_motor, LOW);

    lcd.setCursor (11, 0);
    lcd.print("|");

    lcd.setCursor (11, 1);
    lcd.print("|");
  }
  if (ref_uc > uc_top)
  {
    digitalWrite(uc_motor, HIGH);
    lcd.setCursor (15, 0);
    lcd.print("^");
    lcd.setCursor (15, 1);
    lcd.print("^");
  }
  if (ref_uc <= uc_top)
  {
    digitalWrite(uc_motor, LOW);
    lcd.setCursor (15, 0);
    lcd.print("|");
    lcd.setCursor (15, 1);
    lcd.print("|");
  }




  lcd.setCursor (0, 0);
  lcd.print("NEM ");
  lcd.setCursor (4, 0);
  lcd.print(bir_top);
  lcd.setCursor (8, 0);
  lcd.print(iki_top);
  lcd.setCursor (12, 0);
  lcd.print(uc_top);

  lcd.setCursor (0, 1);
  lcd.print("REF ");
  lcd.setCursor (4, 1);
  lcd.print(ref_bir);
  lcd.setCursor (8, 1);
  lcd.print(ref_iki);
  lcd.setCursor (12, 1);
  lcd.print(ref_uc);



  Serial.print(bir_top);
  Serial.print(",");
  Serial.print(iki_top);
  Serial.print(",");
  Serial.println(uc_top);

  delay(300);
  smscoz();
  lcd.clear();

}





Sosyal Medyada Paylaş Facebook Twitter Google+

Etiketler: , , ,
Eklenme Tarihi: 2 Eylül 2018

Konu hakkında yorumunuzu yazın