You are on page 1of 30

A project report 0n

Measuring water flow rate and Volume using arduino and


flow sensor
Submitted by

D.Naveen Kumar 180069010


E.william cary 180069011
GT.Prasanth 180069013
Sec - 1, Batch -15

II/IV BACHELOR OF TECHNOLOGY

IN

Department of Electrical and Electronics engineering


(SEMESTER-IV)

Koneru Lakshmaiah Education Foundation

VADDESWARAM-522502
April 2020
Koneru Lakshmaiah Education Foundation
Analog Electronics Circuits and Design (18EC2103)
Electrical & Electronics engineers

CERTIFICATE

This is to certify that Mr.D.NaveenKumar -180069010,


Mr.E.Williamcary-180069011 & Mr.Gt.Prasanth-180069013of
section 1 studying II/IV B.Tech in EEE has satisfactorily
completed project “Measuring water flow rate and Volume using
arduino and flow sensor”in the semester II during the academic
year 2019-2020.

Signature of Course Instructor Signature of Course Coordinator

Mr. KASI UDAY KIRAN Mr. KASI UDAY KIRAN

Signature of HOD

Dr.S.V.N.L.Lalitha
ACKNOWLEDGEMENT

We express great pleasure for me to express my gratitude to our honourable


President Sri. Koneru Satyanarayana, for providing the opportunity and platform
with facilities in accomplishing the project based laboratory. We express the
sincere gratitude to our principal Dr. K. Subbarao for his administration towards
our academic growth.

We express sincere gratitude to our Head of the department EEE Dr. S. V.


N. LALITHA for her leadership and constant motivation provided in successful
completion of our academic semester. We record it as our privilege to deeply thank
for providing us the efficient faculty and facilities to make our ideas into reality.

We express my sincere thanks to our project supervisor Mr. KASI UDAY


KIRAN for his novel association of ideas, encouragement, appreciation and
intellectual zeal which motivated us to venture this project successfully.

We are pleased to acknowledge the indebtedness to our lab technicians who


devoted themselves directly or indirectly to make this project success.

Last but not the least we express our deep gratitude and affection to our
parents who stood behind us in all our endeavors.

D.Naveen Kumar 180069010


E.william cary 180069011
GT.Prasanth 180069013
TABLE OF CONTENTS

S.NO CONTENTS PAGE NO

1. Abstract v

2. Introduction vi

3. Components Required vii

4. YFS201 Water Flow ix


Sensor
5. Circuit Diagram x

6. xvi
Arduino Water Flow Sensor
Code&Working

7. Code xviii

8. Working xxii

9. Output xxvi

10. Advantages&disadvantages xxviii

11. Conclusion xxix

12 references xxx
ABSTRACT

If you have ever visited large scale manufacturing companies, the first thing you will notice is that they are all

automated. Soft Drink Industries and Chemical industries have to constantly measure and quantify the liquids

that they are handling during this automation process, and the most common sensor used to measure the flow of a

liquid is a Flow Sensor.

By using a flow sensor with a microcontroller like Arduino, we can calculate the flow rate, and check the volume of

liquid that has passed through a pipe, and control it as required. Apart from manufacturing industries, flow sensors

can also be found in the agriculture sector, food processing, water management, mining industry, water recycling,

coffee machines etc. Further, a water flow sensor will be a good addition to projects like Automatic water

dispenser and smart irrigation systems where we need to monitor and control the flow of liquids.

In this project, we are going to build a water flow sensor using Arduino. We will interface the water flow sensor with

Arduino and LCD, and program it to display the volume of water, which has passed through the valve. For this

particular project, we are going to use the YF-S201 water flow sensor, which uses a hall effect to sense the flow

rate of the liquid.

.
INTRODUCTION
Flow rate and volume helps tell the amount of fluid going into, or through a particular vessel. For certain process

automation applications, this simple-sounding fluid measurement task is so critical to the success of the project

that, failureto get it right, could bring the entire process to its knees. This is why for today’s tutorial, I thought it

will be cool to look atthis nice water flow sensor; the YF-S201, and its use in an Arduino based project.

The sensor uses the principles of electromagnetism, such that, when liquids flow through the sensor, the flow action

