Washing Maching code doesn' wait for fill water tank after 1st. washing is complete

#include <LiquidCrystal_I2C.h>

#define SU_ALMA_RELESI_PIN 9
#define SOL_DONDURME_RELESI_PIN 12
#define SAG_DONDURME_RELESI_PIN 10
#define SU_BOSALTMA_RELESI_PIN 8
#define SIKMA_RELESI_PIN 7
#define DOLU_SENSORU_PIN 2

#define YIKAMA_SURESI_MIN 1
#define YIKAMA_SURESI_MAX 60
#define DURULAMA_SURESI_MIN 1
#define DURULAMA_SURESI_MAX 60
#define SIYIRMA_SURESI_MIN 1
#define SIYIRMA_SURESI_MAX 60

#define ARTIRMA_DUGME_PIN A0
#define AZALTMA_DUGME_PIN A1
#define SECIM_DUGME_PIN A2

LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C adresi ve ekran boyutu

int yikamaSuresi = 5; // Varsayılan yıkama süresi 5 dakika
int durulamaSuresi = 5; // Varsayılan durulama süresi 5 dakika
int siyrmaSuresi = 2; // Varsayılan sıkma süresi 2 dakika

bool suDolu = false;

void setup() {
  pinMode(SU_ALMA_RELESI_PIN, OUTPUT);
  pinMode(SOL_DONDURME_RELESI_PIN, OUTPUT);
  pinMode(SAG_DONDURME_RELESI_PIN, OUTPUT);
  pinMode(SU_BOSALTMA_RELESI_PIN, OUTPUT);
  pinMode(SIKMA_RELESI_PIN, OUTPUT);
  pinMode(DOLU_SENSORU_PIN, INPUT);
  
  pinMode(ARTIRMA_DUGME_PIN, INPUT_PULLUP);
  pinMode(AZALTMA_DUGME_PIN, INPUT_PULLUP);
  pinMode(SECIM_DUGME_PIN, INPUT_PULLUP);

  lcd.init();                      // LCD ekranını başlat
  lcd.backlight();                 // Arka ışığı aç
}

void loop() {
  lcd.setCursor(0, 0);
  lcd.print("Yikama: ");
  lcd.print(yikamaSuresi);
  lcd.print(" dk");
  
  lcd.setCursor(0, 1);
  lcd.print("Durulama: ");
  lcd.print(durulamaSuresi);
  lcd.print(" dk");

  if (digitalRead(SECIM_DUGME_PIN) == LOW) {
    // Seçim düğmesi basıldığında yıkama programını başlat
    yikamaProgrami();
  }

  yikamaSuresi = ayarDugmeleriyleSuresiAyarla(yikamaSuresi, YIKAMA_SURESI_MIN, YIKAMA_SURESI_MAX);
  durulamaSuresi = ayarDugmeleriyleSuresiAyarla(durulamaSuresi, DURULAMA_SURESI_MIN, DURULAMA_SURESI_MAX);
}

