How To Measure Water Flow Rate and Volume using Arduino?


In this tutorial, we will measure the water flow rate and volume using an Arduino and a Flow Sensor. In this circuit, the water flow sensor is linked to an Arduino and an LCD, which is programmed to display the volume of water that has passed through the valve. The water flow sensor used in this circuit is an S201, which uses a hall effect to sense the flow rate of the liquid.

If You want similar Projects CLICK HERE

PCB Manufacturer

The pcb of this project is manufactured by JLCPCB. The reasons to choose JLCPCB for pcb manufacturing are:

  • Higher Quality
  • Lower Cost
  • Faster Delivery

If you want to order your pcb from jlcpcb just go through the link below:

Bill Of Materials

1Arduino BoardArduino UNO R3 Development Board1
2LCD Display 16x2 LCD Display1
3Potentiometer10K 1
4Water Flow Sensor YFS201 Hall Effect Water Flow Sensor1
5Water Pipe normal1
7Connecting wiresjumper wiresome

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.

YFS201 water flow sensor

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.

YFS201 water flow sensor

To connect with the pipe and water flow sensor, I used two connectors with a female thread as shown below.

connectors with a female thread

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.

working of S201 flow sensor

Water Flow Sensor Calculation

As you know,

1 Litre = 1000 mL

So, the range of this sensor is 300mL to 6000mL per minute.

At 1000mL you get 5880 pulses, but is that over a minute otherwise over a second its 5880/60 = 98 Hz square wave which has a period of 1/98 = 10.2 milliseconds.

For 1mL you calculate 5880/1000 = 5.88/60 = 0.098Hz with a period of 10.2 seconds. In the programming, I will be using the pulsein to measure the time of a pulse.


The connection of the water flow sensor and LCD(16×2) 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.

Connection diagram

Circuit Diagram of how we can Measure Water Flow Rate and Volume using Arduino

CIrcuit Diagram of Measurement of Water Flow Rate and Volume using Arduino

In this circuit, the water flow sensor is connected to a pipe; if the pipe’s output valve is closed, no water is sensed by the flow sensor, and thus no pulses are generated. There will be no interrupt signal on Arduino pin 2 and the flow frequency count will be zero. When the pipe’s output valve is opened, water flows through the sensor, rotating the wheel inside the sensor. There will now be pulses, and the Arduino will send an interrupt signal, and the count of the flow frequency will be increased by one for each interrupt signal. In this way we can measure the water flow rate and volume using an Arduino.

The coding is written in such a way that if there is no pulse, the code written inside the else loop will function. And the flow frequency on each pulse is used to calculate the water flow rate and volume. When the calculations are completed, the flow frequency variable is reset to zero, and the process is restarted.

Source Code

YF‐ S201 Water Flow Sensor
Water Flow Sensor output processed to read in litres/hour
Adaptation Courtesy:
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
void setup()
   pinMode(flowsensor, INPUT);
   digitalWrite(flowsensor, HIGH); // Optional Internal Pull-Up
   lcd.begin(16, 2);
   attachInterrupt(digitalPinToInterrupt(flowsensor), flow, RISING); // Setup Interrupt
   lcd.print("Water Flow Meter");
   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.print("Rate: ");
      lcd.print(" L/M");
      l_minute = l_minute/60;
      vol = vol +l_minute;
      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.print("Rate: ");
      lcd.print( flow_frequency );
      lcd.print(" L/M");
      lcd.print(" L");

Uses and Application

  • Automatic water dispensers.
  • Soft drink industries
  • Chemical industries
  • Smart irrigation systems

Recommended For You

About the Author: admin

Leave a Reply

Your email address will not be published.