Flow Meter Pulse Multiplier?

Ok so i need some help with a pulse multiplier for a water flow meter im working with…

The problem is, that in this particular application the flow meter takes to long to signal so the pump will finish pumping the amount of chemical that is set at (Its Max Setting) in the first 10 seconds then lay dormant for 1-3 min until the flow meter finishes its rotation, letting untreated water pass the injection point as it waits.

It would be to expensive to replace the pump or flow meter so i want to solve the problem with my arduino.

my idea is to multiply the pulses from the flow meter and turn down the chemical output per pulse on the pump therefore getting a more even mixture of chemical and water at the injection point.

Here is the code i have so far…

#define INPUTMODE INPUT_PULLUP    // INPUT or INPUT_PULLUP
#define BOUNCETIME 50             // bouncing time in milliseconds

byte buttonPins[]={2};// pin numbers of all buttons
#define NUMBUTTONS (sizeof(buttonPins))

#define LED 5
long ledOnTime, ledCycleTime;
boolean ledIsOn;
unsigned long lastPulseTime, lastLEDcycleStart;


byte buttonState[NUMBUTTONS];  // array holds the actual HIGH/LOW states
byte buttonChange[NUMBUTTONS]; // array holds the state changes when button is pressed or released
enum{UNCHANGED,BUTTONUP,BUTTONDOWN};

void input(){
// read the input state and state changes of all buttons
  static unsigned long lastButtonTime; // time stamp for remembering the time when the button states were last read
  memset(buttonChange,0,sizeof(buttonChange)); // reset all old state changes
  if (millis()-lastButtonTime<BOUNCETIME) return;  // within bounce time: leave the function
  lastButtonTime=millis(); // remember the current time
  for (int i=0;i<NUMBUTTONS;i++) 
  {
    byte curState=digitalRead(buttonPins[i]);        // current button state
    if (INPUTMODE==INPUT_PULLUP) curState=!curState; // logic is inverted with INPUT_PULLUP
    if (curState!=buttonState[i])                    // state change detected
    {
      if (curState==HIGH) buttonChange[i]=BUTTONDOWN;
      else buttonChange[i]=BUTTONUP;
    }
    buttonState[i]=curState;  // save the current button state
  }
}

void debugCycleTime()
{
  Serial.print("Cycle time: ");
  Serial.print(ledCycleTime);
  Serial.print("   on time: ");
  Serial.print(ledOnTime);
  Serial.println();
}



void processing()
{
  long nowMillis=millis();
  if (buttonChange[0]==BUTTONDOWN)
  { // new pulse detected, recalculate the new ledCycleTime and ledOnTime
    ledCycleTime= (nowMillis-lastPulseTime)/10;
    ledOnTime=ledCycleTime/10;
    lastPulseTime=nowMillis;
    debugCycleTime();
  }
  if (nowMillis-lastLEDcycleStart>=ledCycleTime)
  {
    lastLEDcycleStart+=ledCycleTime;
  }
  if (nowMillis-lastLEDcycleStart<ledOnTime)
    ledIsOn=true;
  else   
    ledIsOn=false;
}

void output()
{
  if (ledIsOn)
    digitalWrite(LED,HIGH);
  else
    digitalWrite(LED,LOW);
}



void setup() {                
  Serial.begin(9600);
  for (int i=0;i<NUMBUTTONS;i++)
  {
    pinMode(buttonPins[i],INPUTMODE);
  }
  pinMode(LED, OUTPUT);     
  Serial.println("Waiting for first pulse...");
  do
  {
    input();
  } while (buttonChange[0]!=BUTTONDOWN);
  lastPulseTime=millis();
  Serial.println("Waiting for second pulse...");
  do
  {
    input();
  } while (buttonChange[0]!=BUTTONDOWN);
  long nowMillis=millis();
  ledCycleTime= (nowMillis-lastPulseTime)/10;
  ledOnTime=ledCycleTime/5;
  lastPulseTime=nowMillis;
  lastLEDcycleStart=nowMillis;
  Serial.println("System up and running!");
  debugCycleTime();
}

void loop() {
  input();
  processing();
  output();
}

So far it measures the time between the first two pulses divides it by 10 and flashes an “LED” 10 times faster… What i need to do is be able to display the data on an Adafruit RGB LCD keypad shield (in seconds) and adjust the number it divides the time between pulses with.

like -100 to 100 adjusted with the key pad on the lcd shield.

Also i need it to give 1 pulse every 10 seconds for the time it takes to read the first 2 from the flow meter And the system would need to stop after 5 min inactivity from the flow meter… as to not waste chemical…

So i guess this would be the order of things…

void setup() {

}

void loop() {
    flashLed();
    checkFmPulse();
    displayFmPulseRate();
    displayMultipliedPulseRate();
    askForPulseRatefromUser();
    getUserResponse();
    multiplyPulse();
    ReadTimeFmIsInactive();
    StopPulseIfFmIsInactive();
}

