Arduino & Android Toprak Sulama

Daha önce yapmış olduğum toprak sulama projeme android uygulama ile geliştirdim umarım beğenirsiniz.


#include <SoftwareSerial.h> 


int bluetoothTx = 0; 
int bluetoothRx = 1; 

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);


int dataIn ;
int nem;
int durum = 0;
#include <dht11.h>
#include <LiquidCrystal.h>


//               (Rs, E, D4, D5, D6 ,D7)
LiquidCrystal lcd(13 , 12, 11 , 10 , 9 , 8);
dht11 DHT11;
int buzzer = 4;
int yesil_led = 6;
int kirmizi_led = 5;
int su_led = 2;
int pompa = 3;
int toprak = 0;
int referans = 0;
int sicaklik;
    int toprak_pin=A0;
    int topraksensoru;
int uzaktan;
void setup()
{
  bluetooth.begin(9600);
  DHT11.attach(7);
  pinMode(buzzer, OUTPUT);
  pinMode(yesil_led, OUTPUT);
  pinMode(kirmizi_led, OUTPUT);
  pinMode(su_led, OUTPUT);
  pinMode(pompa, OUTPUT);
  Serial.begin(9600);
  Serial.println("DHT11 TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT11LIB_VERSION);
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor (0, 0);
  lcd.println("  AKILLI  SERA  ");
  lcd.setCursor (0, 1);
  lcd.println("    PROJESI     ");
  delay (2000);



  for (int a = 0; a < 10; a++)
  {
    digitalWrite(kirmizi_led, HIGH);
    digitalWrite(yesil_led, LOW);
    delay (200);
    digitalWrite(kirmizi_led, LOW);
    digitalWrite(yesil_led, HIGH);

    delay (200);
  }

  lcd.clear();
  digitalWrite(kirmizi_led, LOW);
  lcd.setCursor (0, 0);
  lcd.println("TELEFON ILE BAG-");
  lcd.setCursor (0, 1);
  lcd.println("LANTI BEKLENIYOR");
}

void loop()
{

  if (Serial.available() > 0) //Serial portun kontrollü
  {
    dataIn = Serial.read(); //Telefondan gelen verilerin kontrollü
  }
  if (dataIn == 105) // otonom moda geçiş
      {

        lcd.setCursor (0, 0);
        lcd.println("   OTONOM MODA  ");
        lcd.setCursor (0, 1);
        lcd.println("    GECILDI     ");
        uzaktan = 1;      delay(1000);
otonom();
        lcd.clear();
      }
 if (dataIn == 106) // otonom moda geçiş
      {

    lcd.setCursor (0, 0);
    lcd.println("    UZAKTAN     ");
    lcd.setCursor (0, 1);
    lcd.println("    KONTROL     ");
    delay(1000);  lcd.clear();
uzaktann();
        lcd.clear();
      }


  

  
}

void uzaktann()
{
 while (uzaktan == 0)
    {

      lcd.setCursor (0, 0);
      lcd.println("UZAKTAN  KONTROL");
      int chk = DHT11.read();
      sicaklik = (float)DHT11.temperature, DEC;
      nem = (int)DHT11.humidity, DEC;
    topraksensoru = analogRead(toprak_pin);
      toprak = map(abs(topraksensoru), 0, 1024, 99, 1);

      Serial.print(sicaklik);
      Serial.print(",");
      Serial.print(nem);
      Serial.print(",");
      Serial.println(toprak);


      lcd.setCursor (0, 1); lcd.print("S:"); lcd.print((int)DHT11.temperature, DEC); lcd.print("  ");
      lcd.setCursor (4, 1); lcd.print("N:"); lcd.print((int)DHT11.humidity, DEC); lcd.print("  ");
      lcd.setCursor (8, 1); lcd.print("%:"); lcd.print(toprak); lcd.print("  ");
      lcd.setCursor (12, 1); lcd.print("R:"); lcd.print(referans); lcd.print("  ");


      if (Serial.available() > 0) //Serial portun kontrollü
      {
        dataIn = Serial.read(); //Telefondan gelen verilerin kontrollü
      }
      if (dataIn == 105) // otonom moda geçiş
      {

        lcd.setCursor (0, 0);
        lcd.println("   OTONOM MODA  ");
        lcd.setCursor (0, 1);
        lcd.println("    GECILDI     ");
        uzaktan = 1;      delay(1000);
otonom();
        lcd.clear();
      }
      if (dataIn > 0 && dataIn < 101)
      {
        referans = dataIn;

        // referans = map(abs(dataIn), 10, 100, 0, 100);
      }
      while (toprak <= referans)
      {
        lcd.clear();
        lcd.setCursor (0, 0);
        lcd.print("TOPRAK  SULAMASI");
        lcd.setCursor (0, 1);
        lcd.print("   BASLAYACAK   ");
        delay(2000);



        digitalWrite(buzzer, HIGH);
        delay (500);
        digitalWrite(buzzer, LOW);
        delay (1000);

        while (toprak <= referans)
        {


          int chk = DHT11.read();
          sicaklik = (float)DHT11.temperature, DEC;
          nem = (int)DHT11.humidity, DEC;
    topraksensoru = analogRead(toprak_pin);
          toprak = map(abs(topraksensoru), 0, 1024, 99, 1);

          Serial.print(sicaklik);
          Serial.print(",");
          Serial.print(nem);
          Serial.print(",");
          Serial.println(toprak);
          lcd.clear();
          lcd.setCursor (0, 0);
          lcd.print("TOPRAK SULANIYOR");
          lcd.setCursor (0, 1);
          lcd.print("Top. %="); lcd.print(toprak);
          lcd.setCursor (9, 1);
          lcd.print(" Rf="); lcd.print(referans);
          lcd.setCursor (14, 1);

          digitalWrite(su_led, HIGH);
          digitalWrite(pompa, HIGH);

          if (Serial.available() > 0) //Serial portun kontrollü
          {
            dataIn = Serial.read(); //Telefondan gelen verilerin kontrollü
          }
          if (dataIn > 0 && dataIn < 101)
          {
            referans = dataIn;

            // referans = map(abs(dataIn), 10, 100, 0, 100);
          }
          delay(50);
        }

    topraksensoru = analogRead(toprak_pin);
        toprak = map(abs(topraksensoru), 0, 1024, 99, 1);
      }

      digitalWrite(su_led, LOW);
      digitalWrite(pompa, LOW);
      if (dataIn == 101)
      {
        while (1)
        {


    topraksensoru = analogRead(toprak_pin);
          toprak = map(abs(topraksensoru), 0, 1024, 99, 1);
          lcd.setCursor (0, 0);
          lcd.println("UZK. POMPA ACIK ");
          lcd.setCursor (0, 1); lcd.print("Top. %="); lcd.print(toprak); lcd.print("   ");
          lcd.setCursor (9, 1); lcd.print(" Rf= "); lcd.print("   ");
          lcd.setCursor (14, 1); lcd.print(referans); lcd.print("   ");
          digitalWrite(su_led, HIGH);
          digitalWrite(pompa, HIGH);
          if (Serial.available() > 0) //Serial portun kontrollü
          {
            dataIn = Serial.read(); //Telefondan gelen verilerin kontrollü
          }
          if (dataIn > 0 && dataIn < 101)
          {
            referans = dataIn;

            // referans = map(abs(dataIn), 10, 100, 0, 100);
          }


          int chk = DHT11.read();
          sicaklik = (float)DHT11.temperature, DEC;
          nem = (int)DHT11.humidity, DEC;

          Serial.print(sicaklik);
          Serial.print(",");
          Serial.print(nem);
          Serial.print(",");
          Serial.println(toprak);

          if (dataIn == 102 )
          {
            lcd.setCursor (0, 0);
            lcd.println("UZK. POMPA KAP. ");
            lcd.setCursor (0, 1); lcd.print("Top. %="); lcd.print(toprak); lcd.print("   ");
            lcd.setCursor (9, 1); lcd.print(" Rf= "); lcd.print("   ");
            lcd.setCursor (14, 1); lcd.print(referans); lcd.print("   ");
            digitalWrite(su_led, LOW);
            digitalWrite(pompa, LOW);
            delay(1000);

            lcd.clear();
            break;
          }
        }
      }






      if (dataIn == 102 )
      {

        digitalWrite(pompa, LOW);
        lcd.setCursor (0, 0);
        lcd.println("UZK. POMPA KAP.");
        lcd.setCursor (0, 1); lcd.print("Top. %="); lcd.print(toprak); lcd.print("   ");
        lcd.setCursor (9, 1); lcd.print(" Rf= "); lcd.print("   ");
        lcd.setCursor (14, 1); lcd.print(referans); lcd.print("   ");
        delay(1000);

        lcd.clear();
      }
    }

  
}


void otonom()
{
  while (uzaktan == 1)
  {

    int chk = DHT11.read();
    sicaklik = (float)DHT11.temperature, DEC;
    nem = (int)DHT11.humidity, DEC;
    topraksensoru = analogRead(toprak_pin);
    toprak = map(abs(topraksensoru), 0, 1024, 99, 1);

    Serial.print(sicaklik);
    Serial.print(",");
    Serial.print(nem);
    Serial.print(",");
    Serial.println(toprak);
    lcd.setCursor (0, 0);
    lcd.println("OTONOM  CALISMA ");

    lcd.setCursor (0, 1); lcd.print("S:"); lcd.print((int)DHT11.temperature, DEC); lcd.print("  ");
    lcd.setCursor (4, 1); lcd.print("N:"); lcd.print((int)DHT11.humidity, DEC); lcd.print("  ");
    lcd.setCursor (8, 1); lcd.print("%:"); lcd.print(toprak); lcd.print("  ");
    lcd.setCursor (12, 1); lcd.print("R:"); lcd.print(referans); lcd.print("  ");
    if (Serial.available() > 0) //Serial portun kontrollü
    {
      dataIn = Serial.read(); //Telefondan gelen verilerin kontrollü
    }
    if (dataIn == 106)
    {

      lcd.setCursor (0, 0);
      lcd.println("    UZAKTAN     ");
      lcd.setCursor (0, 1);
      lcd.println("    KONTROL     ");
      delay(1000);  lcd.clear();
      uzaktan = 0;
    }
    //  int isireferans = analogRead(A5);
    //  isi = map(abs(isireferans), 0, 1024, 0, 50);
    int toprakreferans = analogRead(A5);
    referans = map(abs(toprakreferans), 0, 1024, 0, 99);

    //          int chk = DHT11.read();
    //          sicaklik = (float)DHT11.temperature, DEC;


    lcd.setCursor (0, 1); lcd.print("S:"); lcd.print((int)DHT11.temperature, DEC); lcd.print("  ");
    lcd.setCursor (4, 1); lcd.print("N:"); lcd.print((int)DHT11.humidity, DEC); lcd.print("  ");
    lcd.setCursor (8, 1); lcd.print("%:"); lcd.print(toprak); lcd.print("  ");
    lcd.setCursor (12, 1); lcd.print("R:"); lcd.print(referans); lcd.print("  ");

    delay(200);

    digitalWrite(su_led, LOW);
    digitalWrite(buzzer, LOW);
    digitalWrite(kirmizi_led, LOW);

    digitalWrite(yesil_led, LOW);
    digitalWrite(pompa, LOW);




    while (toprak <= referans)
    {

      lcd.clear();
      lcd.setCursor (0, 0);
      lcd.print("TOPRAK  SULAMASI");
      lcd.setCursor (0, 1);
      lcd.print("   BASLAYACAK   ");
      delay(2000);



      digitalWrite(buzzer, HIGH);
      delay (500);
      digitalWrite(buzzer, LOW);
      delay (1000);


      while (toprak <= referans)
      {
        lcd.clear();
        lcd.setCursor (0, 0);
        lcd.print("TOPRAK SULANIYOR");
        lcd.setCursor (0, 1); lcd.print("Top. %="); lcd.print(toprak); lcd.print("   ");
        lcd.setCursor (9, 1); lcd.print(" Rf= "); lcd.print("   ");
        lcd.setCursor (14, 1); lcd.print(referans); lcd.print("   ");
        digitalWrite(su_led, HIGH);
        digitalWrite(pompa, HIGH);


        int toprakreferans = analogRead(A5);
        referans = map(abs(toprakreferans), 0, 1024, 0, 99);




        int chk = DHT11.read();
        sicaklik = (float)DHT11.temperature, DEC;
        nem = (int)DHT11.humidity, DEC;
    topraksensoru = analogRead(toprak_pin);
        toprak = map(abs(topraksensoru), 0, 1024, 99, 1);

        Serial.print(sicaklik);
        Serial.print(",");
        Serial.print(nem);
        Serial.print(",");
        Serial.println(toprak);



        delay (300);
      }
      digitalWrite(su_led, LOW);
      digitalWrite(buzzer, LOW);
      digitalWrite(pompa, LOW);
      delay (1000);

      lcd.clear();
    topraksensoru = analogRead(toprak_pin);
      toprak = map(abs(topraksensoru), 0, 1024, 99, 1);

      int toprakreferans = analogRead(A5);
      referans = map(abs(toprakreferans), 0, 1024, 0, 99);
    }

  }

}

Sosyal Medyada Paylaş Facebook Twitter Google+

Etiketler: , , , ,
Eklenme Tarihi: 4 Aralık 2019

Konu hakkında yorumunuzu yazın

HOŞ GELDİNİZ

Youtube kanalıma Abone Olabilirsiniz.