Four way valve servo motor control

I want to make the management of heating systems Four way valve with Arduino. Valve as this- Четырехходовые смесительные клапаны купить в Москве | Комфорт-Эко, a servo drive, as in this picture:
http://www.komfort-eco.ru/files/catalog/rubs/imgs/37/kat10_003.jpg 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 ...

Pictures are fun to look at but tedious to download and not much use for programming. Do you have a link to the specifications for the controller?

Also, if you already have some part-working code post that. (In code tags please). And a drawing of how you have it connected to the Arduino and to its power supply. (A photo of a clear pencil drawing will do).

...R

This is my Skech and connection diagram

valve.ino (4.67 KB)

Most of the time people here don't bite. However we are not going to spend hours trying to figure out your problem. You need to give as much information as possible so that someone here can make a useful suggestion after a few minutes studying your problem.

You need to describe how the controller is meant to work (do you not have a link to the product datasheet?) and what is actually happening when you try your code.

I'm lazy and I'm not going to wade through your code (and why no show it directly in your post) as it has lots of stuff about temperatures that don't have anything to do with making the control move the valve. Can you write a short demo sketch that does nothing but move the valve to its various positions?

When you have that working properly you can start to integrate the movement with temperature sensing.

...R

You are right. I began to study the PID algorithm ...
Valve documentation only Czech-http://www.ktr-adex.cz/komex/mk_cn.pdf
The actuator has a rear button. Closing takes 150 seconds .
Servo drives closing without temperature measurement program is simple:

    if (Valve_stop == true && Valve_opening == false){
      Valve_stop = false; // the valve is already moving
      Valve_closing = true; // indicates that the valve is closing already
      digitalWrite(Relay_Valve_close, LOW); // signal to close the valve

The goal is: the valve at the input temperature varies from 30 to 95 degrees C. Output needed to maintain a constant temperature of 40 degrees C.

Are you saying that "digitalWrite(Relay_Valve_close, LOW);" successfully closes the valve and something similar opens the valve? (Leave out all the conditional statements for the moment).

So the problem is not making the valve open and close but how to use the ability to open/close the valve to control the temperature?

Can the valve be moved to intermediate positions? If so can you do that successfully?

Is your goal to keep the outlet water temperature constant? Without bothering with how it might be coded, is that actually possible? It seems to me that if the valve is closed you have cold water and if it's open you have hot water with nothing in between - unless you can set the valve to intermediate positions.

...R

"digitalWrite (Relay_Valve_close, LOW)" successfully closes the valve after 150 seconds. "digitalWrite (Relay_Valve_open, LOW)" - Opens after 150 seconds. In what position is the valve can be found in the calculation of the opening / closing times. But after 100 openings / closings it will be a big error.

The valve must operate at an intermediate position. Situation complicates finding the temperature change, changes very slowly.

I'll try 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);
}

}

I don't know if your code is right or wrong because I am confused by the various conditional statements and I can't see the essentials of how to control the valve.

It seems to me, from your description, that you only have two options - to send a "close" signal or to send an "open" signal. You haven't said what happens if you remove the signal after a period of time - will the valve stay where it is or will it continue to move to the end of its movement? And you haven't said what happens if you supply an "open" and "close" signal at the same time - perhaps that would let the smoke escape?.

If there is no inbuilt system for setting the valve to a required position and if (as you say) after several movements it is impossible to know exactly where it is pointing then I think you will need to add some parts to enable you to detect the position. One option might be to drive a potentiometer with the valve/motor spindle and use the pot to produce a position related voltage. This is how hobby servos work. However it would be very strange if there is not an inbuilt positioning system unless you are trying to use the valve for something that the designers did not envisage.

If this was my project my first objective would be to learn how to control the position of the valve without any reference to temperatures. I would be trying to have my code as short and simple as I possibly could.

...R

Valve does not have a positioning mechanism. What would the positioning opportunity? The valve position will not provide an output temperature. If the signal LOW to HIGH I change this valve will stop at an intermediate position.
Valve position knowing nothing will not help. I'll try to adjust it according to the PID algorithm for measuring the output of the temperature.

  1. The first thing is to know if the valve is adequate for control. The way it operates is crucial to know. Judging from your sketch control seems imposible. However from the image of the valve there seems to be a temperature "dial" which is encouraging. In fact it could hav a mechanical thermostat inside which works just as a shower blender or similar.

  2. Pid is not a digital output algoritm (open/close). It produces a setpoint value for a control variable. In your case the angle of the valve spindle. If the temperature is wrong the pid will give a value of what the angle should be and consequently how open the valve should be.

