counting pulses

I have just Purchased arduino uno I need it to count the pulses from a a flow meter when the count reaches lest say 200 I need it to out put 5v ….is this easy to do if so can some one point me in the write direction as I am new to all this

this is the flow meter

if you can confirm it would take input from this flow meter i will order one today :

Flow Meter DBS 026

Suitablity Beer,wine,soft drinks,spirits and water

Operating Voltages 5 volt DC + or ? 1 volt
12 volt DC + or ? 2 volts

Typical Current Drain 5 volt version 10 mA,(12 volt version 15 mA available on request)

Signal Square wave,min 90% of supply voltage

Flow Rate Region of 1 litre to 25 litres per minute

Typical Signal 500 pulses per litre,800 pulses with fast turbine

Pipe Fittings John Guest Female Adaptors 3/8
Material Polycarbonate outer case,acetal resin end bearings,rotor,end fittings
Stainless steel rotor spindle (all approved ?Food Quality?)

Supplied with 2m connecting cable, plug,boot screw, John Guest fittings, High Speed Turbine.

Manufactured and designed by Drinkbrook

thanks

dave

For that you need to setup one of the Timer/Counters (0,1) as a counter and connect the output of your flow meter to the Timer/Counter input.

T0 is in PD4.
T1 is in PD5.

Check this old forum entry http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210337292

Or something like this:

int outputPin = 5;
int inputPin = 6;

int maxCount = 200;

void setup()
{
  pinMode(outputPin, OUTPUT);
  pinMode(inputPin, INPUT);
}

void loop()
{
   static int lastState = 0;
   static int count = 0;
   int newState = digitalRead(inputPin);
   if (newState != lastState)
   {
     count ++;
     lastState = newState;
     if (count > maxCount * 2)
     {
       digitalWrite(outputPin, HIGH);
     }
   }
}

Yet another possibility is to connect the sensor to a pin that supports interrupts (pin 2 or 3 on the Uno), attach an interrupt service routine to the corresponding interrupt using attachInterrupt(), and increment a counter in the service routine. Then in loop() you first clear the counter, then wait until the counter reaches 200, then set the required output high.

However, if you don't have anything else that the Arduino needs to do while counting pulses, then the soultion suggested by Si is a little simpler and leaves the interrupt free for something else.

Thanks Simon ...looks like i have cracked it Thanks to you …. this is what i am working on ........ Self Service Bar …… this is how it works …… you come into the pub pay for 8 pints + deposit (for box) you are given a small box with 8 led’s on it and a button when you press the button at first all led’s will light up indicating you have 8 full pints left you plug “your box” into a bar with a lager pump on and pull your first pint then unplug the box and keep it with them if you press the button again one of the lights will have gone out second pint two lights out and so on when you have pulled 8 pints the box not allow any more lager to be pulled until it is reset ……………..in the box is the arduino and a rechargeable 9v battery …… this is the code that works it ………….....THE PROBLEM now how do I reset the program without opening the box and pressing the button is there any way a can digital input to one of the pins .if so can any one tell me the code to do this thanks ………….this is my code

int outputPin = 13;//names pins
int inputPin =10;
int fullPin =8;
int aPin = 1;
int bPin = 2;
int cPin = 3;
int dPin = 4;
int ePin = 5;
int fPin = 6;
int gPin = 7;
int maxCount =1600;//number of pulse's befor end

void setup()
{

digitalWrite (aPin, HIGH);//turns all led's on
digitalWrite (bPin, HIGH);
digitalWrite (cPin, HIGH);
digitalWrite (dPin, HIGH);
digitalWrite (ePin, HIGH);
digitalWrite (fPin, HIGH);
digitalWrite (gPin, HIGH);
digitalWrite (fullPin, HIGH);
pinMode(aPin,OUTPUT);//sets state of pin's
pinMode(bPin,OUTPUT);
pinMode(cPin,OUTPUT);
pinMode(dPin,OUTPUT);
pinMode(ePin,OUTPUT);
pinMode(fPin,OUTPUT);
pinMode(fullPin,OUTPUT);
pinMode(gPin,OUTPUT);
pinMode(outputPin,OUTPUT);
pinMode(inputPin, INPUT);//make's pin 10 input pin

}

void loop()
{
static int lastState = 0;
static int count = 0;
int newState = digitalRead(inputPin);

if (count >1)

{
digitalWrite (fullPin, LOW);//turns first light of when pulse input
}

if (count >200)

{
digitalWrite (aPin, LOW);//turns next light off
}

if (count >400)

{
digitalWrite (bPin, LOW);
}

if (count >600)

{
digitalWrite (cPin, LOW);
}

if (count >800)

{
digitalWrite (dPin, LOW);
}

if (count >1000)

{
digitalWrite (ePin, LOW);
}

if (count >1200)

{
digitalWrite (fPin, LOW);
}
if (count >1400)

{
digitalWrite (gPin, LOW);
}

if (newState != lastState)

{
count ++;//adds one to count
lastState = newState;
if (count > maxCount * 2)//when count gets to the set number sends 5v to pin 13
{
digitalWrite(outputPin, HIGH);
}
}
}

Create a reset function (probably similar to setup) and call it when a spare digital pin goes high/low?

Not that I don't think your project has merit but.... don't you think this was the sort of thing that RFID was made for? I'm thinking of something like - you show the RFID reader attached to the arduino a "admin" card then a punter card. When you do this it creates an entry for the card with along with x pints assigned to the card. As the card was thereafter presented to the reader it would deduct a pint (or whatever is drawn off). Cards could be refilled by again showing the admin card first then the card to be topped up?

or, you can connect a switch between the reset pin and GND. This will reset the Arduino.

Interesting project!

Hi Dave thanks for your comments…. that’s the first time I have looked at RFID cards i was going to use barcodes but I could not get my head around the programming required. I got a price for some one to write the software £5000 so that got put to the back of the draw very quickly …. The rfid cards look prefect for what I am doing but how easy would the programming be to do ??? bearing in mind my programming skills are very basic
Once again thanks for your interest

You might want to give some thought on how to defeat this device - people tend to be quite partial to free beer, and indeed free arduinos. It looks for example that if you can hold whatever pin 13 connects to low, you can drink free lager all day. You might also want to put a unique ID on each device and send logging data to a PC so that when someone tells you 'the device didn't work' you can check & see that actually 8 pints were just pulled when it was connected. On the free Arduino front - you probably need a program (on another arduino?) that connects to the box to ensure that there's still one in there when it is returned. It can double as a reset function too. Finally, beware of anyone carying their own arduino into the pub - they're up to no good :wink:

edit: grammar

THE PROBLEM now how do I reset the program without opening the box

No, the problem is repairing the box after the 7-pints customer tries to get back to the bar :roll_eyes:

Thanks ……. I wont be supplying a wiring diagram to anyone so it would be very hard to guess what to connect to where the only way I can see I my have a problem is if they get in the box they can press the reset button ......but I hope I can word out how to use the rfid cards. I think that’s the way to go its just knowing how to do it ……… as for them getting that pissed they cant get back to the bar.well thats easy ....... I will have to water the beer down .lol

just orderd a rfid reader lets hope i can work out how to use it :fearful: