Measuring Water Flow Rate and Volume using Arduino

6,261 views

Almost all the large scale manufacturing companies are automated and those industries that are mainly working on fluids or chemicals have to constantly measure and quantify the liquids that they have to handle in the automation process. The sensor which is commonly used to measure the flow of liquid is called a Flow Sensor. When the flow sensor along with an Arduino is used we can calculate the flow rate and check the volume of the liquid that is passed through the pipe and control it as needed.

In this tutorial, we are Measuring water Flow Rate and Volume using Arduino and Flow Sensor. In this circuit we have interfaced the water flow sensor with an Arduino and an LCD, it is programmed in a way that it displays the volume of water which has passed through the valve. The water flow we used in this circuit is an S201 water flow sensor, this sensor uses a hall effect to sense the flow rate of the liquid.

Hardware Required

S.noComponentValueQty
1.Water Flow Sensor1
2.Arduino UNO1
3.LCD 1
4.Connector with internal threading16×21
5.Pipe1

Connections

The connections of LCD and Water flow sensor with Arduino are stated in the table below. the potentiometer is connected between 5V and GND and its pin 2 is connected with the V0 of the LCD

S.noWater Flow SensorArduino Pins
1Red Wire5V
2BlackGND
3YellowA0
S.noLCDArduino Pins
1VssGND(ground rail of breadboard)
2VDD5V (Positive rail of the breadboard)
4RS12
5RWGND
6E11
7D79
8D6 to D33 to 5

Circuit Diagram

Working Explanation

In this circuit the water flow sensor is connected to a pipe, if the output valve of the pipe is closed so no water is sensed by the flow sensor hence no pulses. There will be no interrupt signal on pin 2 of the Arduino and the count of the flow frequency. will be zero. If the output valve of the pipe is opened the water will flow through the sensor which rotates the wheel inside the sensor. Now there will be pulses and the Arduino will send an interrupt signal and for each interrupt signal, the count of the flow frequency will be increased by one.

The coding is done in such a way that when there is no pulse the code written inside the else loop will work. And on each pulse, the flow frequency is taken for calculation of water flow rate and volume. When the calculations are done, the flow frequency variable is reset to zero and the whole process starts from the beginning.

Applications and Uses

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

Arduino 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");
    }
   }
}