What would my code need to look like?

That may be a little confusing so maybe this will help. what i have so far works perfect. i have the flow meter hooked up to the Flow meter and pump so that confirms compatibility..

what i need is a way to control the pulse rate output from the arduino and view the data. so the functionality would be.

Flash led once every 10 seconds until the arduino reads the first 2 pulses. Check the time between the two previously recorded pulses. Display that rate in seconds on the lcd along with the default setting of 10. Start output pulses accordingly. Ask user for desired pulse rate. (-100 to 100) Receive user response through the keypad on the lcd shield. Multiply Pulse and output accordingly. Read time flow meter is inactive. If flow meter is inactive for 4 min shut down output pulses.

Can i just add to my existing code? it works perfect as far as the pulse rate gos.

The problem is, that in this particular application the flow meter takes to long to signal so the pump will finish pumping the amount of chemical that is set at (Its Max Setting) in the first 10 seconds then lay dormant for 1-3 min until the flow meter finishes its rotation, letting untreated water pass the injection point as it waits.

I think it would be more useful to explain the basic problem more clearly.

This sounds like you have a flow meter that only outputs a new reading every minute but you have a pump that only needs to run for 10 seconds. But I may well be quite wrong in my interpretation.

Please describe how the system works and what you want to happen without any reference to code.

...R

So the flow meter pulses once every 1-3 min when its hooked up to the water source. the pump is in a pulse setting that pumps relative to the input from the flow meter. The pump requires a more frequent pulse rate to pump steady or non stop. As of now the pump reads the flow meter and pumps the amount of chemical that its set at in the first 10 seconds after the pulse from the flow meter. Than waits until the turbine in the flow meter completes its rotation for another pulse. Letting untreated water pass as it waits. untreated water = bad

What i need to do is simply read the flow meter and output a more frequent pulse to the pump but still be relative to flow. I need it to display what its doing and be adjustable through the push buttons on my lcd shield.

Sounds like all you need to do is monitor the flowmeter. When you determine the pump needs to be turned on, turn it by outputting pulses to the pump, perhaps every second, every 5 seconds, whatever. When you reach whatever your pump stop criteria is (a certain number of flowmeter pulses??), stop outputting pulses to the motor, and it will turn off 10 seconds after the last pulse.

Sounds like about 10 lines of code.

Regards, Ray L.

The pulse output of the flow meter converts to a Gallons Per Hour Measurement. then you can set the pump to x amount of chemical per pulse to get an adequate dosage of chemical. so the pulse output from the arduino would still need to be relative to the flow meter so that you can dose correctly..

the code i previously provided has nothing to do with an lcd display yet. and when it refers to "button" its talking about the flow meter.

it measures time between FM pulses and divides it by 10 than outputs at that rate until it receives another pulse. Always pulsing 10 times faster than the previously recorded pulse rate. So it is still relative to flow.

byte buttonPins[]={2};// pin numbers of all buttons
#define NUMBUTTONS (sizeof(buttonPins))

This is just plain nonsense. Use an array ONLY when you have more than one item in the set.

Based on your description in Reply #3 I would use the following strategy

First, the water flow Calculate the water flow rate and save the value. This gets updated whenever a pulse arrives from the flowmeter. A single flow rate value may be unchanged for up to 3 minutes if there is no pulse within that time.

Second the dosage flow. Based on the current water flow rate instruct the pump to apply the dose in small amounts so that you have the appropriate dosage flow rate to match the water flow rate. This will NOT be based on the flow meter pulses, but on the most recent calculated flow rate There will always be a flow rate value available to work out the next dosage amount

...R

Ok that would work. what would my sketch look like? or what functions would the sketch need.. maybe a basic outline or anything would be helpful.

I found this http://www.instructables.com/id/Arduino-Bike-Speedometer/

it is an instructable for a bike speedometer.. this code would work for me but instead of MPH it would be GPH. and the sensor in the flow meter is also a reed switch. but i don't know how i would output the more frequent pulse to the pump and make the multiplication rate adjustable.

Can i modify this code to work for me? any input would be much appreciated!

Thanks.

mumbleelbmum:
Ok that would work. what would my sketch look like? or what functions would the sketch need… maybe a basic outline or anything would be helpful.

As you have another long Thread on this project I have no idea now where you are in your planning.
I’m not going to waste time answering this question unless you tell me you are interested in following this appoach.

…R

Robin2: As you have another long Thread on this project I have no idea now where you are in your planning. I'm not going to waste time answering this question unless you tell me you are interested in following this appoach.

...R

Yes i am interested! sorry about that.

Thread locked.

DO NOT CROSS-POST, CROSS-POSTING WASTES TIME.