void yikamaProgrami() {
  // Yıkama
  lcd.clear();
  lcd.print("Yikama basladi");
  
  digitalWrite(SU_ALMA_RELESI_PIN, HIGH); // Su al
  while (!suDolu) {
    suDolu = digitalRead(DOLU_SENSORU_PIN); // Dolu sensörünü kontrol et
  }
  digitalWrite(SU_ALMA_RELESI_PIN, LOW); // Su alma rölesi kapat

  for (int i = 0; i < 3; i++) { // 3 kez tekrarla (yıkama, 2 durulama)
    for (int j = 0; j < yikamaSuresi; j++) { // Yıkama süresi boyunca yıkama
      lcd.setCursor(0, 1);
      lcd.print("Kalan sure: ");
      lcd.print(yikamaSuresi - j);
      lcd.print("dk.");
      
      digitalWrite(SAG_DONDURME_RELESI_PIN, HIGH); // Sağa dön
      delay(5000);
      digitalWrite(SAG_DONDURME_RELESI_PIN, LOW);

      delay(5000);

      digitalWrite(SOL_DONDURME_RELESI_PIN, HIGH); // Sola dön
      delay(5000);
      digitalWrite(SOL_DONDURME_RELESI_PIN, LOW);

      delay(5000);
    }

    digitalWrite(SU_BOSALTMA_RELESI_PIN, HIGH); // Su boşalt
    lcd.setCursor(0, 0);
    lcd.print("Su Bosaltma");
    delay(10000);
    digitalWrite(SU_BOSALTMA_RELESI_PIN, LOW);

    if (i < 2){ // Son durulamadan sonra sıkma yapma
      // Durulama

      
      digitalWrite(SU_ALMA_RELESI_PIN, HIGH); // Su al
     delay; while (!suDolu) {
        suDolu = digitalRead(DOLU_SENSORU_PIN); // Dolu sensörünü kontrol et
          if (!suDolu) { // Eğer su dolu değilse
      lcd.clear();
      lcd.setCursor(0, 1);
      lcd.print("Tank bos. Bekleniyor...");
    }
    delay(1000); // 1 saniye bekleme
    }
          lcd.clear();
      lcd.print("Durulama basladi");
      lcd.setCursor(0, 1);
      lcd.print("Kalan sure: ");
      lcd.print(durulamaSuresi);
      lcd.print("dk.");
      
      digitalWrite(SU_ALMA_RELESI_PIN, LOW); // Su alma rölesi kapat
       lcd.setCursor(0, 1);
      lcd.print("Kalan sure: ");
      lcd.print(durulamaSuresi - i);
      
      digitalWrite(SAG_DONDURME_RELESI_PIN, HIGH); // Sağa dön
      delay(5000);
      digitalWrite(SAG_DONDURME_RELESI_PIN, LOW);

      delay(5000);

      digitalWrite(SOL_DONDURME_RELESI_PIN, HIGH); // Sola dön
      delay(5000);
      digitalWrite(SOL_DONDURME_RELESI_PIN, LOW);

      delay(5000);
    }
  }

  // Sıkma
  lcd.clear();
  lcd.print("Sikma basladi");
  lcd.setCursor(0, 1);
  lcd.print("Kalan sure: ");
  lcd.print(siyrmaSuresi);
  
  digitalWrite(SIKMA_RELESI_PIN, HIGH); // Sıkma rölesi açık
  digitalWrite(SU_BOSALTMA_RELESI_PIN, HIGH); // Su boşalt
  // Yıkama programı sonlandırılır
}

int ayarDugmeleriyleSuresiAyarla(int suresi, int minDeger, int maxDeger) {
  int artirmaButonDurumu = digitalRead(ARTIRMA_DUGME_PIN);
  int azaltmaButonDurumu = digitalRead(AZALTMA_DUGME_PIN);

  if (artirmaButonDurumu == LOW) {
    suresi++;
    if (suresi > maxDeger) {
      suresi = minDeger;
    }
    delay(200); // Debouncing
  }

  if (azaltmaButonDurumu == LOW) {
    suresi--;
    if (suresi < minDeger) {
      suresi = maxDeger;
    }
    delay(200); // Debouncing
  }

  return suresi;
}

I moved your topic to an appropriate forum category @ouzcoskun.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

As all line comments and messages on the display are in Turkish, we are unable to know what happens at each stage and therefore it is very difficult to help.

If I understand correctly, you verify the water level once here

  while (!suDolu) {
    suDolu = digitalRead(DOLU_SENSORU_PIN); // Dolu sensörünü kontrol et
  }

and then go on with the 3 washing cycles without refilling.

delay without a parameter is at minimum a bug.

Here is your code with some English comments (basically google translate). There is ice cream :rofl: Maybe you can expand and explain some of the odd things.

#include <LiquidCrystal_I2C.h>

