Pages: [1]   Go Down
Author Topic: Flow Control on demand 1 digital input 2 digital outputs  (Read 406 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello All: Let me explain my  projects:
Firstly I'd like thank everyone who is making up this amazing project and all which is involved on it.
Im sure more than one of un know perfectly about some thing similar mine. Here I go to explain my problem.

Currently I'm using an Ardunio ONE for managing the position for 4 electric pistons, all are controlled by the same way. I'll put below an example, this code runs perfectly. but not orher similar... I'll try to explain the problem

************************************************************
int open1=3;
int close1=4;

int ReadInput1=0;

boolean StrComplete = false;
String inputString = "";         // a string to hold incoming data
boolean Sa1= false;  //Booleans StopControl Opening or closing
int V_Umbral1=0 // Value to reach
void setup() {
  // initialize serial:
  Serial.begin(9600);
  pinMode(open1, OUTPUT);
  pinMode(close1, OUTPUT);
 
  // reserve 200 bytes for the inputString:
  inputString.reserve(200);
}
void loop() {
  // print the string when a newline arrives:

    unsigned long currentMillis = millis();
    ReadInput1=analogRead(A1);
   
    if(ForChrono+500< currentMillis){   // to keep the sistem working correctly it is enough this kind frequently for checking and controlling
      Serial.println(CurrentAnalogicValue);
      ForChrono= currentMillis;
    }
    controles1();
    delay(10);
}
/*
  SerialEvent occurs whenever a new data comes in the
 hardware serial RX.  This routine is run between each
 time loop() runs, so using delay inside loop can delay
 response.  Multiple bytes of data may be available.
 */
 
void serialEvent()
{
  while (Serial.available())
  {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a "#" sentence is completed
    // so the main loop can do something about it:
      if (inChar == 35)
      {
         Splitea(inputString);
         int i=0;
        inputString="";
      }
  }
 
}


void Splitea(String Sinput){
  Serial.println(Sinput);
    int ValSend,IdMotor=0;
    String STmp="";
    int LookEnd =0 ;
    LookEnd =Sinput.indexOf("#");    // making substrings from index of the last element it doesnt existe until now any error
    STmp=Sinput.substring(LookEnd-5,LookEnd-4);
    IdMotor=STmp.toInt();
    ValSend =Sinput.substring(LookEnd-4,LookEnd).toInt();
    CheckMotorAndValue(
    ValSend);
 }


void CheckMotorAndValue(int V)
{
      V_Umbral1=V;
      Sc1=true;
}


void controles1(){ // here is compared actual value from potentioneter wich give us the position and the value to set
      // control Piston 1
     
      if (ReadInput1  > V_Umbral1 && Sc1==true){  //  sample  comparation between two values, actual and value to reach
      digitalWrite(close1, HIGH);
      digitalWrite(open1, LOW);
      Sa1 = true;
      }
     
      if (ReadInput1 < V_Umbral1 && Sc1==true && Sa1 == false){
      digitalWrite(close1, LOW);
      digitalWrite(open1, HIGH);
      Sa1 = false;
      }
     
      // combining these two bool the sistem is checking if the piston is opening or closing
      if(Sc1==true && Sa1 == true){
        if(ReadInput1 <= V_Umbral1){
          Sc1= false;
          Sa1 = false;
          digitalWrite(open1, LOW);
          digitalWrite(close1, LOW);
        } 
     
      }
       // combining these two bool the sistem is checking if the piston is opening or closing
      if(Sc1==true && Sa1 == false){
        if(ReadInput1 >= V_Umbral1){
          Sc1= false;
          Sa1 = false;
          digitalWrite(open1, LOW);
          digitalWrite(close1, LOW);
        } 
     
      } 
}

************************************************************
Also I need manage a system of water flow, trying to reach the value to set. In this project I give the frequency from Flowmeter of digital value It usually have a Konstant aboyt Pulse Per litre accurate enough.

like in the other project, I begin by comparing value from flowmeter and value to reach, and deepending on if I must up or down the flow, I set the apropiate ouput until value is reached, so turn it down.

It seems that everything is ok?? but it isn't because the system has some inertial force and for few second after the control was stopped the flow goes on getting up. The gap forces us to recalculate from the beginnig and this time we must down the flow, then turn on the apropiate output ( normally this time is for getting down the value) until the value to reach is ok, then anew after the control is stopped, few seconds after and from all presures in the circut are stabilized this time flow goes downer than we want.

As easy the control for electric piston as hard to achieve values hoped in the second project.

I have been reading about PID control, I guess is that i need, but the main problem is reaching flow that every moment i need by up and down the motorized valve. All PID control that I have seen is for example for keeping any value of temperature so for this case we only need activate an output to turn on the heater because turning it down temperature goes down on its own.

In my case i need an output for getting more value and another one for getting down it. Some thing like dual PID more or less.
Logged

Pages: [1]   Go Up
Jump to: