Arduino Projects

Water Flow Sensor Arduino, Water Flow Rate & Volume Measurement

Description:

 

Water Flow Sensor Arduino, Water Flow Rate & Volume Measurement- In this Tutorial, you will learn how to accurately measure the Water Flow Rate and Water volume using the Water Flow Sensor YF-S401, Arduino UNO, and a 12v DC Water Pump.

Working on the Water Flow Sensor is a bit tricky whether you are using YF-S401 or YF-S201 Hall Effect Water Flow Sensor, and that’s the reason, most of the people complain about the wrong values. There are things that we need to take care of while using the Water Flow Sensor.  As per the datasheet, when water flows through the rotor, rotor rolls. Its speed changes with different rate of flow. If we can keep the pressure and flow constant we can make an accurate water volume measurement system. I solved this problem by using a 12v Water Pump.

allpcb circuit

In this tutorial, I will also explain what’s inside a Water Flow Sensor and how it works. I will also explain the complete circuit diagram, making, and Arduino programming.

Without any further delay, let’s get started!!!

You can also ready my article on IoT based Water level monitoring and automatic water pump control system using the ESP32 WiFi + Bluetooth Module, Waterproof Ultrasonic Sensor, and the New Blynk V2.0 more…

Note: For the step by step explanation and practical demonstration watch video given at the end of this article.

Amazon Links:

Arduino Nano USB-C Type (Recommended)

Water Flow Sensor YF-S401:

Water Flow Sensor YF-S201:

12v DC water pump

12v Adaptor:

Arduino Uno

*Disclosure: These are affiliate links. As an Amazon Associate I earn from qualifying purchases.



About the YF-S401 Water Flow Sensor:

Water Flow Sensor Arduino

This is the Water Flow Sensor which consists of a PVC body. This Water Flow Sensor is suitable to detect flow in water dispensers, water heaters, gardening or coffee machines.

Features:

Compact, Easy to Install

High Sealing Performance and this Water Flow Sensor has a High-Quality Hall Effect Sensor.

Specification:

Model: YF-S401

  • Working Voltage: DC 4.5V
  • Working Current: 15mA (DC 5V)
  • Working Voltage: DC 5V~24V
  • Water resistant 0.35MPa
  • Flow Rate Range: .3~ 6L/min
  • Load Capacity: ≤10mA (DC 5V)
  • Operating Temperature: ≤ 80C
  • Liquid Temperature: ≤120C
  • Operating Humidity: 35% 90%RH
  • Water Pressure: ≤ .8MPa
  • Storage Temperature: -25 + 80C
  • Storage Humidity: 25% 95%RH
  • Internal diameter: 1.2mm;
  • Error: +/-2L/min;
  • Insulation resistance > 100M ohm
  • Output pulse duty cycle 50% ± 10%
  • Output pulse high level > DC 4.7V (input voltage DC 5V)
  • Flow pulse characteristics F = (98 * Q) ± 2% Q = L / MIN


Download Water Flow Sensor Datasheet: yf-s401water flow sensor datasheet

As you can see in the picture above, this Sensor has a total of three wires, Red, Black, and Yellow. The Red wire will be connected with the Arduino’s 5 Volts, the Black wire will be connected with the ground and Yellow wire which is the signal wire will be connected with the Arduino’s pin number 2, which is the interrupt pin.

Water Flow Sensor Arduino

On the backside of this Water Flow Sensor, as you can see there is an arrow that shows the direction of the flow of water. So this side is the Inlet and this side is the Outlet.

Now let’s check what we have got inside this Sensor, and how this sensor actually works.

Inside this Water Flow Sensor, we have a high-quality Hall Effect Sensor. This sensor also has a rotor which rotates as the water flows from the inlet opening to the outlet opening. This rotor has a magnet which gives pulses to the Hall Effect Sensor. The flow of water or any other liquid should be in the direction of the Arrow.

The Water Flow Sensor for the Flow Rate and Volume Measurement using Arduino Uno, Mega or any other microcontroller board works on the principle of the Hall Effect.


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.

Water Flow Sensor Arduino Connection Diagram:

Water Flow Sensor Arduino

This schematic is designed in the Cadsoft eagle 9.1.0 version. If you want to learn how to make a schematic and PCB then watch my tutorial.

As you can see the connections are very simple. J1 is a female power jack and this is where we connect a 12v adaptor or battery. The 12 volts are used to run the 12v DC water Pump. The ground is directly connected with the Water Pump while the 12 volts are connected with the Water Pump through a Pushbutton.

The Water Flow Sensor 5v pin is connected with the Arduino’s 5 volts, the Ground pin of the Water Flow Sensor is connected with the Arduino’s ground and the signal wire is connected with the Arduino’s pin number 2 which is the interrupt pin. So for the pulses counting we will be using the Arduino’s Hardware Interrupt 0.


Making:

Water Flow Sensor Arduino

The complete making of the whole setup is explained in the video tutorial given at the end of this article. A pipe from the bottle is connected with the inlet valve of the 12v DC Water Pump and the outlet opening of the 12v DC Water Pump is connected with the inlet opening of the Water Flow Sensor. The 12v DC Water Pump is controlled using a Pushbutton. The three wires of the Water Flow Sensor YF-S401 will be connected with the Arduino. These three wires are connected as per the circuit diagram already explained.



Water Flow Sensor YF-S401 Arduino Programming:


Water Flow Sensor Arduino Program explanation:

The programming is very simple it’s just like the tachometer programming with some modifications. In this project, I have used the Arduino’s Hardware Interrupt 0 which is available on pin number 2. I have also defined a pin for the Solenoid valve, which you can use.

As in this project, I am only covering the basics, so, that’s why I didn’t add any LCD. Adding a 16×2 LCD is very simple; you can watch my videos on how to use the 16×2 LCD. For now, I will display values on the Serial Monitor.

 The rest of the program is well commented.

Water Flow Sensor Arduino Tests:

While the Arduino is connected with the Laptop open the Serial Monitor. When you open the serial monitor you will see 0mL. For the water measurement, I will be using a feeder which is marked with 20, 40, and 60mL.

Water Flow Sensor Arduino  Test 1:

Water Flow Sensor Arduino

As you can see the measured volume is 38mL. This Water Flow Sensor is simply amazing and highly accurate.

Now let’s perform another test and make sure you reset the Arduino. Later you can use a button to reset the value, instead of resetting the Arduino every time.


Water Flow Sensor Arduino Test2:

Water Flow Sensor Arduino

As you can see this is exactly 50mL, it’s simply amazing, the precision is really cool. I am really satisfied with this sensor.

For more tests watch the video tutorial given below. I successfully performed all the tests.


Watch Video Tutorial:

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Related Articles

10 Comments

  1. I have doubt in water flow meter calculation.
    How you get 98 Hz ??

    my question is that everytime 1000ml will have different pulse count .
    if water flow is high then pulse count may increase beyond 5880 pulse .
    if water flow is medium then pulse count can be between 5500-5800 or less like wise.

    So how to get exact Calibration factor for water flow sensorif its not mentioned in datasheet also.

    Your calculation is bit confusing for me.

  2. Rahul even i have the same doubt and the developer have mentioned in value in code i dont know how to get that value float calibrationFactor = 90;

  3. I could not get any data in a ESP32, so I ‘ve searched and find this : https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/.

    So I have changed code this way:
    // commented this –> attachInterrupt(sensorInterrupt, pulseCounter, FALLING); //you can use Rising or Falling
    //changed to …

     attachInterrupt(digitalPinToInterrupt(sensorPin), pulseCounter, FALLING); //you can use Rising or Falling
    

    //note that ‘sensorInterrupt’ (=0) variable is no longer used. Change all appearances of ‘sensorInterrupt’ by ‘digitalPinToInterrupt(sensorPin)’ to use it in ESP32.

    digitalPinToInterrupt links pin to Interrupt without explicitly naming the Interrupt.

    Now it works.

  4. Hi,

    can you please check what is the pin pitch of the JST connector of the flow sensor. Is it 2mm or 2.54mm?
    I can’t find that info on the datasheet.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button