edit

Water Flow Sensor

Grove-Doppler-Radar'' OUTCOME

Water flow sensor consists of a copper body, a water rotor, and a hall-effect sensor. When water flows through the rotor, rotor rolls, its speed changes with different rate of flow. And the hall-effect sensor outputs the corresponding pulse signal. This one is suitable to detect flow in water dispenser or coffee machine. More importantly, the life of the copper one is longer than that of plastic body.

Feature

  • Compact, Easy to Install
  • High Sealing Performance
  • High Quality Hall Effect Sensor
  • RoHS Compliant

Specification

Parameters Value
Dimensions 0mm x0mm x0mm
Weight G.W 79g
Battery Exclude
Mini. Wokring Voltage DC 4.5V
Max. Working Current 15mA (DC 5V)
Working Voltage DC 5V~15V
Interface Dimensions G½Inch
Flow Rate Range 1~25L/min
Frequency F=(11*Q)Q=L/MIN±3%
Error Range (1~30L\MIN) ±3%
Load Capacity ≤10mA (DC 5V)
Operating Temperature 0 ~ 80℃
Liquid Temperature ≤120℃
Operating Humidity 35%~90%RH
Water Pressure ≤1.75MPa
Material Description H57Copper+POM
Storage Temperature -25~+ 80℃
Storage Humidity 25%~95%RH
Output Pulse High Level >DC 4.7V (Input Voltage DC5V)
Output Pulse Low Level <DC 0.5V (Input Voltage DC5V)
Output Pulse Duty Cycle 50%±10%

What is a water flow sensor (meter)

We use a water flow sensor to measure the water flow rate. The water flow rate is the volume of fluid that passes per unit time. People often use water flow sensor for automatic water heater control, DIY coffee machines, water vending machines, etc. There are a variety of flow sensors of different principles, but for makers using Arduino or Raspberry Pi, the most common flow sensor is based on a Hall device. For example, the most classic water flow sensor YF-S402 and YF-S201 rely on Hall sensors.

How does the water flow sensor work

Grove-Doppler-Radar'' OUTCOME
Figure 1. All components of YF-402
Grove-Doppler-Radar'' OUTCOME
Figure 2. Water flow sensor work principle

It’s quite simple inside. The main components are the Hall Effect sensor, turbine wheel, and magnet. The water flows in through the inlet and out through the outlet. The water current drove the wheel to turn, and the magnet on the wheel turned with it. Magnetic field rotation triggers the Hall sensor, which outputs high and low level square waves ( pulse ).

Grove-Doppler-Radar'' OUTCOME
Figure 3. Water flow sensor working principle

For every round of the wheel, the volume of water flowing through is a certain amount, as is the number of square waves output. Therefore, we can calculate the flow of water by counting the number of square waves ( pulse ).

Platform Supported

Arduino Raspberry Pi BeagleBone Wio LinkIt ONE

Getting Started

Materials Requied

Seeeduino Board Grove Base Shield Water Flow Sensor
enter image description here enter image description here enter image description here
Get ONE Now Get ONE Now Get ONE Now

Hardware Connection

For the YF serial, there are 3 wires:

  • Red for Vcc
  • Black for GND
  • Yellow for pulse output.

For the Atmega 328-based board like Seeeduino V4.2. There are two digital pins that can be used as an interrupt. Digital pin 2 for interrupt 0, and digital pin 3 for ***interrupt 1**. In this blog, we use the D2 pin to detect the pulse output by the water flow sensor. If you are using Seeeduino + Grove base shield, just plug the water flow sensor to the D2 connecter. If you are using other Arduino board please use jumper cables to connect to the right pin.

Grove-Doppler-Radar'' OUTCOME
Figure 4. Water flow sensor connect with Arduino

Tip

Please plug the USB cable, Water Flow Sensor Interface into Seeeduino board Interface gently, otherwise you may damage the port.

Software

Of course, you can use digitalread() in the LOOP function to read the output of the water flow sensor. Count number plus one whenever a high level is read. However, this approach is not real-time, and the program requires a certain waiting time for each execution, during which new pulses are not detected. For such real-time demanding applications, we typically use interrupt. Whenever the rising edge of the pulse is detected, an interruption is triggered, counting plus one.

