My program doesn't execute properly

hey guys this is my first post and concerning my first arduino project. :slight_smile:
i have created a model for wastewater treatment using arduino. Basically what happens is a relay module controls the four stages of the treatment.
First water is pumped to a tank with the aid of water level sensor(HC SR04 module). Next a gear motor is activated to stir the water. Next all appliances are switched off for the waste to settle. Finally the treated water is pumped out of the tank. Here again the sensor is activated. Throughout these stages and LCD displays the ongoing process and the remaining time for the process to end and also 4 LED's depict the current stage.
My code worked properly at first but now suddenly it isn't working like its supposed to!!! All the LED's light up at once and the LCD doesn't display anything. And the stages don't switch!
Can anyone tell me why and where I've gone wrong?
Thank you!!!

Its the third wire…its upside down…

And that thingumy is not the correct dooberry to play with the whatsit…

Maybe you should (not so much maybe but DEFINITELY) you should go here first.
Then come back and add the many many details that are missing from your post.

//include the library code:
#include <LiquidCrystal.h>
#include <EEPROM.h>


#define echopin 15 // echo pin
#define trigpin 14// Trigger pin

int fillpump = 16;
int agitator = 17;
int decantpump = 18;
int led1 = 3;     //green
int led2 = 4;     //red
int led3 = 5;     //yellow
int led4 = 6;     //blue

int maximumRange = 50;
long duration, distance;

//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7,8,9,10,11,12);

//initialize the library with the numbers of the interface pins
int S,M,H,Stage;
int tVal;
int BtState;

  
  
  void SecToTime(int val){
  
      if(val<60){
        S=val;
        H=0;
        M=0;
        Serial.print(S);
        Serial.println("s");
        lcd.print("TIME> ");
        lcd.print(S);
        lcd.print("s");
        
        
        }else if(val>=60 && val<3600){
          M=val/60;
          S=(val%60);
          H=0;
          Serial.print(M);
          Serial.print("m ");
          Serial.print(S);
          Serial.println("s");
          lcd.print("TIME> ");
          lcd.print(M);
          lcd.print("m ");
          lcd.print(S);
          lcd.print("s");    
          
          
          }else if(val>=3600){
            S=(val%60);
            H=(val/3600);
            M=((val-S)%3600)/60;
    
            Serial.print(H);
            Serial.print("h ");
            Serial.print(M);
            Serial.print("m ");
            Serial.print(S);
            Serial.println("s");
    
    
            lcd.print("TIME> ");
            lcd.print(H);
            lcd.print("h ");
            lcd.print(M);
            lcd.print("m ");
            lcd.print(S);
            lcd.print("s");
          }
      
//Write Time to EEPROM (memory)
    EEPROM.write(1,H);
    EEPROM.write(2,M);
    EEPROM.write(3,S);  
  }


  void TimeToSec(int H,int M,int S){
    tVal=H*3600+M*60+S;
  }

      void setup() {
      
      Serial.begin (9600);
      
      pinMode (trigpin, OUTPUT);
      pinMode (echopin, INPUT );
      pinMode (13,OUTPUT);

      pinMode (led1,OUTPUT);
      pinMode (led2,OUTPUT);
      pinMode (led3,OUTPUT);
      pinMode (led4,OUTPUT);
      
      pinMode(fillpump,OUTPUT);            
      pinMode(agitator,OUTPUT);    
      pinMode(decantpump,OUTPUT);            
      
      // set up the LCD's number of columns and rows:
        lcd.begin(16,2);



   
     Stage = EEPROM.read(0);
      H = EEPROM.read(1);
      M = EEPROM.read(2);
      S = EEPROM.read(3);
    
      TimeToSec(H,M,S); 
}

