Water Flow Sensor Measure on 16×2 LCD Display

3,349 views

Introduction

Water supply is a primary concern for large infrastructure projects like factories, homes, apartments, etc. To fulfill this need, we tap into the public water supply. So, the water flow rate must be monitored to ensure enough water for everyone. Sensors able to measure the rate of water flow are employed for this function. Hence water flow sensor does this job. In this article, we will use a water flow sensor, measure the readings, and display them on a 16×2 LCD Display.

The water flow sensor is versatile enough to be utilized with various waters, including clean water, unclean water, hot water, and cold water. Let’s read this article further to learn more about the water flow sensor.

What is Water Flow Sensor?

As the name implies, water flow sensors can detect the rates at which water moves through pipes. These sensors can be placed at the water source or pipelines to determine the flow rate and the amount of water that has passed through the system. The water flow rate is expressed in liters per hour or cubic meters.

Water Flow Sensor

Hardware Components

You will require the following hardware for Water Flow Sensor Measure on a 16×2 LCD Display.

S.noComponentValueQty
1.Arduino UNO1
2.Water Flow SensorYF-S2011
3.LCD Display16×21
4.Breadboard1
5.Jumper Wires1

Steps in Making a Water Flow Sensor

We’ll need a breadboard, an Arduino microcontroller board, a Hall effect water flow sensor, an LCD, and some connecting wires for this Water Flow Sensor Measure on a 16×2 LCD Display. Once you get them, follow the following steps:

Schematic

Make connections according to the circuit diagram given below.

Wiring / Connections

ArduinoWater Flow SensorLCD
5VVCCVCC
GNDGNDGND
D3SIG
D4VO
D5RS
D6RW
D7EN
D8D11
D9D12

Installing Arduino IDE

First, you need to install Arduino IDE Software from its official website Arduino. Here is a simple step-by-step guide on “How to install Arduino IDE“.

Installing Libraries

Before you start uploading a code, download and unzip the following libraries at /Progam Files(x86)/Arduino/Libraries (default), in order to use the sensor with the Arduino board. Here is a simple step-by-step guide on “How to Add Libraries in Arduino IDE“.

Code

Now copy the following code and upload it to Arduino IDE Software.

#include <LiquidCrystal.h>
const int rs = 4, en = 5, d4 = 6, d5 = 7, d6 = 8, d7 = 9;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
byte statusLed    = 13;

byte sensorInterrupt = 0;  // 0 = digital pin 2
byte sensorPin       = 3;


float calibrationFactor = 7.5;

volatile byte pulseCount;  

float flowRate;
unsigned int flowMilliLitres;
unsigned long totalMilliLitres;

unsigned long oldTime;

void setup()
{

   
  // Set up the status LED line as an output
  pinMode(statusLed, OUTPUT);
  digitalWrite(statusLed, HIGH); 
  pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);

  pulseCount        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitres  = 0;
  oldTime           = 0;

  // The Hall-effect sensor is connected to pin 2 which uses interrupt 0.
  // Configured to trigger on a FALLING state change (transition from HIGH
  // state to LOW state)
  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}

/**
 * Main program loop
 */
void loop()
{
   
   if((millis() - oldTime) > 1000)    // Only process counters once per second
  { 
    
    detachInterrupt(sensorInterrupt);
        
    // Because this loop may not complete in exactly 1 second intervals we calculate
    // the number of milliseconds that have passed since the last execution and use
    // that to scale the output. We also apply the calibrationFactor to scale the output
    // based on the number of pulses per second per units of measure (litres/minute in
    // this case) coming from the sensor.
    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
    
    // Note the time this processing pass was executed. Note that because we've
    // disabled interrupts the millis() function won't actually be incrementing right
    // at this point, but it will still return the value it was set to just before
    // interrupts went away.
    oldTime = millis();
    
    // Divide the flow rate in litres/minute by 60 to determine how many litres have
    // passed through the sensor in this 1 second interval, then multiply by 1000 to
    // convert to millilitres.
    flowMilliLitres = (flowRate / 60) * 1000;
    
    // Add the millilitres passed in this second to the cumulative total
    totalMilliLitres += flowMilliLitres;
      
    unsigned int frac;
    
  lcd.begin(16, 2);
  lcd.print(" Flow Rate");
  lcd.setCursor(1, 1);
  lcd.print(flowRate);
  lcd.setCursor(6, 1);
  lcd.print("L/Min");
    
    

    // Reset the pulse counter so we can start incrementing again
    pulseCount = 0;
    
    // Enable the interrupt again now that we've finished sending output
    attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
  }
}

/*
I.S.R.
 */
void pulseCounter()
{
  // Increment the pulse counter
  pulseCount++;
}

Let’s Test It

The circuit has been assembled and now has to be tested. The LCD will display the resulting reading when the sensor is placed in moving water after the code has been uploaded. Keep your LCD, Arduino, and other electronics away from the water source.

Working Explanation

With this Arduino code for the water flow sensor, the water flow rate is measured in liters per minute and shown on the LCD. The unit of measurement used for the water flow rate is L/min. When water passes through the valve, it causes the rotor to begin rotating. The resulting variation in motor speed can be observed.  The hall effect sensor calculates this change and outputs it as a pulse signal. Thus, it is possible to measure the water’s flow rate.

Applications

  • Automatic water heaters
  • Coffee machines
  • Dairy Industry
  • Water vending machines
  • Magnetic flow meters

Conclusion

We hope you have found this Water Flow Sensor Measure on a 16×2 LCD Display Circuit very useful. If you feel any difficulty in making it feel free to ask anything in the comment section.