Water level indicator and pump controller

I have created a complete Water level indicator and pump controller system using Arduino Uno development Board, and i assembled it on a bread board,

my problem is,

when i power ON, it works without any errors, after filling the tank, the system will automatically standby, then, 10-15 min or later, when the water level goes low, it must be automatically run the connected water pump, but it does not turn on, however, water level indicators also works correctly, when passed the water level under the LOW floating sensor, LOW indicator also turn off, and the pump must be started as soon as the level passed LOW..

however when i press Reset button located on Arduino Board, it works again correctly...

pls explain what is the problem

thanking you,
my mail is ; mallawa@hotmail.com

show your code in proper way.
show schematic of your circuit.

test_11.ino (10.3 KB)

if you have tinkerkad account,

login and

use this link

simulator also working properly, and not only, my breadboard assembled unit also works,

sensors not working after 10-15 minutes turning ON power
thank you.

No, I hve´nt.

it is online simulator, there is no errors running on simulator, my problem occurred at the time of running the real project...

thank you.

you should make it easy for everyone by posting you code using the </> icon

the fundamental piece of code should be similar to following

const byte PumpPin      = LED_BUILTIN;
const byte LvlSensorPin = A0;

const int LowThresh = 400;
const int HiThresh  = 500;

enum { Off = HIGH, On = LOW };

void loop()
{
    int level = analogRead (LvlSensorPin);

    if (LowThresh > level)  {
        if (Off == digitalRead (PumpPin))
            digitalWrite (PumpPin, On);
    }
    else if (HiThresh < level)  {
        if (On == digitalRead (PumpPin))
            digitalWrite (PumpPin, Off);
    }

    delay (500);
    Serial.println (level);
}


void setup()
{
    Serial.begin (9600);
    pinMode (PumpPin, OUTPUT);
    pinMode (LvlSensorPin, INPUT_PULLUP);
}

#include <EEPROM.h>

const unsigned long debounceDelay = 50;

const int waterLevelSensorLow = 0;
const int waterLevelSensorMedium = 1;
const int waterLevelSensorHigh = 2;

const int btnPause = 3;
int btnPauseState;
int lastBtnPauseState = LOW;
unsigned long lastBtnPauseDebounceTime = 0;

const int btnAutoManual = 4;
int btnAutoManualState;
int lastBtnAutoManualState = LOW;
unsigned long lastBtnAutoManualDebounceTime = 0;

const int btnSemiAuto =5;
int btnSemiAutoState;
int lastSemiAutoState = LOW;
unsigned long lastBtnSemiAutoDebounceTime = 0;

const int ledWaterLevelLow = 6;
const int ledWaterLevelMedium = 7;
const int ledWaterLevelHigh = 8;

const int ledAuto = 9;
const int ledManual = 10;
const int ledPause = 13;
const int ledSemiAuto = A0;

const int waterMotor = A2;
const int buzzer = A3;

const int sumpTankLowSensor = A4;
const int ledSumpTankLow = A5;

const int ledRunning = 12;
const int ledStandby = 11;
int standbyLedBrightness = 0;
int standbyLedFadeAmount = 2;

const int ledTimer = A1;

bool isPaused = false;
bool isAuto = true;
bool isSemiAuto = false;

bool isPauseLedOn = false;
bool isRunningLedOn = false;
bool isTimerLedOn = false;

const long ledBlinkingTimeInMilliSeconds = 200;
long lastPauseLedChangedTime = 0;
long lastRunningLedChangedTime = 0;
long lastTimerLedChangedTime = 0;

//Water Level 0 = Empty, 1 = LOW, 2 = MEDIUM, 3 = HIGH
int waterLevel = -1;
int lastWaterLevel = -1;

bool runWaterMotor = false;
bool isWaterMotorRunning = false;

bool isSumpTankLow = false;

long motorStarTime = 0;
//5 minutes
const long motorMaxRunTimeInMilliseconds = 300000;