impacts the fins of a turbine in the sensor, causing the wheel to spin. The shaft of the turbine wheel is connected

to a hall effect sensor so that with every spin, a pulse is generated, and by monitoring that pulse with a

microcontroller, the sensor can be used in determining the volume of fluid passing through it.

As the microcontroller for today, we will use the Arduino Uno. The Uno will be used to count the number of pulses

detected over time and calculate the flow rate (in liters/hour) and total volume of fluid that has passed through it

using the total number of pulses. The result, flow rate and volume, will then be displayed on a 16×2 LCD so as to

provide a visual feedback to the user. If the 16×2 LCD is not available, you can view the data over the Arduino

Serial Monitor.At the end this tutorial, you would know how to use the YF-S201 flow sensor with the Arduino.
To make reading the sensor and calculating flow easy, the interrupt feature of the Atmega328p on the

Ardunio is employed, as such, the signal pin of the YF-S201 is connected to one of the interrupt-enabled

IOs of the Uno (in this case, pin D2). The LCD, on the other hand, is connected in a 4-bit mode to the

Arduino. To save some time on connections, you could also decide to use an I2C enabled version of the

16×2 LCD display. For this, you will only need to connect 4 wires from the display to the Arduino. It will,

however, call for some modification in the code, so be sure you can handle it before making that decision.

Components Required:
1. Water Flow Sensor

2. Arduino UNO

3. LCD (16x2)

4. Connector with internal threading

5. Connecting wires

6. Pipe
YFS201 Water Flow Sensor:
The sensor has 3 wires RED, YELLOW, and BLACK as shown in the figure below. The red wire is used for supply

voltage which ranges from 5V to 18V and the black wire is connected to GND. The yellow wire is used for output

(pulses), which can be read by an MCU. The water flow sensor consists of a pinwheel sensor that measures the

quantity of liquid that has passed through it.

The working of the YFS201 water flow sensor is simple to understand. The water flow sensor works on

the principle of hall effect. Hall effect is the production of the potential difference across an electric

conductor when a magnetic field is applied in the direction perpendicular to that of the flow of current.

The water flow sensor is integrated with a magnetic hall effect sensor, which generates an electric pulse

with every revolution. Its design is in such a way that the hall effect sensor is sealed off from the water, and

allows the sensor to stay safe and dry.


The picture of the YFS201 sensor module alone is shown below.

To connect with the pipe and water flow sensor, I used two connectors with a female thread as shown below.
According to YFS201 Specifications, the maximum current it draws at 5V is 15mA, and the working flow

rate is 1 to 30 liters/minute. When the liquid flows through the sensor, it makes contact with the fins of the

turbine wheel, which is placed in the path of the flowing liquid. The shaft of the turbine wheel is connected

to a hall effect sensor. Due to this, whenever water flows through the valve it generates pulses. Now, all we

have to do is to measure the time for the pluses or to count the number of pulses in 1 second and then

calculate the flow rates in liter per hour (L/Hr) and then use simple conversion formula to find the volume

of the water which had passed through it. To measure the pulses, we are going to use Arduino UNO.
The pic below shows you the pinout of the water flow sensor.

Circuit Diagram:

The water flow sensor circuit diagram is shown below to interface a water flow sensor and LCD (16x2)

with Arduino. If you are new to Arduino and LCDs, you can consider reading this Interfacing Arduino and
LCD Article.
The connection of the water flow sensor and LCD(16x2) with the Arduino is given below in table format.
Note that the pot is connected in between 5V and GND and pot’s pin 2 is connected with the V0 pin of the

LCD.

S.NO Water Flow sensor pin Arduino Pins

1 Red Wire 5V

2 Black GND

3 Yellow A0

S.No LCD Arduino

1 Vss GND(ground rail of breadboard)

2 VDD 5V (Positive rail of the breadboard)

3 For connection with V0 check the above note

4 RS 12

5 RW GND

6 E 11

7 D7 9

8 D6 to D3 3 to 5

I used a breadboard, and once the connection was done as per the circuit diagram shown above, my
testing set-up looked something like this.
Arduino Water Flow Sensor Code:

The complete water flow sensor Arduino code is given at the bottom of the page. The explanation of

the code is as follows.


