# square wave signal flow rate sensor

I just got a flow rate sensor and it says to get the reading: "The output signal is a square wave signal, whose frequency varies linearly with flow rate".

What does this mean?

Here is the product sheet: http://www.gemssensors.com/uploadedFiles/Literature/Product_PDFs/FT-330.pdf

Thanks for the help, Kyle

It means to read the flow rate you will have to interface the signal to a digital input pin and measure the frequency of the signal to then determine the flow rate. The datasheet shows the relationship for two different size flow meters:

P/N Thread Flow Range Pulses/GAL. Frequency (Hz) 226000 3/8 NPT 0.2-2 GPM 10200 34-343 226100 3/8 NPT 0.4-4 GPM ———- 28-340

So if you measure the frequency of the signal you can then correlated it to a specific flow rate at that time.

You will also have to decide if you just want to just know flow rate at any given time, or if you also want to keep track of total gallons flowed over a given period, that is a so called flow totalizer.

Lefty

How do you measure the frequency of the signal with the arduino? Is that PWM?

No not PWM. There have been posting on how to write a frequency measurement sketch and even some software libraries posted to help make it easier to intergrate into your sketch. I haven't yet needed to write such a function so can't really recommend a 'best method".

Perhaps if you could explain what all your Arduino needs to accomplish, it would help with ideas and suggestions?

Lefty

All I am trying to do is to keep track of the gallons that flow over a given time and read out the current gallons per minute used and the total gallons used to a LCD screen.

All I really need to know is how to measure frequency, everything else I know how to do.

using micros is kinda redundant. theres already a function called pulseIn that measures the time between pulses, high or low.

With using pulseIn is the recording interval fast enough so that I the accuracy of gallons per minute is not messed up over time?

ok, so it looks like you need two things. count the number of pulses and find the flow rate. what you would need is an interrupt. an interrupt will run a small piece of code when your sensor outputs a high, a low, or a high to low, or low to high reading. this is done automatically.

the small piece of code should only update a counter and should be as small as possible.

when you want to see how much has flowed, you would divide the number of pulses by the amount of pulses per gallon

"10200" is what the previous posts say.

to find the instantaneous flow, find the period of the pulses. you should do this in the main loop as it is not as time sensitive. find the period, then find the number of pulses per whatever unit of time that would be (hertz). once you have that you can use it with the number of pulses per gallon to find the flow rate.

weirdo557: using micros is kinda redundant. theres already a function called pulseIn that measures the time between pulses, high or low.

Indeed, i hadn't used it before, it saves writing some lines, thank you !

One thing, Pulsein() seems to measure the time a pin is High or Low, not... High and Low.

From the reference :

Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, pulseIn() waits for the pin to go HIGH, starts timing, then waits for the pin to go LOW and stops timing.

To measure frequency you'll need both, so maybe you need to multiply the pulsein() value by two.

I guess both methods are more then fast enough to measure. Minimum value to measure with pulsein() is 10 microseconds. In theory you could measure up to 50.000Hz, about 150 times as fast as the max output of the sensors.

BTW, Any idea how the sensors behave below 0.2 or 0.4 GPM ? it's 288/576 Gallons a day...

Don't know if this will help, but this sensor is basically the same I think. I'm currently using one of these:

http://www.seeedstudio.com/forum/viewtopic.php?f=4&t=989&p=3632#p3632

This is how I have written the sketch so far...

``````int pin = 7;
unsigned int duration;
int pulsesEqualToGallon = 4994; //Found this in an archive datasheet
int pulses = 0;
float totalGallons = 0;
float oldTotalGallons;

void setup()
{
pinMode(pin, INPUT);
Serial.begin(9600);
Serial.println("Total gallons \n 0");
}

void loop()
{
duration = pulseIn(pin, HIGH);
//Count if duration is greater than 0
if (duration > 0){
pulses++;
oldTotalGallons = totalGallons;
//Check if pulses are greater than pulses equal to gallon
if (pulses > pulsesEqualToGallon ){
totalGallons++;
pulses = 0;
}
if (totalGallons > oldTotalGallons){
Serial.println(totalGallons);
}
}
}
``````

can pulseIn be used to measure frequency to determine output pin? i need a sketch that sets one pin high at a specific frequency and another pin high at another frequency. can anybody help?

yeah, pulse in give you your period, use that to calculate your frequency. store that calculation in a variable, then use "if" statements to compare that number to whatever number you want. if its true, make your pin high, if its not, make it low.

You could also use an interrupt based counting mechanism as I did on - http://www.arduino.cc/playground/Main/EEM12L-32AKWhMonitoring - Although my sketch was for a KWH meter the principle is identical. The advantage is that the pulses are counted "in the background" and that you can fetch the counter any time you need it.

In the sketch the number 2000 is the factor between pulses and KWH, you should replace that by 4994 (number you found)

succes

Ok thanks a lot!