void setup() {

Serial.begin(9600);

pinMode(btnPause, INPUT);
pinMode(btnAutoManual, INPUT);
pinMode(btnSemiAuto, INPUT);

pinMode(ledPause, OUTPUT);
pinMode(ledAuto, OUTPUT);
pinMode(ledManual, OUTPUT);
pinMode(ledSemiAuto, OUTPUT);
pinMode(ledWaterLevelLow, OUTPUT);
pinMode(ledWaterLevelMedium, OUTPUT);
pinMode(ledWaterLevelHigh, OUTPUT);

pinMode(waterLevelSensorHigh, INPUT);
pinMode(waterLevelSensorMedium, INPUT);
pinMode(waterLevelSensorLow, INPUT);

pinMode(waterMotor, OUTPUT);
pinMode(buzzer, OUTPUT);

pinMode(sumpTankLowSensor, INPUT);
pinMode(ledSumpTankLow, OUTPUT);

pinMode(ledRunning, OUTPUT);
pinMode(ledStandby, OUTPUT);

pinMode(ledTimer, OUTPUT);

readFromEEPROM();

buzzerBeep();
buzzerBeep();
}

void readFromEEPROM() {

bool isEEPROMUpdated;
EEPROM.get(EEPROM.length() - 1, isEEPROMUpdated);

if (!isEEPROMUpdated){
return;
}

int eeAddress = 0;

EEPROM.get(eeAddress, isPaused);
eeAddress += sizeof(bool);

EEPROM.get(eeAddress, isAuto);
eeAddress += sizeof(bool);

EEPROM.get(eeAddress, isSemiAuto);
eeAddress += sizeof(bool);

EEPROM.get(eeAddress, lastWaterLevel);
eeAddress += sizeof(int);

EEPROM.get(eeAddress, runWaterMotor);
eeAddress += sizeof(bool);

EEPROM.get(eeAddress, isWaterMotorRunning);
eeAddress += sizeof(bool);

EEPROM.get(eeAddress, motorStarTime);
eeAddress += sizeof(long);
}

void loop() {

updateSumpTankWaterStatus();
updateWaterLevel();
updateButtonStatuses();
handleWaterMotor();
updateEEPROM();
}

void updateSumpTankWaterStatus() {
int status = digitalRead(sumpTankLowSensor);

isSumpTankLow = !status;
digitalWrite(ledSumpTankLow, isSumpTankLow);
}

void updateWaterLevel() {
setWaterLevel();
handleWaterLevelLed();
}

void setWaterLevel() {

int low = digitalRead(waterLevelSensorLow);
int medium = digitalRead(waterLevelSensorMedium);
int high = digitalRead(waterLevelSensorHigh);

int calculatedWaterLevel;

if (low == LOW && medium == LOW && high == LOW) {
calculatedWaterLevel = 3;
} else if (low == LOW && medium == LOW && high == HIGH) {
calculatedWaterLevel = 2;
} else if (low == LOW && medium == HIGH && high == HIGH) {
calculatedWaterLevel = 1;
} else if (low == HIGH && medium == HIGH && high == HIGH) {
calculatedWaterLevel = 0;
} else {
calculatedWaterLevel = -1;
}

if(waterLevel != calculatedWaterLevel) {

if(lastWaterLevel == -1) {
  lastWaterLevel = calculatedWaterLevel;
} else {
  lastWaterLevel = waterLevel;
}

waterLevel = calculatedWaterLevel;

}
}

