pulse multiplier NEED WISDOM!!

So i have a liquid flow meter based on a no-voltage contact that signals once per revolution of an internal turbine… it sends signals to a chemical pump that reads its pulse and pumps chemical relative to the water passing…

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 flow meter or pump so i decided to solve the problem with my Arduino…

i have some code that works great for what im doing but i need more functionality. here is what 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 and adjust the number it divides the time between pulses with.

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…

I need some direction on what i need to do. what will my sketch look like?

I would like to use the keypad on the LCD shield to adjust the pulse rate. lets say 100 to -100. just in case i need less frequent pulses.

Hi,

I think I understand, the chemical is dispensed a fixed amount at a time. So one pulse from the flow meter injects a unit of chemical.

If you use your solution, you will have to recal the injection system to 1/10 the dose, otherwise you will be overdosing x10.

A higher resolution flow meter is really the proper solution.

Because you are mixing in the water flow and not in a tank the dosing system has to be very dynamic.

Tom..... :)

Yes this is true, but the pump has an adjustable pulse setting.

0.01560mL/PLS-300mL/PLS ` so i could reduce the chemical output per pulse on the pump and raise the frequency of pulses from the flow meter and get a more even mix of chemical.

the code i provided works perfect for what i need to do, but like i said i need more functionality out of it. how would i use an led display to tell me whats going on, how would i adjust the multiplied pulse rate and how would i start and stop the unit?

The flow meter is just a dry contact.. A push button would do the same. The code reads how long the flow meter is low and outputs high 10 times faster.

TomGeorge: Hi,

I think I understand, the chemical is dispensed a fixed amount at a time. So one pulse from the flow meter injects a unit of chemical.

If you use your solution, you will have to recal the injection system to 1/10 the dose, otherwise you will be overdosing x10.

A higher resolution flow meter is really the proper solution.

Because you are mixing in the water flow and not in a tank the dosing system has to be very dynamic.

Tom..... :)

yes that is true.. but a new flow meter wouldn't be anywhere as fun as solving it with an Arduino :D