#define SU_ALMA_RELESI_PIN 9        // WATER INTAKE RELAY PIN
#define SOL_DONDURME_RELESI_PIN 12  // SOL DONDURME RELESI PIN
#define SAG_DONDURME_RELESI_PIN 10  // RIGHT ICE CREAM RELEASE PIN
#define SU_BOSALTMA_RELESI_PIN 8    // WATER DRAIN PIN
#define SIKMA_RELESI_PIN 7          // TIGHTENING RELEASE PIN
#define DOLU_SENSORU_PIN 2          // Do line sol product  // should be something for water level

#define YIKAMA_SURESI_MIN 1         // WASHING TIME
#define YIKAMA_SURESI_MAX 60        // WASHING TIME
#define DURULAMA_SURESI_MIN 1       // RINSE TIME
#define DURULAMA_SURESI_MAX 60      // RINSE TIME
#define SIYIRMA_SURESI_MIN 1        // STRIPPING TIME
#define SIYIRMA_SURESI_MAX 60       // STRIPPING TIME

#define ARTIRMA_DUGME_PIN A0        // increase button
#define AZALTMA_DUGME_PIN A1        // decreaase button
#define SECIM_DUGME_PIN A2          // vote (accept ??)

LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C adresi ve ekran boyutu

int yikamaSuresi = 5; // Varsayılan yıkama süresi 5 dakika
int durulamaSuresi = 5; // Varsayılan durulama süresi 5 dakika
int siyrmaSuresi = 2; // Varsayılan sıkma süresi 2 dakika

bool suDolu = false;

void setup() {
  pinMode(SU_ALMA_RELESI_PIN, OUTPUT);
  pinMode(SOL_DONDURME_RELESI_PIN, OUTPUT);
  pinMode(SAG_DONDURME_RELESI_PIN, OUTPUT);
  pinMode(SU_BOSALTMA_RELESI_PIN, OUTPUT);
  pinMode(SIKMA_RELESI_PIN, OUTPUT);
  pinMode(DOLU_SENSORU_PIN, INPUT);

  pinMode(ARTIRMA_DUGME_PIN, INPUT_PULLUP);
  pinMode(AZALTMA_DUGME_PIN, INPUT_PULLUP);
  pinMode(SECIM_DUGME_PIN, INPUT_PULLUP);

  lcd.init();                      // LCD ekranını başlat
  lcd.backlight();                 // Arka ışığı aç
}

void loop() {
  lcd.setCursor(0, 0);
  lcd.print("Yikama: ");
  lcd.print(yikamaSuresi);
  lcd.print(" dk");

  lcd.setCursor(0, 1);
  lcd.print("Durulama: ");
  lcd.print(durulamaSuresi);
  lcd.print(" dk");

  if (digitalRead(SECIM_DUGME_PIN) == LOW) {
    // Seçim düğmesi basıldığında yıkama programını başlat
    yikamaProgrami();
  }

  yikamaSuresi = ayarDugmeleriyleSuresiAyarla(yikamaSuresi, YIKAMA_SURESI_MIN, YIKAMA_SURESI_MAX);
  durulamaSuresi = ayarDugmeleriyleSuresiAyarla(durulamaSuresi, DURULAMA_SURESI_MIN, DURULAMA_SURESI_MAX);
}