We are using the header file of the LCD, which eases our interfacing the LCD with Arduino, and

the pins 12,11,5,4,3,9 are allotted for data transfer between LCD and Arduino. The sensor's output
pin is connected to pin 2 of Arduino UNO.

volatile int flow_frequency; // Measures flow sensor pulses

// Calculated litres/hour

float vol = 0.0,l_minute;

unsigned char flowsensor = 2; // Sensor Input

unsigned long currentTime;

unsigned long cloopTime;

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 9);

This function is an interrupt service routine and this will be called whenever there is an interrupt signal at
pin2 of Arduino UNO. For every interrupt signal, the count of the variable flow_frequency will be increased
by 1. For more details on the interrupts and their working, you can read this article on Arduino interrupts.
void flow () // Interrupt function

flow_frequency++;

In the void setup, we tell the MCU that the pin 2 of the Arduino UNO is used as INPUT by giving
command pinMode(pin, OUTPUT). By using attachInterrupt command, whenever there is a rise in the
signal at pin 2, the flow function is called. This increases the count in the variable flow_frequency by
1. The current time and cloopTime are used for the code to run in every 1 second.

void setup()

pinMode(flowsensor, INPUT);

digitalWrite(flowsensor, HIGH);

Serial.begin(9600);

lcd.begin(16, 2);

attachInterrupt(digitalPinToInterrupt(flowsensor), flow, RISING); // Setup

Interrupt

lcd.clear();

lcd.setCursor(0,0);

lcd.print("Water Flow Meter");

lcd.setCursor(0,1);

lcd.print("Circuit Digest");

currentTime = millis();

cloopTime = currentTime;

The if function ensures that for every one second the code inside it runs. In this way, we can count the

number of frequencies produces by the water flow sensor per second. The flow rate pulse characteristics

from the datasheet are given that frequency is 7.5 multiplied by flow rate. So the flow rate is frequency
/ 7.5. After finding flow rate which is in liters/minute, divide it by 60 to convert it into liter/sec. This value is

added to the vol variable for every one second.

void loop ()

currentTime = millis();

// Every second, calculate and print litres/hour

if(currentTime >= (cloopTime + 1000))

cloopTime = currentTime; // Updates cloopTime

