Skip to main content

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.


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


Dimensions0mm x0mm x0mm
WeightG.W 79g
Mini. Wokring VoltageDC 4.5V
Max. Working Current15mA (DC 5V)
Working VoltageDC 5V~15V
Interface DimensionsG1/2Inch
Flow Rate Range1~25L/min
Error Range(1~30L\MIN) ±3%
Load Capacity≤10mA (DC 5V)
Operating Temperature0 ~ 80℃
Liquid Temperature≤120℃
Operating Humidity35%~90%RH
Water Pressure≤1.75MPa
Material DescriptionH57Copper+POM
Storage Temperature-25~+ 80℃
Storage Humidity25%~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 Cycle50%±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

ArduinoRaspberry Pi

Getting Started

Materials Requied

Seeeduino BoardGrove Base ShieldWater Flow Sensor
enter image description hereenter image description hereenter image description here
Get ONE NowGet ONE NowGet 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
Please plug the USB cable, Water Flow Sensor Interface into Seeeduino board Interface gently, otherwise you may damage the port.


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.


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.


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:

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


void setup()
pinMode(flowsensor, INPUT);
digitalWrite(flowsensor, HIGH); // Optional Internal Pull-Up
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");

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


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:

TypeDimensions(DN)Working VoltageFlow Rate RangeLengthMale & FemaleLength of ThreadMaterial
YF-B1DN155V~15V(DC)1~25L/min44mmDouble Male10mmCopper
YF-B2DN155V~15V(DC)1~25L/min50mmMale in Female out10mmCopper
YF-B3DN155V~15V(DC)1~25L/min66mmDouble Male18mmCopper
YF-B4DN155V~15V(DC)1~25L/min66mmMale in Female out10mmCopper
YF-B5DN205V~15V(DC)1~30L/min50mmDouble Male10mmCopper
YF-B6DN205V~15V(DC)1~30L/min60mmDouble Male11mmCopper
YF-B7DN155V~15V(DC)1~25L/min66mmDouble Male10mmCopper
G1&2DN155V~24V(DC)1~30L/min-Double Male-Plastic
G3&4DN205V~24V(DC)1~60L/min-Double Male-Plastic
G1&2DN155V~24V(DC)1~30L/min60mmDouble Male13mmPlastic

Tech Support & Product Discussion

Thank you for choosing our products! We are here to provide you with different support to ensure that your experience with our products is as smooth as possible. We offer several communication channels to cater to different preferences and needs.

Loading Comments...