//////////////////////
// washing program
//////////////////////
void yikamaProgrami() {
  // Yıkama
  lcd.clear();
  lcd.print("Yikama basladi");

  // water intake
  digitalWrite(SU_ALMA_RELESI_PIN, HIGH); // Su al
  // while level low
  while (!suDolu) {
    suDolu = digitalRead(DOLU_SENSORU_PIN); // Dolu sensörünü kontrol et
  }
  // close water intake
  digitalWrite(SU_ALMA_RELESI_PIN, LOW); // Su alma rölesi kapat

  // repeat three times; wash plus two rinse
  for (int i = 0; i < 3; i++) { // 3 kez tekrarla (yıkama, 2 durulama)
    // washing during washing time
    for (int j = 0; j < yikamaSuresi; j++) { // Yıkama süresi boyunca yıkama
      lcd.setCursor(0, 1);
      lcd.print("Kalan sure: ");
      lcd.print(yikamaSuresi - j);
      lcd.print("dk.");

      digitalWrite(SAG_DONDURME_RELESI_PIN, HIGH); // Sağa dön
      delay(5000);
      digitalWrite(SAG_DONDURME_RELESI_PIN, LOW);

      delay(5000);

      digitalWrite(SOL_DONDURME_RELESI_PIN, HIGH); // Sola dön
      delay(5000);
      digitalWrite(SOL_DONDURME_RELESI_PIN, LOW);

      delay(5000);
    }

    // water drain
    digitalWrite(SU_BOSALTMA_RELESI_PIN, HIGH); // Su boşalt
    lcd.setCursor(0, 0);
    lcd.print("Su Bosaltma");
    delay(10000);
    digitalWrite(SU_BOSALTMA_RELESI_PIN, LOW);

    // no spin after last rinse
    if (i < 2) { // Son durulamadan sonra sıkma yapma
      // Durulama
      digitalWrite(SU_ALMA_RELESI_PIN, HIGH); // Su al
      // check full sensor
      delay; while (!suDolu) {
        suDolu = digitalRead(DOLU_SENSORU_PIN); // Dolu sensörünü kontrol et
        if (!suDolu) { // Eğer su dolu değilse
          lcd.clear();
          lcd.setCursor(0, 1);
          lcd.print("Tank bos. Bekleniyor...");
        }
        // wait one second
        delay(1000); // 1 saniye bekleme
      }
      lcd.clear();
      lcd.print("Durulama basladi");
      lcd.setCursor(0, 1);
      lcd.print("Kalan sure: ");
      lcd.print(durulamaSuresi);
      lcd.print("dk.");

      // close water intake relay
      digitalWrite(SU_ALMA_RELESI_PIN, LOW); // Su alma rölesi kapat
      lcd.setCursor(0, 1);
      lcd.print("Kalan sure: ");
      lcd.print(durulamaSuresi - i);

      // turn right
      digitalWrite(SAG_DONDURME_RELESI_PIN, HIGH); // Sağa dön
      delay(5000);
      digitalWrite(SAG_DONDURME_RELESI_PIN, LOW);

      delay(5000);

      // sun down ???
      digitalWrite(SOL_DONDURME_RELESI_PIN, HIGH); // Sola dön
      delay(5000);
      digitalWrite(SOL_DONDURME_RELESI_PIN, LOW);

      delay(5000);
    }
  }

  // squeezing
  // Sıkma
  lcd.clear();
  lcd.print("Sikma basladi");
  lcd.setCursor(0, 1);
  lcd.print("Kalan sure: ");
  lcd.print(siyrmaSuresi);

  // clamping relay open
  digitalWrite(SIKMA_RELESI_PIN, HIGH); // Sıkma rölesi açık
  digitalWrite(SU_BOSALTMA_RELESI_PIN, HIGH); // Su boşalt
  // Yıkama programı sonlandırılır
}


//////////////////////
// set duration
//////////////////////
int ayarDugmeleriyleSuresiAyarla(int suresi, int minDeger, int maxDeger) {
  int artirmaButonDurumu = digitalRead(ARTIRMA_DUGME_PIN);
  int azaltmaButonDurumu = digitalRead(AZALTMA_DUGME_PIN);

  if (artirmaButonDurumu == LOW) {
    suresi++;
    if (suresi > maxDeger) {
      suresi = minDeger;
    }
    delay(200); // Debouncing
  }

  if (azaltmaButonDurumu == LOW) {
    suresi--;
    if (suresi < minDeger) {
      suresi = maxDeger;
    }
    delay(200); // Debouncing
  }

  return suresi;
}

@ouzcoskun
The translation is correct?

#include <LiquidCrystal_I2C.h>