void handleWaterLevelLed() {

if (waterLevel == 1) {

digitalWrite(ledWaterLevelHigh, LOW);
digitalWrite(ledWaterLevelMedium, LOW);
digitalWrite(ledWaterLevelLow, HIGH);

} else if (waterLevel == 2) {

digitalWrite(ledWaterLevelHigh, LOW);
digitalWrite(ledWaterLevelMedium, HIGH);
digitalWrite(ledWaterLevelLow, HIGH);

} else if (waterLevel == 3) {

digitalWrite(ledWaterLevelHigh, HIGH);
digitalWrite(ledWaterLevelMedium, HIGH);
digitalWrite(ledWaterLevelLow, HIGH);

} else {

digitalWrite(ledWaterLevelHigh, LOW);
digitalWrite(ledWaterLevelMedium, LOW);
digitalWrite(ledWaterLevelLow, LOW);

}
}

void updateButtonStatuses() {
setAutoStatus();
setPauseStatus();
setSemiAutoStatus();

handleAutoManualLeds();
handlePauseLed();
handleSemiAutoLed();
}

void setAutoStatus() {

int reading = digitalRead(btnAutoManual);

if (reading != lastBtnAutoManualState) {
lastBtnAutoManualDebounceTime = millis();
}

if ((millis() - lastBtnAutoManualDebounceTime) > debounceDelay) {
if (reading != btnAutoManualState) {
btnAutoManualState = reading;

  if (btnAutoManualState == HIGH) {
    isAuto = !isAuto;
    buzzerBeep();
  }
}

}
lastBtnAutoManualState = reading;
}

void handleAutoManualLeds() {

bool isAutoLedOn = isAuto && !isPaused;
digitalWrite(ledAuto, isAutoLedOn);

bool isManualLedOn = !isAuto && !isPaused;
digitalWrite(ledManual, isManualLedOn);
}

void setPauseStatus() {

int reading = digitalRead(btnPause);

if (reading != lastBtnPauseState) {
lastBtnPauseDebounceTime = millis();
}

if ((millis() - lastBtnPauseDebounceTime) > debounceDelay) {
if (reading != btnPauseState) {
btnPauseState = reading;

  if (btnPauseState == HIGH) {
    isPaused = !isPaused;
  }
}

}
lastBtnPauseState = reading;
}

void handlePauseLed() {

if(isPaused) {

long timeElapsedAfterLastChange = millis() - lastPauseLedChangedTime;

if(timeElapsedAfterLastChange > ledBlinkingTimeInMilliSeconds) {
  
  isPauseLedOn = !isPauseLedOn;
  digitalWrite(ledPause, isPauseLedOn);
  lastPauseLedChangedTime = millis();
}

} else {

digitalWrite(ledPause, LOW);
isPauseLedOn = false;

}

if(isPauseLedOn) {
buzzerBeep();
}
}

void setSemiAutoStatus() {

int reading = digitalRead(btnSemiAuto);

if (reading != lastSemiAutoState) {
lastBtnSemiAutoDebounceTime = millis();
}

if ((millis() - lastBtnSemiAutoDebounceTime) > debounceDelay) {
if (reading != btnSemiAutoState) {
btnSemiAutoState = reading;

  if (btnSemiAutoState == HIGH) {
    isSemiAuto = !isSemiAuto && (waterLevel < 3 && waterLevel > 0);
    buzzerBeep();
  }
}

}
lastSemiAutoState = reading;

if (waterLevel == 3) {
isSemiAuto = false;
}
}

void handleSemiAutoLed() {
digitalWrite(ledSemiAuto, isSemiAuto && isAuto && !isPaused);
}

void handleWaterMotor() {
setWaterMotorRunStatus();

if(isWaterMotorRunning != runWaterMotor) {

if(runWaterMotor) {
  buzzerBeep();
  buzzerBeep();
  buzzerBeep();
  
  motorStarTime = millis();
}

digitalWrite(waterMotor, runWaterMotor);
isWaterMotorRunning = runWaterMotor;

if(!runWaterMotor) {
  buzzerBeep();
  buzzerBeep();
  buzzerBeep();
  
  motorStarTime = 0;
}

}

handleRunningLed();
handleSandbyLed();
handleTimerLed();
}

