Four way valve control

I want to make the management of heating systems Four way valve with Arduino. Valve as this- Четырехходовые смесительные клапаны купить в Москве | Комфорт-Эко. I want to maintain a constant temperature in the valve output. The valve control motor unit has three wires-forward, rewind and GND. Maybe you have an algorithm for such management. Maybe you have an example, and you can share. I can not do it. Valve wanders back and forth ...

The picture shows a manually controlled mixer. It might be simpler to replace it with a pair of solenoid valves.

valve with a servo drive, as in this picture:
http://www.komfort-eco.ru/files/catalog/rubs/imgs/37/kat10_003.jpg

Hi,

I just finished a very similar project with an UNO.
The sketch measures internal temperature, external temperature and water temperature, makes up a water temperature value based on these, then moves the valve. here is the sketch, feel free to reuse if you like it.

4way_valve.ino (8.92 KB)

Thanks, I'll try and let you know the results :slight_smile:

Such a task should use the PID algorithm. I'll try to combine the following code

#include <PID_v1.h>
void loop()
{
Input = analogRead(0);
myPID.Compute();

/************************************************
* turn the output pin on/off based on pid output
************************************************/
if(millis() - windowStartTime>WindowSize)
{ //time to shift the Relay Window
windowStartTime += WindowSize;
}
if(Output==0)

{ //PID thinks we shouldn't activate either relay. Do nothing
digitalWrite(Relay_Valve_close, HIGH);
digitalWrite(Relay_Valve_open, HIGH);
}
else if(Output>0)

{ //Pid thinks we should be activating Relay_Valve_open
if(Output > millis() - windowStartTime) digitalWrite(Relay_Valve_open,LOW);

else digitalWrite(Relay_Valve_open,HIGH);
digitalWrite(Relay_Valve_close,HIGH);
}
else //PID thinks we should be activating Relay_Valve_close
{
if(-Output > millis() - windowStartTime) digitalWrite(Relay_Valve_close,LOW);
else digitalWrite(Relay_Valve_close,HIGH);
digitalWrite(Relay_Valve_open,HIGH);
}

}

Hi,
emzeperx, alvydas001, I have two questions:

  1. do you use NTC sensor and the value,
  2. which is a scheme to connect key (button)?

Thank you

  1. I use ds18b20 sensors.
  2. I use Dfrobot LCD Key pad and MenuBackend library.
    this code works fine:
    The valve is closing / is opening 6 seconds
    Pause for 20 seconds
    If the difference input-setpoint is less than 2 degrees, closing time 4 seconds + difference
    If the difference input-setpoint is more than 10 degrees, timeout=0
/* ******************************************************************************* */
void Four_way_valve_control()
  { 

/* ********* OPEN VALVE ***************** */
    if (Input_t <= SetPoint_t -1.5 && Valve_stop == true && Valve_closing == false && millis() > Valve_opening_time){
valve_error = SetPoint_t -1.5 -Input_t;
if (valve_error <= 2){ // if the difference is small
        Valve_stop = false; // valve moving
        Valve_opening = true;
        Valve_pause = millis() + 6000 - 2000 + (valve_error * 1000);
        digitalWrite(RelayPinClose, HIGH); 
        digitalWrite(RelayPinOpen, LOW); 
}else{
        Valve_stop = false; 
        Valve_opening = true;
        Valve_pause = millis() + 6000;
        digitalWrite(RelayPinClose, HIGH); 
        digitalWrite(RelayPinOpen, LOW); 
 }
   }
   /* ********* P A U S E 20 second after each valve switching ***************** */

   if (Valve_stop == false && millis() > Valve_pause) { 
   //If the difference is greater than 10 degrees, 
if (Input_t > SetPoint_t + 10) { //there is no pause
      Valve_closing_time = millis(); 
      Valve_opening_time = millis(); 
      Valve_stop = true; 
} else {
      Valve_pause = millis() + 20000; 
      Valve_closing_time = Valve_pause; 
      Valve_opening_time = Valve_pause; 
      Valve_stop = true; 
        digitalWrite(RelayPinClose, HIGH); 
        digitalWrite(RelayPinOpen, HIGH); 
}
   }
/* ********* CLOSE VALVE ***************** */

    if (Input_t >= SetPoint_t + 1.5 && Valve_stop == true && Valve_opening == false  && millis() > Valve_closing_time){
      valve_error = Input_t - SetPoint_t + 1.5;
      if (valve_error > 2){// if the difference is small
        Valve_stop = false; 
        Valve_closing = true;
        Valve_pause = millis() + 6000 - 2000 + (valve_error * 1000);
      digitalWrite(RelayPinOpen, HIGH); 
      digitalWrite(RelayPinClose, LOW); 
      }else{
        Valve_stop = false; 
        Valve_closing = true;
        Valve_pause = millis() + 6000;
      digitalWrite(RelayPinOpen, HIGH); 
      digitalWrite(RelayPinClose, LOW); 
      }
    }
   
  }

alvydas001, I would ask you if you can to post your code, so that we beginners can correctly understand and apply learned. Greetings :slight_smile:

of course, but all my comments Lithuanian language :blush:.
P. S. I'm really not a very good programmer...

OOoooo big thank you, language is not a problem,
There is a always google translate :slight_smile:

hi Yovca,

I used tmp36gz for temperature sensing, and this schematic for buttons (2nd pic):

all timings can be set with the predefined variables. easy to find the right one, just check the comments

Thanks, emzeperx :slight_smile: