Flow Meter and couting pulses

Hello Everyone,

I am fairly new to the arduino world i have some very basic skills and understanding of how it all works. basically i am creating a fluid dispatch system for a food preservative. this is for a school project. my idea is to use the arduino as the controller and have it read and count pulses that will keep track of how much fluid has been pumped. i want to be able to push start and the system pumps until a value is met.

what i am having trouble with is how would i write code for the flow meter? would it be some sort of count++ code that has a value of say 1000 pulses and once it is met it resets to 0 and writes the pump motor pin low? please help me as i am in the dark on this.

That sounds like a reasonable approach. You would need some code to detect the button press that starts the whole process. The state change detection shows how to do this. When the button is pressed, you would set the counter to the number of pulses corresponding to the amount you wanted to dispense, and start the pump.

You would also use the same approach to read the meter and detect when a pulse has occurred and decrement the count remaining. When the count remaining is less than one, stop the pump.

You might think about what you want to happen if somebody pushes the button again while it is dispensing. Perhaps you want to ignore subsequent button presses until the current cycle has complete i.e. the count remaining is less than one. Do you want to have a way to abort the cycle after it has started?

yes, i would like to have a stop function as well while it is pumping and i would like to be able to ignore the additional start signals. i know adding those may be sort of complex for the level i am at. so for now i would like to be able to have a digital input basically start the pump and have a counter turn off the pump once the desired pulses on a digital input are met. what would the code look like or what kind of code would it be. for example my start logic would look like...

int Start = 2;
int PumpRelay = 13;

void setup ()

{
  pinMode(Start, INPUT);
  pinMode(PumpRelay, OUTPUT); 
}

void loop ()

{
  if (digitalRead(Start) == HIGH)
    {
      digitalWrite(PumpRelay, HIGH);
    }
    else
    {
      digitalWrite(PumpRelay, LOW);
    }
}

so it is very basic, but i would like to incorprate the flow meter pulses in there somehow to shut off the pump.

Look at the state change detection example sketch I mentioned in my previous post.

Food preservative is not sold by number of pulses. It's sold by fluid volume. Do you have the pulses per liter (or fraction thereof) spec for the pump ?

raschemmel: Food preservative is not sold by number of pulses. It's sold by fluid volume. Do you have the pulses per liter (or fraction thereof) spec for the pump ?

raschemmel, you are correct. but.. i am just trying to figure out how to simply count my pulses. the meter i am going to use is a meter from adafruit. it gives 1 pulse for every 2.25 mililiters. so if i am looking for 1 liter of fluid i will need rougly 445 pulses.

once i have that part down then i can adjust to give me an accurate measurement. i will be using solenoid actuated valves to also stop the flow as well.

PeterH: Look at the state change detection example sketch I mentioned in my previous post.

Peter,

i will look at some examples. if i have any questions i will let you know.

guys, this is some code i have come up with for now still working on the kinks. please let me know if i am on to something and if you guys notice any issues. as of right now the start button would need to be a maintained button rather than a momentary button.. let me know thanks!

const int startPin = 2;          //Start button is assigned to this pin.
const int pumpRelay = 13;        //The relay coil is assigned to this pin.
const int valveRelay = 12;       //The Valve relay coil is assigned to this pin.
const int flowMeterSignal = 3;  //flow meter signal input.

int flowMeterCounter = 455;  //This is the number of pulses per liter.  (aproximately)
int flowMeterState = 0;      //Current state of flow meter.
int lastFlowMeterState = 0;  //Previous state of flow meter.
boolean flowMeterBit = HIGH; //flow meter bit.

void setup ()

{
  pinMode(startPin, INPUT);                  //initializing the start button as a input.
  pinMode(pumpRelay, OUTPUT);             //initializing the pump relay as a output.
  pinMode(valveRelay, OUTPUT);            //initializing the valve relay as a output.
  pinMode(flowMeterSignal, INPUT);        //initializing the flow meter signal as an input.
  Serial.begin(9600);                     // initialize serial communication:
  
}

void loop ()

{
  if (digitalRead(startPin) == HIGH)        //start of the pumping process.
    {
      flowMeterState = flowMeterSignal;           //read the current state of the flow meter
          digitalWrite(pumpRelay, HIGH);          //starts the pump.
          digitalWrite(valveRelay, HIGH);          //opens the valve
          
        if (flowMeterState != lastFlowMeterState)  //if the flow meter is different from previous state decade by 1
           {
             if (flowMeterState == HIGH)           
             flowMeterCounter--;                    //this is where your subtract 1 pulse 
             Serial.println("Pumping");
             Serial.print("number of pulses left:   ");
             Serial.println(flowMeterCounter);
           }
              else
              {
                digitalWrite(pumpRelay, LOW);        //makes sure the pump stops
                digitalWrite(valveRelay, LOW);       //closes the valves
                Serial.println("Not pumping.");
              }
    }
    lastFlowMeterState = flowMeterState;          //save the last pulse as the new pulse for next run.
}

Try using the hash tag button "#" to the left of the quote button. Click MODIFY, highlight code, click "#" button, click SAVE.

as of right now the start button would need to be a maintained button rather than a momentary button.

Bullshit. You've been told at least twice to look at the state change detection example. It's time you actually DID that.

PaulS:

as of right now the start button would need to be a maintained button rather than a momentary button.

Bullshit. You've been told at least twice to look at the state change detection example. It's time you actually DID that.

Paul,

I don't know if you read the code I understand it wasn't formatted correctly when inserting into the thread my mistake. If you look at it now you WILL see that I used the change state detection code in there. The identical one from the IDE examples. I may have miscommunicated when I said that about the start button. The reason I said it's momentary right now is because the start button logic is not saving is previous bit to hold the change state logic true. So once I depress start it is no longer true stopping that function. Needless to say I did use that change state example. I am new to this so I'm sorry for what seems to be ignorance to you is confusion to me..

If you look at it now you WILL see that I used the change state detection code in there.

No, you didn't:

  if (digitalRead(startPin) == HIGH)        //start of the pumping process.

Okay.. I promise im trying to understand where you're coming from , but, once that line of code you highlighted is true the following code is beneath is the change state detection

  {
      flowMeterState = flowMeterSignal;           //read the current state of the flow meter
          digitalWrite(pumpRelay, HIGH);          //starts the pump.
          digitalWrite(valveRelay, HIGH);          //opens the valve
          
        if (flowMeterState != lastFlowMeterState)  //if the flow meter is different from previous state decade by 1
           {
             if (flowMeterState == HIGH)           
             flowMeterCounter--;                    //this is where your subtract 1 pulse 
             Serial.println("Pumping");
             Serial.print("number of pulses left:   ");
             Serial.println(flowMeterCounter);

the only thing i did differently, which is because its a trial by error thing for me and where you may say im doing it wrong, which is okay. is i have the pump and the valve turn on just before it compares the last state of the flow meter to detect a change. i wanted to maybe get fluid moving for it to notice the change. i may be wrong there, that i don't know. Once it see theres a change is down counts from the 455. Where your saying im not using that state change detection, that is my start for the whole process, if that is wrong and i removed is as soon as the controller is powered it would run through its cycle. i want to be able to control the start that is why that code is there.

but, once that line of code you highlighted is true the following code is beneath is the change state detection

You should be doing NOTHING until you determine that a state change occurred, and that that the change is TO pressed.

And, I really do mean NOTHING!

PaulS:

but, once that line of code you highlighted is true the following code is beneath is the change state detection

You should be doing NOTHING until you determine that a state change occurred, and that that the change is TO pressed.

And, I really do mean NOTHING!

Paul,

I understand. I will revise the program and set up the system and begin testing it. i am waiting for some parts so it may be some time. i appreciate your input. i will let you guys know if i have any further questions.