Tutorial: Reading Water Flow rate with Water Flow Sensor

Pre-project discussion, teammates recruitment, project publishment and proposal.

Tutorial: Reading Water Flow rate with Water Flow Sensor

by makersworkbench » Sun Aug 29, 2010 2:43 pm

This is part of a project I have been working on and I thought I would share it here since there have been a few threads on how to read water flow rate in liters per hour using the Water Flow Sensor found in the Seeed Studio Depo. It uses a simple rotating wheel that pulses a hall effect sensor. By reading these pulses and implementing a little math, we can read the liquids flow rate accurate to within 3%. The threads are simple G1/2 so finding barbed ends will not be that hard. I found some at a hardware store for $1.89 each.

Image

You will need
    Seeeduino / Arduino
    Water Flow Sensor
    10K resistor

Wiring up the Water Flow Sensor is pretty simple. There are 3 wires: Black, Red, and Yellow.
    Black to the Seeeduino's ground pin
    Red to Seeeduino's 5v pin
    The yellow wire will need to be connected to a 10k pull up resistor.and then to pin 2 on the Seeeduino.

Here is a fritzing diagram I made to show you how to wire it all up.
Image

Once you have it wired up you will need to upload the following code to your Seeeduino. Once it is uploaded and you have some fluid flowing through the Water Flow Sensor, you can open the serial monitor and it will display the flow rate, refreshing every second.

Code: Select all
// reading liquid flow rate using Seeeduino and Water Flow Sensor from Seeedstudio.com
// Code adapted by Charles Gantt from PC Fan RPM code written by Crenn @thebestcasescenario.com
// http:/themakersworkbench.com http://thebestcasescenario.com http://seeedstudio.com

volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;                               
int hallsensor = 2;    //The pin location of the sensor