void setWaterMotorRunStatus() {

bool isWaterLevelLow = waterLevel == 0;
bool isWaterLevelLowToHigh = waterLevel < 3 && waterLevel > 0;
bool isTankFillingUp = isWaterLevelLowToHigh && waterLevel > lastWaterLevel;
bool runMotorAutoMode = isAuto && (isWaterLevelLow || isTankFillingUp);
bool runMotorSemiAutoMode = isSemiAuto && (isWaterLevelLowToHigh || isTankFillingUp);
bool isTimerUp = isAuto && (millis() - motorStarTime) >= motorMaxRunTimeInMilliseconds;

runWaterMotor = (runMotorAutoMode || runMotorSemiAutoMode || !isAuto) && !isPaused && !isSumpTankLow && !isTimerUp;
}

void handleRunningLed() {

if(isWaterMotorRunning) {

long timeElapsedAfterLastChange = millis() - lastRunningLedChangedTime;

if(timeElapsedAfterLastChange > ledBlinkingTimeInMilliSeconds) {
  
  isRunningLedOn = !isRunningLedOn;
  digitalWrite(ledRunning, isRunningLedOn);
  lastRunningLedChangedTime = millis();
}

} else {

digitalWrite(ledRunning, LOW);
isRunningLedOn = false;

}

if(isRunningLedOn) {
buzzerBeep();
}
}

void handleSandbyLed() {

if(!isWaterMotorRunning && (isAuto || isSemiAuto) && !isPaused) {

analogWrite(ledStandby, standbyLedBrightness);
standbyLedBrightness = standbyLedBrightness + standbyLedFadeAmount;

if (standbyLedBrightness <= 0 || standbyLedBrightness >= 255) {
	standbyLedFadeAmount = -standbyLedFadeAmount;
}

delay(30);

} else {
digitalWrite(ledStandby, LOW);
}
}

void handleTimerLed() {

if(isWaterMotorRunning && motorStarTime > 0 && isAuto){

long timeElapsedAfterLastChange = millis() - lastTimerLedChangedTime;

if(timeElapsedAfterLastChange > ledBlinkingTimeInMilliSeconds) {
  
  isTimerLedOn = !isTimerLedOn;
  digitalWrite(ledTimer, isTimerLedOn);
  lastTimerLedChangedTime = millis();
}

} else {
digitalWrite(ledTimer, LOW);
isTimerLedOn = false;
}
}

void buzzerBeep() {
const int buzzerTime = 250;

digitalWrite(buzzer, HIGH);
delay(buzzerTime);
digitalWrite(buzzer, LOW);
delay(buzzerTime);
}

void updateEEPROM() {

int eeAddress = 0;

EEPROM.update(eeAddress, isPaused);
eeAddress += sizeof(bool);

EEPROM.update(eeAddress, isAuto);
eeAddress += sizeof(bool);

EEPROM.update(eeAddress, isSemiAuto);
eeAddress += sizeof(bool);

EEPROM.update(eeAddress, lastWaterLevel);
eeAddress += sizeof(int);

EEPROM.update(eeAddress, runWaterMotor);
eeAddress += sizeof(bool);

EEPROM.update(eeAddress, isWaterMotorRunning);
eeAddress += sizeof(bool);

EEPROM.update(eeAddress, motorStarTime);
eeAddress += sizeof(long);

EEPROM.update(EEPROM.length() - 1, true);
}

Code in code tags please.

Yuppers, directly energizing a relay coil from an Arduino GPIO pin is trouble. Use a opto-isolated relay module.

Use words like "opto isolated relay module" in an internet searchie thingy.

And don't expect the 9V battery to last for any meaningful length of time.

That the reason why I don´t use a simulator.

thank you, but that is not my problem kolaha,

simulator also working properly, and not only, my breadboard assembled unit also works,
BUT,
sensors not working after 10-15 minutes turning ON power
thank you.