If the valve has an internal thermostatic function your pid would control the setpoint for that thermostat by adjusting the valves handle using the servo. That means that you would give the servobthe orderbto go to a specific position in a repeatable way. Either by sensing it by the arduinon or if it is a proper servo giving it an order to go to a specific position. In the latter case the servo senses its own position.

If the valve does not have an internal thermostat the controling will essentially work the same but with faster response.

If you can only give the signals open, close and stop you still could use the pid output via a virtual valve position. Since it takes 150 s for a full stroke partial strokes could be made by using a shorter increment. You would then translate the pid output to a new value for your virtual position value. This value should be compared to the previous virtual value and you should from that be able to calculate if a open signal or a close signal should be given and for how long. Given the stroke time of the valve i think the control will be slowand you should not call the pid until each movement of the valve has been completed or you would have to make adjustments by calculations. It could work but seems not very efficient.

alvydas001:
Valve does not have a positioning mechanism. What would the positioning opportunity? The valve position will not provide an output temperature. If the signal LOW to HIGH I change this valve will stop at an intermediate position.
Valve position knowing nothing will not help. I'll try to adjust it according to the PID algorithm for measuring the output of the temperature.

I'm sorry but this does not make sense to me.

Does "Valve does not have a positioning mechanism" mean that the control servo has no mechanism to set the valve to an intermediate position?

I have no idea what this means "What would the positioning opportunity?"

This "The valve position will not provide an output temperature" seems to me to mean that you do not get an intermediate output temperature when the valve is at an intermediate position? If so. what do you get?

I presume this means that you can stop the valve at any intermediate position "If the signal LOW to HIGH I change this valve will stop at an intermediate position." But the words I quoted in my previous paragraph imply that this is not useful.

I don't understand why you say this "Valve position knowing nothing will not help". Is it because intermediate positions do not give intermediate temperatures?

I think you need to tell us in detail what the valve does if it is controlled by hand without any electronics.

...R

Sorry, my English is really bad...

Robin2:
Does "Valve does not have a positioning mechanism" mean that the control servo has no mechanism to set the valve to an intermediate position?

The valve moves from the start to the end of 150 seconds. During that time, I can stop valve servo motor. This will be an intermediate position.

Robin2:
I have no idea what this means "What would the positioning opportunity?"

Knowledge of valve position does not guarantee the right temperature.

Robin2:
This "The valve position will not provide an output temperature" seems to me to mean that you do not get an intermediate output temperature when the valve is at an intermediate position? If so. what do you get?

Do I know or do not know the position of the valve, still need to measure the temperature
Because of inertia, the correct temperature is measured with a time delay of up to 10-15 seconds.

Robin2:
I presume this means that you can stop the valve at any intermediate position "If the signal LOW to HIGH I change this valve will stop at an intermediate position." But the words I quoted in my previous paragraph imply that this is not useful.

// START closing the valve
      digitalWrite(Relay_Valve_close, LOW); // START closing the valve
      digitalWrite(Relay_Valve_open, HIGH); // STOP opening the valve
// start opening valve servo
      digitalWrite(Relay_Valve_close, HIGH); // STOP closing the valve
      digitalWrite(Relay_Valve_open, LOW); // START opening the valve
// SLEEPING valve servo
      digitalWrite(Relay_Valve_close, HIGH); // STOP closing the valve
      digitalWrite(Relay_Valve_open, HIGH); // STOP opening the valve

Robin2:
I don't understand why you say this "Valve position knowing nothing will not help". Is it because intermediate positions do not give intermediate temperatures?

Yes, temperature is independent of the position or the position of the valve is independent of temperature
I think you need to tell us in detail what the valve does if it is controlled by hand without any electronics.

alvydas001:
Knowledge of valve position does not guarantee the right temperature.

Robin2:
This "The valve position will not provide an output temperature" seems to me to mean that you do not get an intermediate output temperature when the valve is at an intermediate position? If so. what do you get?

