Need help with wiring.

what would my circuit look like for this code? using an uno btw.

#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 13
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/5;
    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();
}

Its input is a dry contact switch(two wire + -) and the output is to a chemical pump. The manual to the pump said " when using a no-voltage contact use a mechanical relay designed for an electronic circuit. Its minimum application load should be 5mA or less.

The project is for a pulse multiplier for a flow meter.. it will output the pulse to a chemical pump.
what im having trouble with is the output.. or pump input. can the arduino supply what the pump needs? Or will i need more hardware?

What kind of pump?

Unless the pump is very small (microfluidics small), with very low current, you'll need a power supply for the pump, and no matter what, it sounds like you'll need a relay or mosfet.

Since you haven't posted the specs on the hardware you're using, we can't really give you any further pointers.

http://www.iwakiamerica.com/Literature/IX%20Instruction%20Manual%20North%20America%20T770-2.pdf

This is what im working with.

But i think i see whats needed..... I could get a relay that is operated by pin 13 and GND... and the pump has a 12VDC output so i plan to use that to power the Arduino.

This pump with programmable control unit is very flexible, many options and configurable output types, alarms, etc.
Not really sure what you need the Arduino for. What do you want the Arduino to do?

I think you need to use something like this circuit with the PWM open-collector input on that pump:


Effectively, that does a level translation of the PWM 0/5 volt swing to a 0/12 volt swing for the control of the pump (see also page 73 note 2 in that manual you posted).

You could use a relay to basically switch 12 volts to that pin, but there really isn't any need, depending on your reliability requirements.

The particular flow meter im using has a very slow pulse rate. it pulses every 1-3 min. The pump will read the pulse and dump the dose its set at in the first 10 seconds then let untreated water pass wile the turbine in the flow meter finishes its rotation. So i guess you could say its more for the flow meter..
arduino receives pulses from it. measures the distance between the last two previously recorded pulses divides by 10 and outputs the higher frequency to the pump....

Its a work in progress :smiley:
In way over my head.

This should be pretty straightforward. If you look at that data sheet on page 30, it shows how to use a transistor as the switch in the top left diagram. The attached picture shows how you would connect it to an Arduino. The left side are the Arduino connections, and the right side are the pump connections.

The Arduino output pin goes through a 270 Ohm resistor and to the base of the 2N2222 transistor.
The pump pin 1 connects to the collector of the 2N2222 transistor.
The Arduino ground, pump pin 4, and emitter of the transistor are all connected together.

When the Arduino output is high, current flows through the resistor to the base of the transistor, turning it on, which connects pin 1 and 4 of the pump connector, supplying the pulse to the pump. When the Arduino output is low, no current flows through the resistor, the transistor is off, and the pump does not get a pulse.

pump.PNG

The pump will read the pulse and dump the dose its set at in the first 10 seconds then let untreated water pass wile the turbine in the flow meter finishes its rotation. So i guess you could say its more for the flow meter..
arduino receives pulses from it. measures the distance between the last two previously recorded pulses divides by 10 and outputs the higher frequency to the pump....

Looks like the controller is already doing something similar ...

The particular flow meter im using has a very slow pulse rate. it pulses every 1-3 min.

I'm quite sure that the programmed mL/pulse has been set to a high value.
You have a huge range available ... the lower you program the mL/pulse to be, the higher the pulse frequency will be for a given flowrate.

dlloyd:
You have a huge range available ... the lower you program the mL/pulse to be, the higher the pulse frequency will be for a given flowrate.

But that's for the pump, which is not the issue. Yes, you can control how much volume is delivered in one pulse, but that's still the volume for one pulse.

The problem is that the flow sensor that would be driving the pump outputs the pulses too slowly:

mumbleelbmum:
The particular flow meter im using has a very slow pulse rate. it pulses every 1-3 min. The pump will read the pulse and dump the dose its set at in the first 10 seconds then let untreated water pass wile the turbine in the flow meter finishes its rotation.

To rephrase the OP's problem statement: the issue is that the pulses come in so slowly that a lot of water passes through with no treatment. A pulse happens, the water passing by at that moment gets a slug of chemical, then the water that passes by for the next several minutes gets nothing. If you turn down the mL/Pulse value, you will just get less chemical per pulse, but you will still get long periods between pulses that get no chemical.

Right now, it gives a large dose infrequently. What is needed is a series of smaller doses more frequently. To do that, the pulse rate out of the flow sensor needs to be increased. Once that's done, the pump's dose per pulse can be adjusted down. But the number of pulses that the sensor reports per volume needs to be increased first.

OK, got it. I thought the flow meter was built into the pump.

The particular flow meter im using has a very slow pulse rate. it pulses every 1-3 min.

Can the flow meter be replaced with a unit with higher pulse rate (lower volme/pulse)?
Otherwise, what is the model or part number of this flow meter?

The flow meter is a Master Meter Model No. MM3. In my particular project its not very cost effective to replace the flow meter.

the sensor in the flow meter is a no-voltage contact. that's all i can find on it. the part number is rubbed off.

ShapeShifter:
This should be pretty straightforward. If you look at that data sheet on page 30, it shows how to use a transistor as the switch in the top left diagram. The attached picture shows how you would connect it to an Arduino. The left side are the Arduino connections, and the right side are the pump connections.

The Arduino output pin goes through a 270 Ohm resistor and to the base of the 2N2222 transistor.
The pump pin 1 connects to the collector of the 2N2222 transistor.
The Arduino ground, pump pin 4, and emitter of the transistor are all connected together.

When the Arduino output is high, current flows through the resistor to the base of the transistor, turning it on, which connects pin 1 and 4 of the pump connector, supplying the pulse to the pump. When the Arduino output is low, no current flows through the resistor, the transistor is off, and the pump does not get a pulse.

would you have a part number or place where i can get this resistor and transistor?

Looks like the registers are replaceable and you can get register output option of 0.1 gal per pulse. Your existing register is probably 1 gal or even 10 gal per pulse. This would meet your x10 requirement (possibly x100).
http://www.mastermeter.com/images/documents/Electrical_Output_Register_IP68_OCT_2013_1322721027_6576.pdf

mumbleelbmum:
would you have a part number or place where i can get this resistor and transistor?

They are very common parts available from MANY sources. The resistor value is not critical, anything in the 220 to 1000 Ohm range should work just the same.

Here is one source: 2N2222 Transitor and 330 Ohm resistor

With just a little bit of searching, I'm sure you can find better prices. If you have a local electronics part store (like a Radio Shack) you can also get them locally. They are among the most common parts.