void loop(){

  switch(Stage){
    
    case 1 :

          Stage=1;

          
    
          digitalWrite(trigpin,LOW);
          delayMicroseconds(2);

          digitalWrite(trigpin,HIGH);
          delayMicroseconds(10);
            
                    
          duration=pulseIn (echopin,HIGH);
          distance= duration/58.2;
          delay (50);
          Serial.println(distance);


          


      if (distance > 8 ){
        lcd.begin(16,2);
        lcd.clear();
        lcd.print("STAGE : 01");
        lcd.setCursor(3,1);
        lcd.print("FILLING WATER");   
        delay(2000);

         digitalWrite (13,HIGH);
        
         digitalWrite(led1,HIGH);
         digitalWrite(led3,LOW);
         digitalWrite(led2,LOW);
         digitalWrite(led4,LOW);

         digitalWrite(fillpump,LOW);       
         digitalWrite(agitator,HIGH);        
         digitalWrite(decantpump,HIGH);   

        delay(5000);     
     
}


    else if (distance <=7) {
       

        delay(100);
        lcd.begin(16, 2);
        lcd.print("END OF STAGE 01");
        delay(2000);
        Stage=2;
        tVal=30; //set Stage 2 time 30
        EEPROM.write(0, Stage);  

        
        digitalWrite (13,LOW);

        digitalWrite(fillpump,HIGH);       
        digitalWrite(agitator,LOW);        
        digitalWrite(decantpump,HIGH); 
      }


      
      //-------------END OF STAGE 1 ---------------------//
    break; 
    case 2 :

      //----------------STAGE 02--------------------------// 
        
        for(int i=tVal; i>0 ; i--){    ////     stage 2: 30 seconds

         digitalWrite(led4,HIGH);
         digitalWrite(led3,LOW);
         digitalWrite(led2,LOW);
         digitalWrite(led1,LOW);

          lcd.begin(16, 2);
          lcd.clear();
          lcd.print("STAGE : 02");
          lcd.setCursor(0, 1);
          SecToTime(i);
          
          
                    
        delay(1000);
        digitalWrite(fillpump,HIGH);   
        digitalWrite(agitator,HIGH);    
        digitalWrite(decantpump,HIGH);   
        
        delay(100);
         }
        digitalWrite(fillpump,HIGH);   
        digitalWrite(agitator,LOW);   
        digitalWrite(decantpump,HIGH);   
        
        delay(100);
        lcd.begin(16, 2);
        lcd.print("END OF STAGE 02");
        delay(2000);
        Stage=3;
        tVal=30; //set Stage 3 time 30
        EEPROM.write(0, Stage);
         //-------------END OF STAGE 2 ---------------------/
    break;
    case 3 :
    
       //----------------STAGE 03--------------------------// 
        digitalWrite(fillpump,HIGH);   
        digitalWrite(agitator,LOW);   
        digitalWrite(decantpump,HIGH); 

             
        
        delay(100);
                
        for(int i=tVal; i>0 ; i--){    ////     stage 3: 30 seconds 
          digitalWrite(led2,HIGH);
          digitalWrite(led4,LOW);
          digitalWrite(led3,LOW);
          digitalWrite(led1,LOW);  
          
          lcd.begin(16, 2);
          lcd.clear();
          lcd.print("STAGE : 03");
          lcd.setCursor(0, 1);
          SecToTime(i);
          delay(1000);
        }
        digitalWrite(fillpump,HIGH);   
        digitalWrite(agitator,LOW);  
        digitalWrite(decantpump,HIGH);   
        
        delay(100);
        lcd.begin(16, 2);
        lcd.print("END OF STAGE 03");
        delay(2000);
        Stage=4;
        EEPROM.write(0, Stage);
       //-----------------END OF STAGE 3 -------------------// 

  break;
  case 4 :
    
       //----------------STAGE 04--------------------------// 
       
   Stage=4;

         
                
         digitalWrite(trigpin,LOW);
         delayMicroseconds(2);

         digitalWrite(trigpin,HIGH);
         delayMicroseconds(10);

         duration=pulseIn (echopin,HIGH);
         distance= duration/58.2;
         delay (50);
         Serial.println(distance);

        if (distance <=7) {
          lcd.begin(16, 2);
          lcd.clear();
          lcd.print("STAGE : 04");   
          lcd.setCursor(3,1);
          lcd.print("DECANTING...");
          delay(2000);

         digitalWrite (13,HIGH); 
          
         digitalWrite(led3,HIGH);
         digitalWrite(led4,LOW);
         digitalWrite(led2,LOW);
         digitalWrite(led1,LOW);

         digitalWrite(fillpump,HIGH);   
         digitalWrite(agitator,LOW);   
         digitalWrite(decantpump,LOW);    
       
         
        delay(5000);
 }


         
       else if (distance > 25 ){

         digitalWrite (13,HIGH); 
         digitalWrite(fillpump,HIGH);   
         digitalWrite(agitator,LOW);   
         digitalWrite(decantpump,HIGH);    
         delay(100);
     
        lcd.begin(16, 2);
        lcd.print("END OF STAGE 04");
        delay(2000);
        Stage=1;
        EEPROM.write(0, Stage);
 }
      //-------------END OF STAGE 4 ---------------------/ 
  }
  }

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

Without looking closely at your code, my advice is to add a bunch of Serial.println() debug statements to get a better idea of where the problem is.