#define WATER_INTAKE_RELAY_PIN 9
#define LEFT_ICE_CREAM_RELAY_PIN 12
#define RIGHT_ICE_CREAM_RELAY_PIN 10
#define WATER_DRAIN_RELAY_PIN 8
#define TIGHTENING_RELEASE_PIN 7
#define FULL_SENSOR_PIN 2

#define WASHING_TIME_MIN 1
#define WASHING_TIME_MAX 60
#define RINSE_TIME_MIN 1
#define RINSE_TIME_MAX 60
#define STRIPPING_TIME_MIN 1
#define STRIPPING_TIME_MAX 60

#define INCREASE_BUTTON_PIN A0
#define REDUCTION_BUTTON_PIN A1
#define SELECTION_BUTTON_PIN A2

LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address and screen size

int washTime = 5; // Default washing time 5 minutes
int rinseTime = 5; // Default rinse time 5 minutes
int spinTime = 2; // Default spin time 2 minutes

bool waterFull = false;
//--------------------------------------------------------------------
void setup() {
  pinMode(WATER_INTAKE_RELAY_PIN, OUTPUT);
  pinMode(LEFT_ICE_CREAM_RELAY_PIN, OUTPUT);
  pinMode(RIGHT_ICE_CREAM_RELAY_PIN, OUTPUT);
  pinMode(WATER_DRAIN_RELAY_PIN, OUTPUT);
  pinMode(TIGHTENING_RELEASE_PIN, OUTPUT);
  pinMode(FULL_SENSOR_PIN, INPUT);

  pinMode(INCREASE_BUTTON_PIN, INPUT_PULLUP);
  pinMode(REDUCTION_BUTTON_PIN, INPUT_PULLUP);
  pinMode(SELECTION_BUTTON_PIN, INPUT_PULLUP);

  lcd.init(); //initialize LCD screen
  lcd.backlight(); //Turn on backlight
}
//------------------------------------------------------------------------
void loop() {
  lcd.setCursor(0, 0);
  lcd.print("Wash: ");
  lcd.print(washTime);
  lcd.print(" min");

  lcd.setCursor(0, 1);
  lcd.print("Rinse: ");
  lcd.print(rinseTime);
  lcd.print(" min");

  if (digitalRead(SELECTION_BUTTON_PIN) == LOW) {
    // Start the washing program when the selection button is pressed
    washingProgram();
  }

  washTime = SetTimeWithsettingButtons(washTime, WASHING_TIME_MIN, WASHING_TIME_MAX);
  rinseTime = SetTimeWithsettingButtons(rinseTime, RINSE_TIME_MIN, RINSE_TIME_MAX);
}
//------------------------------------------------------------------------
void washingProgram() {
  //wash
  lcd.clear();
  lcd.print("Washing has started");

  digitalWrite(WATER_INTAKE_RELAY_PIN, HIGH); // Question
  while (!waterFull) {
    waterFull = digitalRead(FULL_SENSOR_PIN); //Check full sensor
  }
  digitalWrite(WATER_INTAKE_RELAY_PIN, LOW); // Water intake relay close

  for (int i = 0; i < 3; i++) { // repeat 3 times (wash, 2 rinses)
    for (int j = 0; j < washTime; j++) { // Washing during the washing time
      lcd.setCursor(0, 1);
      lcd.print("Remaining sura: ");
      lcd.print(washTime - j);
      lcd.print("min.");

      digitalWrite(RIGHT_ICE_CREAM_RELAY_PIN, HIGH); // Turn right
      delay(5000);
      digitalWrite(RIGHT_ICE_CREAM_RELAY_PIN, LOW);

      delay(5000);

      digitalWrite(LEFT_ICE_CREAM_RELAY_PIN, HIGH); // Turn left
      delay(5000);
      digitalWrite(LEFT_ICE_CREAM_RELAY_PIN, LOW);

      delay(5000);
    }

    digitalWrite(WATER_DRAIN_RELAY_PIN, HIGH); // Drain water
    lcd.setCursor(0, 0);
    lcd.print("Water Drain");
    delay(10000);
    digitalWrite(WATER_DRAIN_RELAY_PIN, LOW);

    if (i < 2) { // Do not spin after the last rinse
      //Rinse


      digitalWrite(WATER_INTAKE_RELAY_PIN, HIGH); // Question
      delay; while (!waterFull) {
        waterFull = digitalRead(FULL_SENSOR_PIN); //Check full sensor
        if (!waterFull) { // If it is not full of water
          lcd.clear();
          lcd.setCursor(0, 1);
          lcd.print("Tank empty. Waiting...");
        }
        delay(1000); // wait 1 second
      }
      lcd.clear();
      lcd.print("Rinsing has started");
      lcd.setCursor(0, 1);
      lcd.print("R. time: ");
      lcd.print(rinseTime);
      lcd.print("min.");

      digitalWrite(WATER_INTAKE_RELAY_PIN, LOW); // Water intake relay close
      lcd.setCursor(0, 1);
      lcd.print("R. time: ");
      lcd.print(rinseTime - i);

      digitalWrite(RIGHT_ICE_CREAM_RELAY_PIN, HIGH); // Turn right
      delay(5000);
      digitalWrite(RIGHT_ICE_CREAM_RELAY_PIN, LOW);

      delay(5000);

      digitalWrite(LEFT_ICE_CREAM_RELAY_PIN, HIGH); // Turn left
      delay(5000);
      digitalWrite(LEFT_ICE_CREAM_RELAY_PIN, LOW);

      delay(5000);
    }
  }

  //Tighten
  lcd.clear();
  lcd.print("Spinning has started");
  lcd.setCursor(0, 1);
  lcd.print("Remaining spin: ");
  lcd.print(spinTime);

  digitalWrite(TIGHTENING_RELEASE_PIN, HIGH); // Clamping relay open
  digitalWrite(WATER_DRAIN_RELAY_PIN, HIGH); // Drain water
  // The washing program is terminated
}
//------------------------------------------------------------------------
int SetTimeWithsettingButtons(int time, int minValue, int maxValue) {
  int increaseButtonStatus = digitalRead(INCREASE_BUTTON_PIN);
  int decreaseButtonStatus = digitalRead(REDUCTION_BUTTON_PIN);

  if (increaseButtonStatus == LOW) {
    time++;
    if (time > maxValue) {
      time = minValue;
    }
    delay(200); // Debouncing
  }

  if (decreaseButtonStatus == LOW) {
    time--;
    if (time < minValue) {
      time = maxValue;
    }
    delay(200); // Debouncing
  }

  return time;
}

