RODI flush/fill

I am at a stand still and frying my brain lol. I am still a newbie so still learning so bare with me.

the system I am trying to do is to be able to use 2 float switches to turn on/off Solenoid's. this will flush out the tds creep from the ro unit first before running water through the DI stage to fill up a container. I am useing a arduino duemilanove if needed.

the basics of what my plan is: 2 float swtiches (1 at the bottom of container, 1 at the top) 3 solenoids (1st turns on the main water to the unit, 2nd routes the water to the drain, 3rd lets water go through the DI stage)

program: if both float switches are low it will turn on solenoids 1 and 2 for 4 min. (in my program I am useing less time for testing)

after the 4 min is up solenoid 2 closes and solenoids 1 and 3 are open

solenoids 1 and 3 stay open until both float switches are high. once they are both high all 3 solenoids are closed.

here is where I am lost. I have the program working for great (im useing led's in place of the solenoids for testing). I don't want the program to start again until both float switches are low. in my program it wants to turn back on when the high float switch has lowered.

here is the code I have so far

/*
 dual float switches, 3 solinoids

the circuit:
lower float switch opens solenoid to turn RODI unit on 
and opens solenoid to drain RO water for 3 min. after 3 min
solenoid to drain closes and solenoid to DI stage opens. water
continues to run until upper float switch is accitivated. once
higher float switch is acctivated all silenoids are closed
 */

// constants won't change. They're used here to 
// set pin numbers:
const int Float1 = 2;     // the number of float switch low
const int Float2 = 3;      // the number of float switch high
const int Solenoid1 =  5;      // the number for main water solinoid
const int Solenoid2 =  6;        //the number for RO drain solinoid
const int Solenoid3 = 7;        // the number for DI solinoid

// variables will change:
int buttonState1 = 0;         // variable for reading the pushbutton status
int buttonState2 = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the Solenoid pin as an output:
  pinMode(Solenoid1, OUTPUT);  
  pinMode(Solenoid2, OUTPUT);
  pinMode(Solenoid3, OUTPUT);  
  // initialize the Float switch as an input:
  pinMode(Float1, INPUT_PULLUP);
  pinMode(Float2, INPUT_PULLUP); 
}

void loop(){
  // read the state of the float valves:
  buttonState1 = digitalRead(Float1);
  buttonState2 = digitalRead(Float2);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState1 == LOW && buttonState2 == LOW) {        
    digitalWrite(Solenoid1, HIGH); // GREEN LED ON
    digitalWrite(Solenoid2, HIGH); // RED LED ON
    digitalWrite(Solenoid3, LOW); // YELLOW LED OFF
    delay(10000); // WAIT FOR CERTAIN TIME
    digitalWrite(Solenoid1, HIGH); // GREEN LED ON
    digitalWrite(Solenoid2, LOW); //RED LED OFF
    digitalWrite(Solenoid3, HIGH); // YELLOW LED ON
    delay(10000);
  } 
  if (buttonState1 == HIGH && buttonState2 == LOW) {     
    // turn LED on:    
    digitalWrite(Solenoid1, HIGH); 
    digitalWrite(Solenoid2, LOW);
    digitalWrite(Solenoid3, HIGH);
  } 
  if (buttonState1 == HIGH && buttonState2 == HIGH) {     
    // turn LED on:    
    digitalWrite(Solenoid1, LOW); 
    digitalWrite(Solenoid2, LOW);
    digitalWrite(Solenoid3, LOW); 
  }
  delay(2000);
}

OMG was it really this simple, I removed the: if (buttonState1 == HIGH && buttonState2 == LOW) { // turn LED on: digitalWrite(Solenoid1, HIGH); digitalWrite(Solenoid2, LOW); digitalWrite(Solenoid3, HIGH); }

section and now it seems to work as I needed. Ive been racking my brain so long I think I was over thinking things. here is the code now, does everything seem to be right or is there a way to make it more effeciant?

/*
 dual float switches, 3 solinoids

the circuit:
lower float switch opens solenoid to turn RODI unit on 
and opens solenoid to drain RO water for 3 min. after 3 min
solenoid to drain closes and solenoid to DI stage opens. water
continues to run until upper float switch is accitivated. once
higher float switch is acctivated all silenoids are closed
 */

// constants won't change. They're used here to 
// set pin numbers:
const int Float1 = 2;     // the number of float switch low
const int Float2 = 3;      // the number of float switch high
const int Solenoid1 =  5;      // the number for main water solinoid
const int Solenoid2 =  6;        //the number for RO drain solinoid
const int Solenoid3 = 7;        // the number for DI solinoid

// variables will change:
int buttonState1 = 0;         // variable for reading the pushbutton status
int buttonState2 = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the Solenoid pin as an output:
  pinMode(Solenoid1, OUTPUT);  
  pinMode(Solenoid2, OUTPUT);
  pinMode(Solenoid3, OUTPUT);  
  // initialize the Float switch as an input:
  pinMode(Float1, INPUT_PULLUP);
  pinMode(Float2, INPUT_PULLUP); 
}

void loop(){
  // read the state of the float valves:
  buttonState1 = digitalRead(Float1);
  buttonState2 = digitalRead(Float2);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState1 == LOW && buttonState2 == LOW) {        
    digitalWrite(Solenoid1, HIGH); // GREEN LED ON
    digitalWrite(Solenoid2, HIGH); // RED LED ON
    digitalWrite(Solenoid3, LOW); // YELLOW LED OFF
    delay(10000); // WAIT FOR CERTAIN TIME
    digitalWrite(Solenoid1, HIGH); // GREEN LED ON
    digitalWrite(Solenoid2, LOW); //RED LED OFF
    digitalWrite(Solenoid3, HIGH); // YELLOW LED ON
    delay(10000);
  } 
  if (buttonState1 == HIGH && buttonState2 == HIGH) {     
    // turn LED on:    
    digitalWrite(Solenoid1, LOW); 
    digitalWrite(Solenoid2, LOW);
    digitalWrite(Solenoid3, LOW); 
  }
  delay(2000);
}

Good that you have sorted your little problem out.

Can see that using a low cost RTC DS1307 module would make things even better, by acting as an emergency off, in case the float switches fail, plus you can schedule it to do a flush each day or week etc.

Also, cannot see any practical reason for the 3rd solenoid cutting off the DI pod; have never seen anyone doing that either. Even in Flush mode, very little RO water is produced, so DI use is insignificant.

While a flush between collections or before you start a collection is good, you should really do a flush after the collection, so excess contaminents are removed straight away.

hth

Yeah i have the rtc, and will most likely use it as a backup, right now i have a float valve for a backup to shut the water down but the timer will be good for shutting down the circuit.

I can most likely get by without the 1st solenoid as my system already has a auto shutoff, the reason for the one on the di is so i dont let the 1st few min if water when it’s turned on go to the di. When i 1st turn on the unit the tds is over 300ppm, if that goes in the di it will burn it up fairly fast.

I do like the flushing after the unit is done though, i will deff be adding that into the program. Thanks for the tip and help.