Auto/Manual button is uses for the pump run manual / Automatically

PAUSE - it means when the running pump, you can STOP the pump temporarly

that's all,
but my problem is simulator also working properly, and not only, my breadboard assembled unit also works,

sensors not working after 10-15 minutes turning ON power
thank you.

Can you run your real circuit with just the switches and sensors and LEDs?

No motors or relays or pumps.

If it works in the sim and not real life, you have a wiring or power issue.

Also, why so many resistors in the upper right hand corner of your drawing? Resistors and switches and sensors all on the same pins?

Also please Autoformat your code using the tool in the IDE, then Copy for Forum using the IDE ability, then paste it here so it is certain fidelity and easier to read.

TIA

a7

can you explain your logic for controlling when the motor runs and its stopped?

which inputs are monitored and which sub-functions control the motor

Your post with the code is not posted as a code-section.
Posting code as plain text makes it really awful !

re-edit the posting with the code that the code is shown as a code-section
here is a manual how to do this

best regards Stefan

[code]
#include <EEPROM.h>

const unsigned long debounceDelay = 50;

const int waterLevelSensorLow = 0;
const int waterLevelSensorMedium = 1;
const int waterLevelSensorHigh = 2;

const int btnPause = 3;
int btnPauseState;
int lastBtnPauseState = LOW;
unsigned long lastBtnPauseDebounceTime = 0;

const int btnAutoManual = 4;
int btnAutoManualState;
int lastBtnAutoManualState = LOW;
unsigned long lastBtnAutoManualDebounceTime = 0;

const int btnSemiAuto =5;
int btnSemiAutoState;
int lastSemiAutoState = LOW;
unsigned long lastBtnSemiAutoDebounceTime = 0;

const int ledWaterLevelLow = 6;
const int ledWaterLevelMedium = 7;
const int ledWaterLevelHigh = 8;

const int ledAuto = 9;
const int ledManual = 10;
const int ledPause = 13;
const int ledSemiAuto = A0;

const int waterMotor = A2;
const int buzzer = A3;

const int sumpTankLowSensor = A4;
const int ledSumpTankLow = A5;

const int ledRunning = 12;
const int ledStandby = 11;
int standbyLedBrightness = 0;
int standbyLedFadeAmount = 2;

const int ledTimer = A1;

bool isPaused = false;
bool isAuto = true;
bool isSemiAuto = false;

bool isPauseLedOn = false;
bool isRunningLedOn = false;
bool isTimerLedOn = false;

const long ledBlinkingTimeInMilliSeconds = 200;
long lastPauseLedChangedTime = 0;
long lastRunningLedChangedTime = 0;
long lastTimerLedChangedTime = 0;

//Water Level 0 = Empty, 1 = LOW, 2 = MEDIUM, 3 = HIGH
int waterLevel = -1;
int lastWaterLevel = -1; 

bool runWaterMotor = false;
bool isWaterMotorRunning = false;

bool isSumpTankLow = false;

long motorStarTime = 0;
//5 minutes
const long motorMaxRunTimeInMilliseconds = 30000;

void setup() {
  
  Serial.begin(9600);
  
  pinMode(btnPause, INPUT);
  pinMode(btnAutoManual, INPUT);
  pinMode(btnSemiAuto, INPUT);
  
  pinMode(ledPause, OUTPUT);
  pinMode(ledAuto, OUTPUT);
  pinMode(ledManual, OUTPUT);
  pinMode(ledSemiAuto, OUTPUT);
  pinMode(ledWaterLevelLow, OUTPUT);
  pinMode(ledWaterLevelMedium, OUTPUT);
  pinMode(ledWaterLevelHigh, OUTPUT);
  
  pinMode(waterLevelSensorHigh, INPUT);
  pinMode(waterLevelSensorMedium, INPUT);
  pinMode(waterLevelSensorLow, INPUT);
  
  pinMode(waterMotor, OUTPUT);
  pinMode(buzzer, OUTPUT);
  
  pinMode(sumpTankLowSensor, INPUT);
  pinMode(ledSumpTankLow, OUTPUT);
  
  pinMode(ledRunning, OUTPUT);
  pinMode(ledStandby, OUTPUT);
  
  pinMode(ledTimer, OUTPUT);
  
  //readFromEEPROM();
  
  buzzerBeep();
  buzzerBeep();
}