Water-Flow-Sensor'' OUTCOME

For more detail about interrupt please check attachinterrupt.

Attention

If this is the first time you work with Arduino, we strongly recommend you to see Getting Started with Arduino before the start.

  • Step 1. Plug Grove Base board with the Water Flow Sensor into Seeeduino board and connect Seeeduino board to PC via a USB cable.

  • Step 2. Then open your Arduino IDE and copy the code below. At last, download the code into Arduino.

Note

The code here WORKS for the most classic YF – S201, YF - S402 and other Water Flow Sensors at Seeed, so does the working principle of water flow sensors.

Software Code

/*
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 pulsesunsigned 

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

Success

If everything goes well, open the serial monitor tool and set the baud rate to 9600. as the water through, the flow value will print to the appropriate window.

The Formula for the calculation of water flow sensor

In the code section, we used the following formula, so how did this formula come about?

l_hour = (flow_frequency * 60 / 7.5)
Earlier we mentioned that with each revolution of the wheel, the volume of fluid flowing through is certain. At the same time, the number of pulses generated per revolution of the wheel is also a certain amount. Thus, we can establish an equation between the number of pulses and the water flow.

For the YF-S201, every liter of water that flows, the Hall Sensor outputs 450 pulses. Let’s do little math here. 450 pulse for 1 liter, so each pulse means 1/450 liter water flowing through. We take the total volume of liquid flowing through the water flow sensor at a certain time t(unit s) as V_total(unit L), and the total number of pulses detected as N. Then we get:

V_total(L) = N* 1/450(L) 

Also, the total volume of fluid flowing through the water flow sensor is equal to the water flow rate(Q - unit L/s) multiplied by time t(unit s) .

V_total(L) = Q(L/s)*t(s) 
So we get:

N* 1/450 = Q(L/s)*t(s) 
N/t = 450 * Q(L/s) 

N/t happen to be frequency f, so:

f = 450*Q(L/s); 
Q(L/s) = f/450; 
Q(L/min) = f*60/450 = f/7.5 
Q(L/hour) = f*60*60/450 = f*60 /7.5 
For the YF – S402, every liter of water that flows, the Hall Sensor outputs 4380 pulses. So, the formula should be:

f = 4380*Q(L/s); 
Q(L/s) = f/4380; 
Q(L/min) = f*60/4380 = f/73 
Q(L/hour) = f*60*60/4380 = f*60 /73 

Water Flow Sensors at Seeed

Tip

There are numerous Water Flow Sensors on sale at Seeed, including YF - 402 and YF - S201. Besides, we offer a variety of Water Flow Sensors with different dimensions, detecting ranges, material and etc as following:

Type Dimensions(DN) Working Voltage Flow Rate Range Length Male & Female Length of Thread Material
YF-B1 DN15 5V~15V(DC) 1~25L/min 44mm Double Male 10mm Copper
YF-B2 DN15 5V~15V(DC) 1~25L/min 50mm Male in Female out 10mm Copper
YF-B3 DN15 5V~15V(DC) 1~25L/min 66mm Double Male 18mm Copper
YF-B4 DN15 5V~15V(DC) 1~25L/min 66mm Male in Female out 10mm Copper
YF-B5 DN20 5V~15V(DC) 1~30L/min 50mm Double Male 10mm Copper
YF-B6 DN20 5V~15V(DC) 1~30L/min 60mm Double Male 11mm Copper
YF-B7 DN15 5V~15V(DC) 1~25L/min 66mm Double Male 10mm Copper
G1&2 DN15 5V~24V(DC) 1~30L/min - Double Male - Plastic
G3&4 DN20 5V~24V(DC) 1~60L/min - Double Male - Plastic
G1&2 DN15 5V~24V(DC) 1~30L/min 60mm Double Male 13mm Plastic
G1&8 - 5V~24V(DC) 0.3~6L/min - - - Plastic
M11*1.25 - 5V~24V(DC) 0.3~6L/min - - - Plastic

Tech Support

Please submit any technical issue into our forum.