Your code agrees. The full check is too early.

  digitalWrite(WATER_INTAKE_RELAY_PIN, HIGH); // Question
  while (!waterFull) {
    waterFull = digitalRead(FULL_SENSOR_PIN); //Check full sensor
  }
  digitalWrite(WATER_INTAKE_RELAY_PIN, LOW); // Water intake relay close

  for (int i = 0; i < 3; i++) { // repeat 3 times (wash, 2 rinses)
    for (int j = 0; j < washTime; j++) { // Washing during the washing time
      lcd.setCursor(0, 1);

Move it to just before the wash cycle begins again

  for (int i = 0; i < 3; i++) { // repeat 3 times (wash, 2 rinses)

    digitalWrite(WATER_INTAKE_RELAY_PIN, HIGH); // Question
    while (!waterFull) {
      waterFull = digitalRead(FULL_SENSOR_PIN); //Check full sensor
    }
    digitalWrite(WATER_INTAKE_RELAY_PIN, LOW); // Water intake relay close

    for (int j = 0; j < washTime; j++) { // Washing during the washing time
      lcd.setCursor(0, 1);

HTH

a7

1 Like

Everybody thank you for your time and interest. I solved the problem with “wait until the water level sensor high” command. I wil try again tomorrow. Instead of wait while , I used wait it turns HIGH. I hope it will work.
Thank you again and again.
Your time and interest is very precious for me.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.