Liquid flow with an autovalve

Hi can any one help. Im trying to control a flow rate of a liquid using Arduino, ive uploaded the sketch, the sketch runs up to case 3 then nothing happens in not sure why, I know ive done some thing wrong I just cant work out what, what I want to happen is the valve opens to a set flow rate, I appreciate that such valves are non linear and iffy at best but for this set up thats fine, the sketch will probably need some tweaking too to get a better / more consistent flow but I can do that once I work out where ive gone wrong.

TIA

Pesh

sketch_FullVolume_Mash_Test_Sketch_2.0.ino (11.4 KB)

I'm a little confused because once you get to section 3 the comment states "Section added to time sparge for 1 hour" but you have a delay(500) in that section which results in decrementing the seconds counter every .5 seconds! In any case you remain in section 3 for 30 minutes before incrementing to the next section.

would you mind posting your sketch in Code tags? =) It is the </> symbol on the top of the taskbar :slight_smile: Many people here (including me) are on mobile and can't download and check an ino file on mobile phone.

So the bit that isnt working is this

 case 3: // set sparge rate

  Serial.println();
  Serial.println(section);
  Serial.println();
  Serial.println(spargeRate);
  Serial.println( "L/Min");
  Serial.println();
  Serial.println(BKFillFlowRate);
  
      
   if (BKFillFlowRate <= spargeRate+0.5 )  BKFillValveOpenControl(); 
   
   if  (BKFillFlowRate >= spargeRate-0.5 )  BKFillValveCloseControl() ; 
  
   
  
   
   
//      delay(5000);

       // Section added to time sparge for 1 hour

       {
 S--;
 delay(500);
 if(S<0)
 {
 M--;
 S=59;
}
if(M<0)
{
 H--;
 M=59;
}
 if(H<0) { H=23; M=59; S=59; } if(M>9)
 {
  Serial.print(M);
  Serial.print("  " );
  Serial.print ("\t");
 }
 else
 {
    Serial.print(M);
    Serial.print("  " );
    Serial.print ("\t");

 }
 if(S>9)
{
   Serial.print(S);
   Serial.print("  " );
   Serial.print("\t");
}

 else

 {

  Serial.print(S);
  Serial.print("  " );
  Serial.print("\t");
 }
 if(H>9)
{
 }
 else
 {
 Serial.println ();
 }

 if (M == 0 && S == 0)
  { 
     section = section +1;
    Serial.print ("stop");
   
  }
}
       
      break;


           case 4: // Open Bk Fill Valve to empty MLT
           
  openBKFillValve();
{

  
 section = section +1 ;

 break;
}


void openBKFillValve(){ 
       digitalWrite(BKFillEnablePin, HIGH);
       digitalWrite(BKFillMotor1Pin, LOW);
       digitalWrite(BKFillMotor2Pin, HIGH);
                 }                
void closeBKFillValve(){
       digitalWrite(BKFillEnablePin, HIGH);
       digitalWrite(BKFillMotor1Pin, HIGH);
       digitalWrite(BKFillMotor2Pin, LOW);  
                 }   
                 
                 
void BKFillValveOpenControl(){ // BKFill Open valve control for sparge
      long BKFillInterval = 100;
      long BKFillShortInterval = 50;   
      unsigned long BKFillCurrentMillis = millis();
      long BKFillPreviousMillis = 0;
      unsigned long BKFillSICurrentMillis = millis();
      long BKFillSIPreviousMillis = 0;
   if(BKFillCurrentMillis - BKFillPreviousMillis > BKFillInterval) {   
      digitalWrite(BKFillEnablePin, HIGH);
       digitalWrite(BKFillMotor1Pin, LOW);
       digitalWrite(BKFillMotor2Pin, HIGH);
       BKFillPreviousMillis = BKFillCurrentMillis; }
      if(BKFillSICurrentMillis - BKFillSIPreviousMillis > BKFillShortInterval) {   
       digitalWrite(BKFillEnablePin, HIGH);
       digitalWrite(BKFillMotor1Pin, LOW);
       digitalWrite(BKFillMotor2Pin, LOW);
       BKFillSIPreviousMillis = BKFillSICurrentMillis; }
 }        
                   
void BKFillValveCloseControl(){ // BKFill Close valve control for sparge
  long BKFillInterval = 100;
      long BKFillShortInterval = 50;   
      unsigned long BKFillCurrentMillis = millis();
      long BKFillPreviousMillis = 0;
      unsigned long BKFillSICurrentMillis = millis();
      long BKFillSIPreviousMillis = 0;
   if(BKFillCurrentMillis - BKFillPreviousMillis > BKFillInterval) {   
      digitalWrite(BKFillEnablePin, HIGH);
       digitalWrite(BKFillMotor1Pin, HIGH);
       digitalWrite(BKFillMotor2Pin, LOW);
       BKFillPreviousMillis = BKFillCurrentMillis; } 
       if(BKFillSICurrentMillis - BKFillSIPreviousMillis > BKFillShortInterval) {   
      digitalWrite(BKFillEnablePin, HIGH);
       digitalWrite(BKFillMotor1Pin, LOW);
       digitalWrite(BKFillMotor2Pin, LOW);
      BKFillSIPreviousMillis = BKFillSICurrentMillis; }
 }

Yeah so like i said it does want tweaked a bit, the sparge timer should run for 1 hour, i can take out the delay i guess, it should stay in case 3 for 1 hour. At this point i want to make it do some thing in case 3 then go from there, i have done this before but i cant remember how.

Thanks

Pesh

Pesho77:
So the bit that isnt working is this

Yeah so like i said it does want tweaked a bit, the sparge timer should run for 1 hour, i can take out the delay i guess, it should stay in case 3 for 1 hour. At this point i want to make it do some thing in case 3 then go from there, i have done this before but i cant remember how.

Thanks

Pesh

The best I can tell it is executing case 3 properly; however, it is only going to stay in section 3 for 30 minutes because you have a delay(500) rather than a delay(1000). Is it printing the minutes and seconds as you expect (other than each second is really .5 seconds)?

Yeah it looks like your right, the timer issue was an easy fix, but the valve wasn't operating at all, ive added a delay(500) after the

digitalWrite(BKFillEnablePin, HIGH);
digitalWrite(BKFillMotor1Pin, LOW);
digitalWrite(BKFillMotor2Pin, HIGH);
delay(500);

in the void BKFillValveOpenControl() , and that seams to have sorted it, im guessing the voltage is switching too fast for the valve to keep up and its just staying shut, this could be because of the age / condition of the valve too.

Thank you vert much

Pesh