void rpm ()     //This is the function that the interupt calls
{
  NbTopsFan++;  //This function measures the rising and falling edge of the

hall effect sensors signal
}
// The setup() method runs once, when the sketch starts
void setup() //
{
  pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
  Serial.begin(9600); //This is the setup function where the serial port is

initialised,
  attachInterrupt(0, rpm, RISING); //and the interrupt is attached
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop ()   
{
  NbTopsFan = 0;   //Set NbTops to 0 ready for calculations
  sei();      //Enables interrupts
  delay (1000);   //Wait 1 second
  cli();      //Disable interrupts
  Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate

in L/hour
  Serial.print (Calc, DEC); //Prints the number calculated above
  Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a  new line
}



I hope this helps someone out! Thank's to Seeed Studio for hooking me up with a sensor so I could develop this tutorial.
User avatar
Newbie
Newbie
 
Posts: 19
Joined: Thu Jun 10, 2010 1:18 am
Location: USA

Re: Tutorial: Reading Water Flow rate with Water Flow Sensor

by ESP » Wed Sep 01, 2010 9:28 am

Can't wait to post it onto our product page.... Thank you so much pal!
User avatar
Staff Sergeant
Staff Sergeant
 
Posts: 361
Joined: Fri Aug 22, 2008 5:45 pm

Re: Tutorial: Reading Water Flow rate with Water Flow Sensor

by makersworkbench » Thu Sep 02, 2010 8:56 am

No problem Eric. I enjoyed writing it. I am working on the next write up, where I will show the user how to display that flow rate on an LCD. Eventually I want to set it up so the user can log the data using the Seeeduino Stalker.
User avatar
Newbie
Newbie
 
Posts: 19
Joined: Thu Jun 10, 2010 1:18 am
Location: USA

Re: Tutorial: Reading Water Flow rate with Water Flow Sensor

by eltoddo » Fri Oct 08, 2010 12:38 pm

This is very interesting! Thanks for posting. I have a question around a practical example I'm thinking about putting together around this. I see the the "accurate within 3%" note and I get a bit nervous...

How appropriate would this sensor be for measuring small amounts of liquid, like cups of beverage from a beverage dispenser? I would ideally like to achieve centiliter accuracy, if I pour a 50 centiliter cup of liquid (half a liter), is this sensor going to be resolute enough? ...Do I risk being off by 1.5 cl or so per beverage? Or better yet, can it be calibrated?

Thanks!
Newbie
Newbie
 
Posts: 1
Joined: Fri Oct 08, 2010 12:28 pm

Re: Tutorial: Reading Water Flow rate with Water Flow Sensor

by Nashblackcat » Sun Nov 07, 2010 6:34 am

I was think the same thing. I am wanting to dispense different liquids in the same fashion but I am wondering what this 3% means too. What would be the lowest accurate amount it could safely measure?

Kevin
Newbie
Newbie
 
Posts: 1
Joined: Sun Nov 07, 2010 6:29 am

Re: Tutorial: Reading Water Flow rate with Water Flow Sensor

by LeeLinkoff » Sat Dec 11, 2010 9:00 am

Hello,

Thank you very much for the write up. I am a newbie to microcontrollers and particularly in regards to fluid dynamics and flow rate.

Can anyone explain in detail the formula used:

NbTopsFan * 60 / 7.5 used in the code above
Newbie
Newbie
 
Posts: 1
Joined: Sat Dec 11, 2010 8:44 am

Re: Tutorial: Reading Water Flow rate with Water Flow Sensor

by nikoumouk » Sun Jan 23, 2011 6:20 am

Hi everyone,

Sorry for my english but i'm french... In first thank you for your post it' very interesting... I have just one qustion about your code, the flow is in L/min no? In the data sheet 7.5Q is for L/min...

Bye
Newbie
Newbie
 
Posts: 1
Joined: Sun Jan 23, 2011 5:09 am

Re: Tutorial: Reading Water Flow rate with Water Flow Sensor

by Brakke » Fri Feb 18, 2011 9:36 pm

eltoddo: Yes, it will be off 1.5cl in the worst case. If, and only if, the accuracy is constant for a certain device, it can be configured. Lets say you have constant -1% error in measured vs. real value, (aka. 50cl measured, 50.5cl real) you pull 1.01 as multiplier into the code. In +1%, you use 0.99 as multiplier. (Yes, it is a bit wrong, but I'm just making it simple enough.) Experiment and change the multiplier value to compensate. If the error was constant, that is.

Nashblackcat: If the sensor works with 1 to 30 liters per minute(LPM) range, 50cl is gained with 6LPM in 5 seconds. Take that as 10cl in 1 sec, and if going down to 2LPM speed, it is ~3.33cl in one sec. Hard to say what the safe margin is, but I would NOT try filling 4cl vodka shot. 8cl maybe.

LeeLinkoff: In the formula NbTopsFan * 60 / 7.5 , the NbTopsFan is the amount of rising pulse edges detected by the controller in a set delay time. Here it was 1 second. So we have here our pulses per second and the *60 multiplies this value by 60, so we get pulses per minute. The 7.5 is a constant set in the datasheet of the sensor that tells us the relation between flowrate and pulses per minute the sensor is sending. I would add here a correction value *0.97 to *1.03 if the measurement error is constant to a certain device.

nikoumouk: I agree, the comment and code is wrong and real output is in LPM. Add *60 or change original *60 to *3600 to get liters per hour.
Newbie
Newbie
 
Posts: 3
Joined: Fri Feb 18, 2011 8:32 pm
Location: Finland

Re: Tutorial: Reading Water Flow rate with Water Flow Sensor

by dnordenberg » Mon Feb 21, 2011 1:45 am

What happens to pulses that arrives while the interrupt is disabled? Don't you need a buffer here?
Soldier
Soldier
 
Posts: 92
Joined: Sun Jan 31, 2010 6:29 pm

Re: Tutorial: Reading Water Flow rate with Water Flow Sensor

by Brakke » Sun Feb 27, 2011 12:20 am

dnordenberg: No, you don't care about them. We need to look only the pulses during the 1 second period for our calculation of flow. The problems will come up only if the flow will change a lot in a short period of time, instead of being (almost) constant.
Newbie
Newbie
 
Posts: 3
Joined: Fri Feb 18, 2011 8:32 pm
Location: Finland

Next

Who is online
Users browsing this forum: No registered users and 3 guests