if(flow_frequency != 0){

// Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min.

l_minute = (flow_frequency / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flow

rate in L/hour

lcd.clear();

lcd.setCursor(0,0);

lcd.print("Rate: ");

lcd.print(l_minute);

lcd.print(" L/M");

l_minute = l_minute/60;

lcd.setCursor(0,1);

vol = vol +l_minute;

lcd.print("Vol:");

lcd.print(vol);

lcd.print(" L");

flow_frequency = 0; // Reset Counter

Serial.print(l_minute, DEC); // Print litres/hour


Serial.println(" L/Sec");

The else function works when there is no output from the water flow sensor within the given time span.

else {

lcd.clear();

lcd.setCursor(0,0);

lcd.print("Rate: ");

lcd.print( flow_frequency );

lcd.print(" L/M");

lcd.setCursor(0,1);

lcd.print("Vol:");

lcd.print(vol);

lcd.print(" L");

Arduino Water Flow Sensor Working


In our project, we connected the water flow sensor to a pipe. If the output valve of the pipe is closed, the

output of the water flow sensor is zero (No pulses). There will be no interrupt signal seen at the pin 2 of the
Arduino, and the count of the flow_frequency will be zero. In this condition, the code which is written inside

the else loop will work.


If the output valve of the pipe is opened. The water flows through the sensor, which in turn rotates the wheel

inside the sensor. In this condition, we can observe pulses, which are generated from the sensor. These

pulses will act as an interrupt signal to the Arduino UNO. For every interrupt signal(rising edge), the count
of the flow_frequency variable will be increased by one. The current time and cloopTIme variable ensure
that for every one second the value of the flow_frequency is taken for calculation of flow rate and volume.
After the calculation is finished, the flow_frequency variable is set to zero and the whole procedure is
started from the beginning.

The complete working can also be found in the video linked at the bottom of this page. Hope you enjoyed
the tutorial and enjoyed something useful, if you have any problems, please leave them in the comment

section or use our forums for other technical questions.


Code:

/*
YF‐ S201 Water Flow Sensor
Water Flow Sensor output processed to read in litres/hour
Adaptation Courtesy: hobbytronics.co.uk
*/
volatile int flow_frequency; // Measures flow sensor pulses
// Calculated litres/hour
float vol = 0.0,l_minute;
unsigned char flowsensor = 2; // Sensor Input
unsigned long currentTime;
unsigned long cloopTime;
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 9);
void flow () // Interrupt function
{
flow_frequency++;
}
void setup()
{
pinMode(flowsensor, INPUT);
digitalWrite(flowsensor, HIGH); // Optional Internal Pull-Up
Serial.begin(9600);
lcd.begin(16, 2);
attachInterrupt(digitalPinToInterrupt(flowsensor), flow, RISING); // Setup Interrupt
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Water Flow Meter");
lcd.setCursor(0,1);
lcd.print("Circuit Digest");
currentTime = millis();
cloopTime = currentTime;
}
void loop ()
{
currentTime = millis();
// Every second, calculate and print litres/hour
if(currentTime >= (cloopTime + 1000))
{
cloopTime = currentTime; // Updates cloopTime
if(flow_frequency != 0){
// Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min.
l_minute = (flow_frequency / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flowrate in L/hour
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Rate: ");
lcd.print(l_minute);
lcd.print(" L/M");
l_minute = l_minute/60;
lcd.setCursor(0,1);
vol = vol +l_minute;
lcd.print("Vol:");
lcd.print(vol);
lcd.print(" L");
flow_frequency = 0; // Reset Counter
Serial.print(l_minute, DEC); // Print litres/hour
Serial.println(" L/Sec");
}
else {
Serial.println(" flow rate = 0 ");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Rate: ");
lcd.print( flow_frequency );
lcd.print(" L/M");
lcd.setCursor(0,1);
lcd.print("Vol:");
lcd.print(vol);
lcd.print(" L");
}
}
}
Working

Go over your connections to be sure everything is as it should be. With this done and the code complete,

connect the hardware to your computer and upload the code to the Arduino board. If successful, you

should see the display come up as shown in the image below

Connect some pipes to it using whatever means is easy for you and pass some water through the flow
sensor. You should see the flowrate being displayed on your screen, vary with the intensity of water flow,
and you should also see the volume increase as more water flows through it.If you don’t have the
tubes/pipes for water around at that instant, you can blow some air into the sensor. You should hear the
rotor in spin and the values on the LCD should increase.
Flowrate/ volume metering is a very important part of several industrial and even individual consumer

processes. It provides to not only monitor consumption but also meter supply and I believe applications like

smart water meters and automated fluid dispensers should give you tons of insights into how this seemingly
basic project could be transformed into an amazing super useful product.That’s it! feel free to reach me

via the comments section for help with any challenge you might have replicating the project.

Recent advances in flow sensing have resulted in more accurate, durable, and economical meters.

Increasingly important is the ability to interface meters with a computer for instantaneous flow

readout to remotely control flow, or to allow unattended process operation. To meet such demands,

new types of flowmeters are being introduced, and older designs are being improved and updated.

Prime considerations when selecting a flow sensor include: the type of fluid being measured, its

temperature and pressure, viscosity, conductivity, corrosiveness, and cleanliness. Equally

important are the requirements of the sensor itself: Flow velocity range, accuracy,

ease of installation, and maintenance requirements. Finally, cost can be a major factor in the

decision.

Two basic classes of flowmeters are differential producers and linear flowmeters.

Differential-producer flowmeters create a restriction in the flow field. When flow is contracted, either

gradually or abruptly, kinetic energy increases at the expense of potential energy (static pressure).

difference between pressure at the full pipe section and that in the vicinity of the contraction is

related to the square root of the velocity at the full section minus the square root of the velocity at

the contraction. Fluid properties and the abruptness of the contraction also play a role in the

operation of these meters.

The pressure/flow relationship depends on the length and condition of the reference piping,

pressure tap locations, and the geometry of the restricting element (differential producer). Any
change in these characteristics alters the relationship, making these devices extremely sensitive to

installation conditions. The greatest disadvantage to this class of flowmeters is that they require a

secondary measuring system -- flow is determined based on a pressure-flow relationship.

Sensors play a very crucial role in today’s automatic systems. Being a small, low cost and reliable

device, sensors are easy to embed with larger electronics. Today we can find various types of sensors

in the market. With the advance in technology, sensors are also evolved in their functioning and size.

From the early size of cm units, size of sensors has shrunk to the scale of nm. Sensors have also

solved many challenges of electronic and electrical engineering such as finding the intensity of ambient

light, determining the temperature in the furnace, calculating humidity of surrounding, etc…. Water flow

sensor gives an amazing solution for measuring the flow rate of liquids.

Water flow sensor consists of a plastic valve from which water can pass. A water rotor along with a hall

effect sensor is present the sense and measure the water flow When water flows through the valve it

rotates the rotor. By this, the change can be observed in the speed of the motor. This change is

calculated as output as a pulse signal by the hall effect sensor. Thus, the rate of flow of water can be

measured. The main working principle behind the working of this sensor is the Hall effect. According

to this principle, in this sensor, a voltage difference is induced in the conductor due to the rotation of

the rotor. This induced voltage difference is transverse to the electric current.
The water flow sensor can be used with hot waters, cold waters, warm waters, clean water, and dirty

water also. These sensors are available in different diameters, with different flow rate ranges.

These sensors can be easily interfaced with microcontrollers like Arduino. For this, an Arduino

microcontroller board for processing, a Hall effect water flow sensor, a 16×2 LCD display, and

Breadboard connecting wires are required. The sensor is placed at the water source inlet or at the

opening of the pipe.

The sensor contains three wires. Red wire to connect with supply voltage. Black wire to connect to

ground and a yellow wire to collect output from Hall effect sensor. For supply voltage 5V to 18V of DC is

required.

Water flow sensors can measure the rate of flow of water either by measuring velocity or

displacement. These sensors can also measure the flow of water like fluids such as measuring

milk in a dairy industry etc…

There are various types of water flow sensors available based on their diameter and method of

measuring. A cost-effective and most commonly used water flow sensor is Paddlewheel sensor.

It can be used with water-like fluids.

For the type of applications where a straight pipe is not available for inlet, Positive displacement

flow meter is used. This type of water flow sensor can be used for viscous liquids also.

For working with dirty water and wastewater which may be conductive, Magnetic flow meter is used.

For applications such as sewage water, slurries, and other dirty liquids Ultrasonic flow meters are used.
The LCD display is used to display the measurements. The magnetic hall effect water flow sensor

outputs a pulse of every revolution of the rotor. The hall effect sensor present in the device is sealed

from water to keep it safe and dry.

Example of Water Flow Sensor:

YFS201 Hall effect sensor is an example of this sensor. These sensors also require a display to

display the measurements. This sensor outputs 4-5 pulses for every liter of liquid flowing through it

per minute. It has a working flow rate of 1-30liters per minute.


Output
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).
Advantages:

 Unobstructed flow passage without projecting parts

 No moving parts

 No additional pressure drop

 Essentially flow profile insensitive, only short inlet and outlet sections required

 Unaffected by changes in temperature, density, viscosity, concentration and electrical conductivity

 Favorable choice of materials for chemically aggressive or abrasive measuring media

 Unaffected by contamination and deposits

 Especially suitable for hydraulic solids transport

 Linear relationship between flow rate and measured variable

 Operates in both flow directions (forward and reverse)


 Measuring range setting can be optimized

 Low maintenance, but still easy to maintain

Limitations:

 For liquids only

 Lower conductivity limit 0.05 μS/cm

 Gas inclusions cause errors.


Conclusion:

By carrying out this project, I concluded thatwater controlling and speed of the flow of
water by following the basic definition, i.e, by seeing the digital display .

I developed a program which is used to use the operate the sensor


And it is used for many applications and it has
the major increasing the water and we can control the speed of the
water .
arduino is used as a major of the project and has the main reason this is the
conclusion o this project.
REFERENCES:

1.https://circuitdigest.com/microcontroller-projects/arduino-based-water-flow-sensor

2.https://circuitdigest.com/microcontroller-projects/arduino-based-water-flow-sensor

3. https://www.elprocus.com/a-memoir-on-water-flow-sensor/

You might also like