void readFromEEPROM() {
  
  bool isEEPROMUpdated;
  EEPROM.get(EEPROM.length() - 1, isEEPROMUpdated);
  
  if (!isEEPROMUpdated){
    return;
  }
  
  int eeAddress = 0;
  
  EEPROM.get(eeAddress, isPaused);
  eeAddress += sizeof(bool);
    
  EEPROM.get(eeAddress, isAuto);
  eeAddress += sizeof(bool);
  
  EEPROM.get(eeAddress, isSemiAuto);
  eeAddress += sizeof(bool);
  
  EEPROM.get(eeAddress, lastWaterLevel);
  eeAddress += sizeof(int);
  
  EEPROM.get(eeAddress, runWaterMotor);
  eeAddress += sizeof(bool);
  
  EEPROM.get(eeAddress, isWaterMotorRunning);
  eeAddress += sizeof(bool);
  
  EEPROM.get(eeAddress, motorStarTime);
  eeAddress += sizeof(long);
}

void loop() {
  
  updateSumpTankWaterStatus();
  updateWaterLevel();
  updateButtonStatuses();
  handleWaterMotor();
  updateEEPROM();
}

void updateSumpTankWaterStatus() {
  int status = digitalRead(sumpTankLowSensor);
  
  isSumpTankLow = !status;
  digitalWrite(ledSumpTankLow, isSumpTankLow);
}

void updateWaterLevel() {
  setWaterLevel();
  handleWaterLevelLed();
}

void setWaterLevel() {
  
  int low = digitalRead(waterLevelSensorLow);
  int medium = digitalRead(waterLevelSensorMedium);
  int high = digitalRead(waterLevelSensorHigh);
  
  int calculatedWaterLevel;
  
  if (low == LOW && medium == LOW && high == LOW) {
  	calculatedWaterLevel = 3;
  } else if (low == LOW && medium == LOW && high == HIGH) {
  	calculatedWaterLevel = 2;
  } else if (low == LOW && medium == HIGH && high == HIGH) {
  	calculatedWaterLevel = 1;
  } else if (low == HIGH && medium == HIGH && high == HIGH) {
  	calculatedWaterLevel = 0;
  } else {
  	calculatedWaterLevel = -1;
  }
  
  if(waterLevel != calculatedWaterLevel) {
    
    if(lastWaterLevel == -1) {
      lastWaterLevel = calculatedWaterLevel;
    } else {
      lastWaterLevel = waterLevel;
    }
    
    waterLevel = calculatedWaterLevel;
  }
}

void handleWaterLevelLed() {
    
  if (waterLevel == 1) {
    
    digitalWrite(ledWaterLevelHigh, LOW);
    digitalWrite(ledWaterLevelMedium, LOW);
    digitalWrite(ledWaterLevelLow, HIGH);
    
  } else if (waterLevel == 2) {
    
    digitalWrite(ledWaterLevelHigh, LOW);
    digitalWrite(ledWaterLevelMedium, HIGH);
    digitalWrite(ledWaterLevelLow, HIGH);
    
  } else if (waterLevel == 3) {
    
    digitalWrite(ledWaterLevelHigh, HIGH);
    digitalWrite(ledWaterLevelMedium, HIGH);
    digitalWrite(ledWaterLevelLow, HIGH);
  
  } else {
  
    digitalWrite(ledWaterLevelHigh, LOW);
    digitalWrite(ledWaterLevelMedium, LOW);
    digitalWrite(ledWaterLevelLow, LOW);
  }
}

