currentTest<=previousTest HOW?!

I am a beginner that is struggling. If someone knows the title or the forum that I can look for that would be great please provide a link bellow.

Here is my issue. I am trying to control a cleaning bath and wanted to automate it with Arduino. I would like to take a EC reading and if it is bellow 9 I would like to add solution to bring the EC back to 10 by activating a pump on a timer. This part is simple. The hard part is how can I test to make sure that it has raised the EC after the first reading. I would like to test IF (currentReading <= prevuesReading). I would like to cycle the pump 3 times and on the third fail to improve the EC happens I would like to put it in a paused state. This is for safety and would keep acid from spilling on the floor or prevent the pump from burning up due to not having acid to pump from. Can someone explain to me how to accomplish this? I have looked on google and youtube for examples but I don’t exactly know how to search for the answer due to not knowing the proper key words. Please take some time and help out a rookie! Also if you have any example code showing how to do this that was be awesome.

Again thanks for your help.

Dipp007:
Can someone explain to me how to accomplish this?

State machine. You've already started. List the states. List the transitions.

If you have code written that attempts to do this, but doesn't work, post the code and we can point out the error.

Be sure to use code tags (</> button)

int potPen=A0; // this is a test for PH sen

int blueLED=3; // this is the pump

int potPenVal;

int safe=800;

String disp=("potreading ");

String pump=("Running Pump");

void setup()
{
pinMode,(potPen, INPUT); // EC test
pinMode,(blueLED, OUTPUT); // Pump test

Serial.begin(9600);

lcd.init(); // initialize the lcd
lcd.init();
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(0,0);
lcd.print ("Good Morning!");
lcd.setCursor(0,1);
lcd.print("let me get set");

delay (5000);
lcd.clear();

}

void loop()
{
potPenVal = analogRead(potPen); // EC Reading
Serial.println(potPenVal); // visual EC on serial
delay(500);
lcd.setCursor(0,0);
lcd.print (disp);
lcd.print (" ");
lcd.setCursor(0,0);
lcd.print (disp);
lcd.print (potPenVal); // visual on LCD

if (potPenVal<=safe)
{
lcd.setCursor(0,1);
lcd.print (pump);
digitalWrite(blueLED, HIGH); // pump running
delay(5000);
lcd.setCursor(0,1);
lcd.print(" ");
digitalWrite(blueLED, LOW); // pump off
delay(5000);

}

}

This is what I have been testing with but have been unable to get anything to work past this point and I don't know how to test the EC sensor against a prevues test to make sure the pump did its job.

Have a look at the attached. Run it with your serial monitor open and watch the sequence. Then look at the code and try to follow what it's doing. Note that delay() does not appear once in the code...

#define VALVE_ON            HIGH        //whatever turns the flow valve on
#define VALVE_OFF           LOW         //whatever turns the flow valve off
//
#define SOLUTION_ADD_TIME   10000ul     //mS to allow solution to flow (10-sec)
#define MIXING_TIME         30000ul     //mS to allow solution to mix before taking another EC sample (30-sec)
#define CHECK_INTERVAL      300000ul    //mS between check sequences (5-minutes)
//
#define INITIAL_STATE       0
#define ADD_SOLUTION        1
#define ALLOW_MIXING        2
#define CHECK_RESULT        3
#define SAFETY_SHUTDOWN     4
#define HALT_AND_CATCH_FIRE 5

const int pinValve = 13;

void setup() 
{
    Serial.begin(9600);
    pinMode( pinValve, OUTPUT );
    digitalWrite( pinValve, VALVE_OFF );

}//setup

void loop() 
{
    EC_StateMachine();
    
}//loop

void EC_StateMachine( void )
{
    static int
        attempts;
    int
        ECReading;
    static byte
        stateECSM = INITIAL_STATE;
    static unsigned long
        timeEC = -CHECK_INTERVAL;

    switch( stateECSM )
    {
        case    INITIAL_STATE:
            if( (millis() - timeEC) < CHECK_INTERVAL )
                return;
                
            ECReading = ReadEC();
            Serial.print( "EC reading.......: " ); Serial.println( ECReading );
            if( ECReading < 9 )
            {
                Serial.print( "Initiating flow..: " );
                attempts = 3;
                timeEC = millis();
                digitalWrite( pinValve, VALVE_ON );
                stateECSM = ADD_SOLUTION;
                
            }//if
            
        break;

        case    ADD_SOLUTION:
            if( (millis() - timeEC) >= SOLUTION_ADD_TIME )
            {
                Serial.println( "Complete" );
                digitalWrite( pinValve, VALVE_OFF );
                attempts--;
                Serial.print( "Attempts remain..: " ); Serial.println( attempts );
                //if we run out of attempts, go directly to safety shutdown
                if( attempts == 0 )
                    stateECSM = SAFETY_SHUTDOWN;
                else
                {
                    Serial.print( "Solution mixing..: " );
                    stateECSM = ALLOW_MIXING;
                    timeEC = millis();
                }//else
                    
            }//if
            
        case    ALLOW_MIXING:
            //allow time for the added solution to distribute through the bath
            if( (millis() - timeEC) >= MIXING_TIME )
            {
                Serial.println( "Complete" );
                stateECSM = CHECK_RESULT;
                
            }//if
            
        break;

        case    CHECK_RESULT:
            //see if the reading has risen to or above 9
            ECReading = ReadEC();
            Serial.print( "Result...........: " ); Serial.println( ECReading );
            if( ECReading < 9 )
            {
                Serial.print( "\nRetrying.........: " );
                timeEC = millis();
                digitalWrite( pinValve, VALVE_ON );
                stateECSM = ADD_SOLUTION;
                
            }//if
            else
            {
                timeEC = millis();
                stateECSM = INITIAL_STATE;
                
            }//set up for the next reading
            
        break;

        case    SAFETY_SHUTDOWN:
            Serial.print( "Safety shutdown" );    
            digitalWrite( pinValve, VALVE_OFF );
            stateECSM = HALT_AND_CATCH_FIRE;
        break;

        case    HALT_AND_CATCH_FIRE:
            //could add a reset button to return to initial state or wait in this state
            //until reset (e.g. power cycle or manual reset of Arduino etc)
        break;
        
    }//switch

}//EC_StateMachine

int ReadEC( void )
{
    //walk through the state machine to test safety shutdown
    //by always returning a value < 9
    //replace this with whatever reads your sensor
     
    return 8;
}

Thanks so much. I have no idea why i didn't think about it testing the 9. Thanks again huge help!