Do I know or do not know the position of the valve, still need to measure the temperature
Because of inertia, the correct temperature is measured with a time delay of up to 10-15 seconds.

Yes, temperature is independent of the position or the position of the valve is independent of temperature

I think you need to tell us in detail what the valve does if it is controlled by hand without any electronics.

I don't think the problem is your poor english - it seems perfectly adequate.

It's a pity you didn't answer my last question (the last piece in bold above).

@Hasseklas asked earlier if the valve has an internal thermostat and you didn't answer his question. That might account for the delay of 10-15 seconds that you mention. If the mixing is just done by adjusting flows like a kitchen tap (and if there is already hot water at the valve) I would expect the new temperature to occur much quicker than that.

If the valve includes a thermostat then all you need to do is figure out the valve angles for the appropriate temperatures.

If the valve does not include a thermostat AND if it really takes 10-15 seconds for the changed temperature to occur then your program will have to wait that long before measuring the effect of each adjustment.

The reason I included the first part quoted above and the first part in bold is because I am still unclear whether the position of the valve affects the temperature. I did not mean, in my question, whether the position of the valve signifies a precise temperature - just whether the water is hotter at one angle compared with another angle - I would be surprised if it is not.

I have the feeling you are trying to run before you can walk by worrying about the precise temperature before you have a good understanding of how the valve works.

...R

you dont need the position of the valve
when valvetime=setpoint-reading C open valve for valvetimekonstant like 1000 ms) second.
That is the P
if ivalvetime= ivalvetime
Ifactor +valvetime*9100-ifactor)
this is the I
it means when the valve is still not in position the valve will get more opentime.
for alarm put a maxtimer in if valve still needs opening after 1 hour give alarm.

My valve works in a heating system, as in this diagram:

If multiple operations on the valve leave you unsure how it is positioned, perhaps a simpler algorithm than PID is called for. Is there a problem if you try to open the valve more when it's already fully open?

If not, at startup, close the valve, then open it half way. Wait for the temp to stabilize. Then, if it's too hot, close the valve a bit. If too cold, open it a bit. Wait and try again.

You'll need a dead zone around the setpoint so that you're not constantly tweaking the valve position. You may need some fixed delay after a change before you're satisfied that it has taken effect too.

I like the PID and virtual valve position idea, but if you don't really know where the valve is, maybe simpler is best.

wildbill:
If multiple operations on the valve leave you unsure how it is positioned, perhaps a simpler algorithm than PID is called for. Is there a problem if you try to open the valve more when it's already fully open?

valve servo have end moving protection.

wildbill:
If not, at startup, close the valve, then open it half way. Wait for the temp to stabilize. Then, if it's too hot, close the valve a bit. If too cold, open it a bit. Wait and try again.

You'll need a dead zone around the setpoint so that you're not constantly tweaking the valve position. You may need some fixed delay after a change before you're satisfied that it has taken effect too.

by this algorithm output temperature varies from 33-34 degrees to 46-47 degrees, if the setpoint - 40.

by this algorithm output temperature varies from 33-34 degrees to 46-47 degrees, if the setpoint - 40.

Do you think that's because the algorithm is too basic, or could it be that the inaccuracy of the servo movement is hurting you?

I'd be interested to measure the input temperatures too - presumably, there's a need to compensate for variation there too. PID does seem to be your answer, I just can't see how to do it well unless you know where the valve is.

Could you perhaps, as suggested, keep track of where you think you are and periodically, reset the valve to a known position? i.e. move to fully open or fully closed whichever is closest and then back to your desired position.

alvydas001:
by this algorithm output temperature varies from 33-34 degrees to 46-47 degrees, if the setpoint - 40.

If you had said this earlier it would have saved me wasting a lot of time (this is NOT an english language problem).

Are you allowing sufficient time for the temperature to stabilize before measuring it?

I think you said earlier that the position of the valve does not guarantee a particular temperature. I think you need to investigate why this is the case. Maybe you also need to sense the input temperatures? Is it possible that moving the valve to increase the temperature sometimes causes the boiler to start up and increase the incoming temperature?

You might consider an algorithm which moves the valve only a few degrees (much less than what you think is needed to correct the temperature) and check the resulting temperature after each of these small movements before deciding if more movement is needed.

...R