void updateButtonStatuses() {
  setAutoStatus();
  setPauseStatus();
  setSemiAutoStatus();
  
  handleAutoManualLeds();
  handlePauseLed();
  handleSemiAutoLed();
}

void setAutoStatus() {
  
  int reading = digitalRead(btnAutoManual);
  
  if (reading != lastBtnAutoManualState) {
    lastBtnAutoManualDebounceTime = millis();
  }
  
  if ((millis() - lastBtnAutoManualDebounceTime) > debounceDelay) {
    if (reading != btnAutoManualState) {
      btnAutoManualState = reading;

      if (btnAutoManualState == HIGH) {
        isAuto = !isAuto;
        buzzerBeep();
      }
    }
  }
  lastBtnAutoManualState = reading;
}

void handleAutoManualLeds() {
  
  bool isAutoLedOn = isAuto && !isPaused;
  digitalWrite(ledAuto, isAutoLedOn);
  
  bool isManualLedOn = !isAuto && !isPaused;
  digitalWrite(ledManual, isManualLedOn);
}

void setPauseStatus() {
  
  int reading = digitalRead(btnPause);
  
  if (reading != lastBtnPauseState) {
    lastBtnPauseDebounceTime = millis();
  }
  
  if ((millis() - lastBtnPauseDebounceTime) > debounceDelay) {
    if (reading != btnPauseState) {
      btnPauseState = reading;

      if (btnPauseState == HIGH) {
        isPaused = !isPaused;
      }
    }
  }
  lastBtnPauseState = reading;
}

void handlePauseLed() {
    
  if(isPaused) {
    
    long timeElapsedAfterLastChange = millis() - lastPauseLedChangedTime;
    
    if(timeElapsedAfterLastChange > ledBlinkingTimeInMilliSeconds) {
      
      isPauseLedOn = !isPauseLedOn;
      digitalWrite(ledPause, isPauseLedOn);
      lastPauseLedChangedTime = millis();
    }
  } else {
  
    digitalWrite(ledPause, LOW);
    isPauseLedOn = false;
  } 

  if(isPauseLedOn) {
    buzzerBeep();
  }
}

void setSemiAutoStatus() {
  
  int reading = digitalRead(btnSemiAuto);
  
  if (reading != lastSemiAutoState) {
    lastBtnSemiAutoDebounceTime = millis();
  }
  
  if ((millis() - lastBtnSemiAutoDebounceTime) > debounceDelay) {
    if (reading != btnSemiAutoState) {
      btnSemiAutoState = reading;

      if (btnSemiAutoState == HIGH) {
        isSemiAuto = !isSemiAuto && (waterLevel < 3 && waterLevel > 0);
        buzzerBeep();
      }
    }
  }
  lastSemiAutoState = reading;
  
  if (waterLevel == 3) {
    isSemiAuto = false;
  }
}

void handleSemiAutoLed() {
  digitalWrite(ledSemiAuto, isSemiAuto && isAuto && !isPaused);
}

void handleWaterMotor() {
  setWaterMotorRunStatus();
  
  if(isWaterMotorRunning != runWaterMotor) {
    
    if(runWaterMotor) {
      buzzerBeep();
      buzzerBeep();
      buzzerBeep();
      
      motorStarTime = millis();
    }
    
    digitalWrite(waterMotor, runWaterMotor);
    isWaterMotorRunning = runWaterMotor;
    
    if(!runWaterMotor) {
      buzzerBeep();
      buzzerBeep();
      buzzerBeep();
      
      motorStarTime = 0;
    }
  }
  
  handleRunningLed();
  handleSandbyLed();
  handleTimerLed();
}

