Seeedstudio Forum

Electronics can be art.
It is currently Thu Aug 21, 2014 4:26 am




Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Tutorial: Reading Water Flow rate with Water Flow Sensor
PostPosted: Sun Aug 29, 2010 2:43 pm 
Offline
Newbie
Newbie
User avatar

Joined: Thu Jun 10, 2010 1:18 am
Posts: 19
Location: USA
Honor: 0.00
Points: 19.00 Points
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:
// 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.

_________________
Charles Gantt
The Makers Workbench.com


Top
 Profile  
 
 Post subject: Re: Tutorial: Reading Water Flow rate with Water Flow Sensor
PostPosted: Wed Sep 01, 2010 9:28 am 
Offline
Staff Sergeant
Staff Sergeant
User avatar

Joined: Fri Aug 22, 2008 5:45 pm
Posts: 361
Honor: 0.00
Points: 361.00 Points
Can't wait to post it onto our product page.... Thank you so much pal!


Top
 Profile  
 
 Post subject: Re: Tutorial: Reading Water Flow rate with Water Flow Sensor
PostPosted: Thu Sep 02, 2010 8:56 am 
Offline
Newbie
Newbie
User avatar

Joined: Thu Jun 10, 2010 1:18 am
Posts: 19
Location: USA
Honor: 0.00
Points: 19.00 Points
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.

_________________
Charles Gantt
The Makers Workbench.com


Top
 Profile  
 
 Post subject: Re: Tutorial: Reading Water Flow rate with Water Flow Sensor
PostPosted: Fri Oct 08, 2010 12:38 pm 
Offline
Newbie
Newbie

Joined: Fri Oct 08, 2010 12:28 pm
Posts: 1
Honor: 0.00
Points: 1.00 Points
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!


Top
 Profile  
 
 Post subject: Re: Tutorial: Reading Water Flow rate with Water Flow Sensor
PostPosted: Sun Nov 07, 2010 6:34 am 
Offline
Newbie
Newbie

Joined: Sun Nov 07, 2010 6:29 am
Posts: 1
Honor: 0.00
Points: 1.00 Points
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


Top
 Profile  
 
 Post subject: Re: Tutorial: Reading Water Flow rate with Water Flow Sensor
PostPosted: Sat Dec 11, 2010 9:00 am 
Offline
Newbie
Newbie

Joined: Sat Dec 11, 2010 8:44 am
Posts: 1
Honor: 0.00
Points: 1.00 Points
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


Top
 Profile  
 
 Post subject: Re: Tutorial: Reading Water Flow rate with Water Flow Sensor
PostPosted: Sun Jan 23, 2011 6:20 am 
Offline
Newbie
Newbie

Joined: Sun Jan 23, 2011 5:09 am
Posts: 1
Honor: 0.00
Points: 1.00 Points
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


Top
 Profile  
 
 Post subject: Re: Tutorial: Reading Water Flow rate with Water Flow Sensor
PostPosted: Fri Feb 18, 2011 9:36 pm 
Offline
Newbie
Newbie

Joined: Fri Feb 18, 2011 8:32 pm
Posts: 3
Location: Finland
Honor: 0.00
Points: 3.00 Points
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.


Top
 Profile  
 
 Post subject: Re: Tutorial: Reading Water Flow rate with Water Flow Sensor
PostPosted: Mon Feb 21, 2011 1:45 am 
Offline
Soldier
Soldier

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


Top
 Profile  
 
 Post subject: Re: Tutorial: Reading Water Flow rate with Water Flow Sensor
PostPosted: Sun Feb 27, 2011 12:20 am 
Offline
Newbie
Newbie

Joined: Fri Feb 18, 2011 8:32 pm
Posts: 3
Location: Finland
Honor: 0.00
Points: 3.00 Points
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2, 3  Next


Who is online

Users browsing this forum: Google Feedfetcher and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group  
Design By Poker Bandits