Related Tutorials
No related posts.
Effective water management involves supplying water according to the real requirement, and thus measuring water is very essential step in water management systems. There are many water flow measurement techniques as well as different types of water flow meters used to measure the volume of water flow in pipelines but these all are too costly. This article describes ideas for design and development of low cost automatic water flow meters, with the help of readily-available and low-cost water flow sensors.
YF-S201 Hall-Effect Water Flow Sensor
Accurate flow measurement is an essential step both in the terms of qualitative and economic points of view. Flow meters have proven excellent devices for measuring water flow, and now it is very easy to build a water management system using the renowned water flow sensor YF-S201. This sensor sits in line with the water line and contains a pinwheel sensor to measure how much water has moved through it. There is an integrated magnetic Hall-Effect sensor that outputs an electrical pulse with every revolution. The “YFS201 Hall Effect Water Flow Sensor” comes with three wires: Red/VCC (5-24V DC Input), Black/GND (0V) and Yellow/OUT (Pulse Output). By counting the pulses from the output of the sensor, we can easily calculate the water flow rate (in litre/hour – L/hr) using a suitable conversion formula.
Hardware Hook Up
Connecting the water flow sensor to arduino requires minimal interconnection. Connect the VCC (Red) and GND (Black) wires of the water flow Sensor to the 5v and Gnd of Arduino, and link Pulse Output (Yellow) wire of the water flow sensor to Arduino’s digital pin 2. Note that the water flow sensor is not a power-hungry type; it draws a maximum of 15-20mA at 5V DC input!
Software Preparation
The Arduino Sketch (code) uses the external interrupt (int 0) on Arduino’s digital pin 2 (D2). This is used to read the output pulses coming from the water flow sensor. When Arduino detects the pulse, it immediately triggers the pulseCounter() function. This function then counts the total number of pulses detected (wanna know more about interrupts? http://playground.arduino.cc/Main/AVR).
/*
YF‐ S201 Water Flow Sensor
Water Flow Sensor output processed to read in litres/hour
Adaptation Courtesy: www.hobbytronics.co.uk
*/
volatile int flow_frequency; // Measures flow sensor pulses
unsigned int l_hour; // Calculated litres/hour
unsigned char flowsensor = 2; // Sensor Input
unsigned long currentTime;
unsigned long cloopTime;
void flow () // Interrupt function
{
flow_frequency++;
}
void setup()
{
pinMode(flowsensor, INPUT);
digitalWrite(flowsensor, HIGH); // Optional Internal Pull-Up
Serial.begin(9600);
attachInterrupt(0, flow, RISING); // Setup Interrupt
sei(); // Enable interrupts
currentTime = millis();
cloopTime = currentTime;
}
void loop ()
{
currentTime = millis();
// Every second, calculate and print litres/hour
if(currentTime >= (cloopTime + 1000))
{
cloopTime = currentTime; // Updates cloopTime
// Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min.
l_hour = (flow_frequency * 60 / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flowrate in L/hour
flow_frequency = 0; // Reset Counter
Serial.print(l_hour, DEC); // Print litres/hour
Serial.println(" L/hour");
}
}
Flow sensors typically output a series of pulses proportional to the instantaneous flow rate which means that to interpret them it is necessary to implement a simple frequency counter. Since this project uses a water flow sensor containing a Hall-Effect sensor that outputs a pulse rate proportional to flow rate, so not only is it a useful project in its own right but it also demonstrates a very useful technique that you can use in a wide range of projects that need to measure the rate at which something happens (an electronic wind instrument, for example).
Little Math Work
Now, have a look at the maths behind this Arduino Sketch. In our lab experiment, we used one YF-S201 water flow sensor bought from ebay (www.ebay.in ), and done the homework well with observed readings (±10 accuracy). In order to measure the quantity of water being passed in particular time through the water flow sensor it was first passed through the water flow sensor which was taken as input interface in the flow. Formulas are applied in order to measure the number of rotations/pulses in a minute of rotation.
Flow rate can be determined inferentially by different techniques like change in velocity or kinetic energy. Here we have determined flow rate by change in velocity of water. Velocity depends on the pressure that forces the through pipelines. As the pipe’s cross-sectional area is known and remains constant, the average velocity is an indication of the flow rate. The basis relationship for determining the liquid’s flow rate in such cases is Q=VxA, where Q is flow rate/total flow of water through the pipe, V is average velocity of the flow and A is the cross-sectional area of the pipe (viscosity, density and the friction of the liquid in contact with the pipe also influence the flow rate of water).
In other words:
Behind The Curtain
Really it was an awkward midnight experiment. We (me and my lab engineer diya missy) rolled up our sleeves and started the process with wet-hands. At first we made a simple construction comprised a rubber tube, plastic funnel, water flow sensor, and water bottles. Next we connected the water flow sensor’s output to the Arduino board (filled with the sketch) and allowed water flow through the water flow sensor at a steady rate of about 1 Litre/minute. Besides the Arduino’s serial monitor, we also used our DSO to measure pulse output from the water flow sensor. In that crude experiement, serial monitor displayed a rate of 56 Litre/hour (in lieu of the expected 60 Litre/hour rate)!
Since this experiment is now at the halfway mark, you can expect inspiring updates in due time. Meanwhile, refer all related projects on pulse/frequency counting with microcontrollers, published in this website to keep your interest alive. An example link: https://www.electroschematics.com/arduino-optical-position-rotary-encoder/
You must be logged in to post a comment.
Can you help me out please… i need to change the program so as to send the data to thingspeak… i have replaced arduino by esp8266…. please give me some code….
@msabinesh0: Not tried such an idea yet. I hope this helps you – https://gist.github.com/klanjabrik/367d7d370f27703425e7a77475b18b16
Further Explanation of the Maths:
Since I’m getting endless queries/requests raised by voracious readers and experimenters on the maths used here, I’d like to post a seriatim reply:
* Core component of the project is the YF-S201 Hall Effect Water Flow Meter /
Sensor
* Flow rate pulse characteristics of this particular sensor: Frequency (Hz) = 7.5 *
Flow rate (L/min)
For example, the Frequency (Hz) for 120L/H Flow = 7.5 * (120/60) = 15Hz +/- 10%
In other words, if the observed pulse frequency is 15Hz, then Flow rate (L/H) =
(15Hz x60)/7.5 = 120 L/H
* In datasheet it’s mentioned as 16Hz
(http://www.hobbytronics.co.uk/datasheets/sensors/YF-S201.pdf). It’s usual, as
it’s not a precision sensor, and the pulse rate does vary a bit depending on the
flow rate!
* The example Arduino sketch in the article (provided by the seller) is used to
quickly test the sensor as it’ll calculate the approximate flow of water in
liters/hour.
* Since the pulse signal is a simple square wave (each pulse is approximately 2.25
milliliters) so its quite easy to handle and translate into liters per minute using
the formula: Flow rate in L/min = Pulse frequency (Hz) / 7.5
And then multiply it by 60 to get glow rate in L/H
That’s ALL!
Hareendran,
I am doing the same with Wemos D1 mini, as I want to transmit the data to the cloud using MQTT.
Couple of questions :
Do you know what is the corresponding Physical Interrupt pins on the wemos D1 ESP module.
All the Digital pins on the Wemos are interrupt enabled.
But do you know what are the ” Internal pins reference” to be used.
For example : In this article it says use pin 2 for INT.0(zero) on an Arduino Uno.
https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/
== cut and paste==
Note that in the table below, the interrupt numbers refer to the number to be passed to attachInterrupt(). For historical reasons,
== dont cut and paste ==
“attachInterrupt(digitalPinToInterrupt(0), pulseCounter, FALLING);”.
Likewise for the Wemos – it has to be something similar ?
Any ideas .
On a related note – I am a fan of your page and articles – well written in detail.
kiranshashi: Thanks for your feedback. Since your question is connected with Wemos D1 mini , I obviously need sometime to give a pragmatic reply. Meanwhile you can refer these links (if not read yet) as it seems very helpful:
https://techtutorialsx.com/2016/12/11/esp8266-external-interrupts/
https://circuits4you.com/2017/12/08/esp8266-external-interrupt-example/
https://www.codrey.com/arduino-projects/wemos-d1-mini-an-introduction/
Question is : What is the Pin number that I have to connect to on Wemos, to be treated as INT.0.
The Wemos has physical pins such as “D0, D1, D2, D3 and D4, D5, D6, D7 and D8”
Does INT.0 correspond to D0 ? Apparently D0 interrupt for the flow meter is not working.
I m using the YF-S201, 1/2 inch pipe water flow sensor.
What is 7.5?
I am new to Arduino and to the world of programming.
I would really like to know what “Serial.begin(9600)” means.
Thanks in advance 😀
Serial.begin is used to set the speed of communication (in bits per second). For more, refer this- https://www.arduino.cc/en/serial/begin , and/or this one – http://www.ladyada.net/learn/arduino/lesson4.html
please keep us updated on this
this may be a dumb question but in your equation
Pulse frequency (Hz) = 7.5Q, Q is flow rate in Litres/minute
Flow Rate (Litres/hour) = (Pulse frequency x 60 min) / 7.5Q
where Q is flow rate, So why there’s a Q in denominator
I’m confused
Pulse frequency (Hz) = 7.5Q, Q is flow rate in Litres/minute
so,
Q (liters/min) = pulse frequency/7.5
Q(liters/ hour) = (pulse frequency * 60) / 7.5
but your equn
Pulse frequency (Hz) = 7.5Q, Q is flow rate in Litres/minute
Flow Rate (Litres/min) = Pulse frequency / 7.5Q
Flow Rate (Litres/hour) = (Pulse frequency x 60 min) / 7.5Q
why Q in denominator?
Refer the “Little Math Work” section again!
this is a useful sensor for agriculture based projects, where can i get the sensor
Thanks Mr. T.K.Hareendran
a minor error code
if(currentTime >= (cloopTime + 1000))
if(currentTime = (cloopTime + 1000))
I think it is an issue with the visual editor. It changed angle brackets into their HTML entity equivalents when the post was saved.
thank you very much sir T.K.hareendran. I like to read all of your projects with theory and grasping my knowledge a lot.sir I want to know that may I use this flow measurement meter for commercial selling purpose.means may I manufacture and sell it commercially?? Need your needful advice here sir
Thanks again