void setWaterMotorRunStatus() {
  
  bool isWaterLevelLow = waterLevel == 0;
  bool isWaterLevelLowToHigh = waterLevel < 3 && waterLevel > 0;
  bool isTankFillingUp = isWaterLevelLowToHigh && waterLevel > lastWaterLevel;
  bool runMotorAutoMode = isAuto && (isWaterLevelLow || isTankFillingUp);
  bool runMotorSemiAutoMode = isSemiAuto && (isWaterLevelLowToHigh || isTankFillingUp);
  bool isTimerUp = isAuto && (millis() - motorStarTime) >= motorMaxRunTimeInMilliseconds;
  
  
  runWaterMotor = (runMotorAutoMode || runMotorSemiAutoMode || !isAuto) && !isPaused && !isSumpTankLow && !isTimerUp;
}

void handleRunningLed() {
    
  if(isWaterMotorRunning) {
    
    long timeElapsedAfterLastChange = millis() - lastRunningLedChangedTime;
    
    if(timeElapsedAfterLastChange > ledBlinkingTimeInMilliSeconds) {
      
      isRunningLedOn = !isRunningLedOn;
      digitalWrite(ledRunning, isRunningLedOn);
      lastRunningLedChangedTime = millis();
    }
  } else {
  
    digitalWrite(ledRunning, LOW);
    isRunningLedOn = false;
  } 

  if(isRunningLedOn) {
    buzzerBeep();
  }
}

void handleSandbyLed() {
  
  if(!isWaterMotorRunning && (isAuto || isSemiAuto) && !isPaused) {      
  	
    analogWrite(ledStandby, standbyLedBrightness);
  	standbyLedBrightness = standbyLedBrightness + standbyLedFadeAmount;

  	if (standbyLedBrightness <= 0 || standbyLedBrightness >= 255) {
    	standbyLedFadeAmount = -standbyLedFadeAmount;
  	}
    
  	delay(30);
    
  } else {
    digitalWrite(ledStandby, LOW);
  }
}

void handleTimerLed() {
  
  if(isWaterMotorRunning && motorStarTime > 0 && isAuto){
    
    long timeElapsedAfterLastChange = millis() - lastTimerLedChangedTime;
    
    if(timeElapsedAfterLastChange > ledBlinkingTimeInMilliSeconds) {
      
      isTimerLedOn = !isTimerLedOn;
      digitalWrite(ledTimer, isTimerLedOn);
      lastTimerLedChangedTime = millis();
    }
  } else {
     digitalWrite(ledTimer, LOW);
     isTimerLedOn = false;
  }
}

void buzzerBeep() {
  const int buzzerTime = 250;
  
  digitalWrite(buzzer, HIGH);
  delay(buzzerTime);
  digitalWrite(buzzer, LOW);
  delay(buzzerTime);
}

void updateEEPROM() {
  
  int eeAddress = 0;
  
  EEPROM.update(eeAddress, isPaused);
  eeAddress += sizeof(bool);
    
  EEPROM.update(eeAddress, isAuto);
  eeAddress += sizeof(bool);
  
  EEPROM.update(eeAddress, isSemiAuto);
  eeAddress += sizeof(bool);
  
  EEPROM.update(eeAddress, lastWaterLevel);
  eeAddress += sizeof(int);
  
  EEPROM.update(eeAddress, runWaterMotor);
  eeAddress += sizeof(bool);
  
  EEPROM.update(eeAddress, isWaterMotorRunning);
  eeAddress += sizeof(bool);
  
  EEPROM.update(eeAddress, motorStarTime);
  eeAddress += sizeof(long);
  
  EEPROM.update(EEPROM.length() - 1, true);
}
[/code]



Hi @sanjeewamdn,
well done posting your code as a code-section.

Even better would be to re-edit your

post #9

best regards Stefan
Be the change you want to see in the world

This notion of be the change you want to see in the world does 3 powerful things when we adopt it:
It stops us from judging others;
It replaces complaining about others with reflection on self;
It stirs us into taking action within the only thing in the world over which we have any control: ourselves.