# Adafruit Flow meter 828 Liters/min

Hello ,
I am new to arduino community and i would like to know how can i program adafruit flow meter http://www.adafruit.com/products/828 .
I want to measure the liters/min so that i know the speed of water in a pipe . From GitHub i found the code which count the total liters passing through the sensor . Does anyone has the code for measuring Q(liters/min) continuously ??

Thank you in advance !! Surely if the code you have tells you the total quantity that must be between two instants in time? (eg perhaps t0= when the sketch started, and t1= now.) I surmise (since you didn't post the code) that it keeps a total of the quantity which grows each time through loop().

You could use millis() to attach a time to each go through loop(), then you can subtract the 2x millis'es to give you a time between each quantity measurements, and hence get the flow as quantity/time.

Something like that anyway, but post the code for better help.

This is the code from GitHub :

``````/**********************************************************
This is example code for using the Adafruit liquid flow meters.

Tested and works great with the Adafruit plastic and brass meters

Connect the red wire to +5V,
the black wire to common ground
and the yellow sensor wire to pin #2

Adafruit invests time and resources providing this open source code,

All text above must be included in any redistribution
**********************************************************/
#include "LiquidCrystal.h"
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

// which pin to use for reading the sensor? can use any pin!
#define FLOWSENSORPIN 2

// count how many pulses!
volatile uint16_t pulses = 0;
// track the state of the pulse pin
volatile uint8_t lastflowpinstate;
// you can try to keep time of how long it is between pulses
volatile uint32_t lastflowratetimer = 0;
// and use that to calculate a flow rate
volatile float flowrate;
// Interrupt is called once a millisecond, looks for any pulses from the sensor!
SIGNAL(TIMER0_COMPA_vect) {

if (x == lastflowpinstate) {
lastflowratetimer++;
return; // nothing changed!
}

if (x == HIGH) {
//low to high transition!
pulses++;
}
lastflowpinstate = x;
flowrate = 1000.0;
flowrate /= lastflowratetimer;  // in hertz
lastflowratetimer = 0;
}

void useInterrupt(boolean v) {
if (v) {
// Timer0 is already used for millis() - we'll just interrupt somewhere
// in the middle and call the "Compare A" function above
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
} else {
// do not call the interrupt function COMPA anymore
TIMSK0 &= ~_BV(OCIE0A);
}
}

void setup() {
Serial.begin(9600);
Serial.print("Flow sensor test!");
lcd.begin(16, 2);

pinMode(FLOWSENSORPIN, INPUT);
digitalWrite(FLOWSENSORPIN, HIGH);
useInterrupt(true);
}

void loop()                     // run over and over again
{
lcd.setCursor(0, 0);
lcd.print("Pulses:"); lcd.print(pulses, DEC);
lcd.print(" Hz:");
lcd.print(flowrate);
//lcd.print(flowrate);
Serial.print("Freq: "); Serial.println(flowrate);
Serial.print("Pulses: "); Serial.println(pulses, DEC);

// if a plastic sensor use the following calculation
// Sensor Frequency (Hz) = 7.5 * Q (Liters/min)
// Liters = Q * time elapsed (seconds) / 60 (seconds/minute)
// Liters = (Frequency (Pulses/second) / 7.5) * time elapsed (seconds) / 60
// Liters = Pulses / (7.5 * 60)
float liters = pulses;
liters /= 7.5;
liters /= 60.0;

/*
// if a brass sensor use the following calculation
float liters = pulses;
liters /= 8.1;
liters -= 6;
liters /= 60.0;
*/
Serial.print(liters); Serial.println(" Liters");
lcd.setCursor(0, 1);
lcd.print(liters); lcd.print(" Liters        ");

delay(100);
}
******************************************************************************************
``````

Actually i can’t understand this

``````// if a plastic sensor use the following calculation
// Sensor Frequency (Hz) = 7.5 * Q (Liters/min)
// Liters = Q * time elapsed (seconds) / 60 (seconds/minute)
// Liters = (Frequency (Pulses/second) / 7.5) * time elapsed (seconds) / 60
// Liters = Pulses / (7.5 * 60)
float liters = pulses;
liters /= 7.5;
liters /= 60.0;
``````

What does the liters/=60.0; means ?

I will be grateful if you can help !

liters /= 60.0; Is a compound statement, means the same as liters = liters / 60.0;

Oh I see !! Thank you !!

So i thought that it would be easier to set a code to see if i have a flow or not ! So i came up with that :

``````#define FLOWSENSORPIN 3
int pulsecounter = 0;
int test=1;

void setup() {
Serial.begin(9600);
pinMode(FLOWSENSORPIN, INPUT);

}

void loop() {

while (test = 1){
if (pulsecounter == LOW){
Serial.print("We have flow");
Serial.print('\n');
delay(100);
}
else if (pulsecounter == HIGH ){
Serial.print("We DONT have flow");
Serial.print('\n');
delay(100);
}
delay(1000);

}
}
``````

Is it ok ? I have some trouble though because the sensor changes state very easily only by picking him up!
Any suggestions what may cause that ?