Component guide · Beginner · 3 min read
Water Flow Sensors (YF-S201)

Wiring and Code
By Geekobot Learning Team · Updated 24 Oct 2026
On this page
A water flow sensor such as the YF-S201 has a small turbine with a magnet. Each turn passes a hall sensor that outputs a pulse, so the pulse rate is proportional to flow. Common datasheets give roughly 7.5 Hz per litre per minute, or about 450 pulses per litre, but each sensor differs. Count pulses with an interrupt and calibrate with a measuring jug for good accuracy.
Key specs at a glance
- Supply
- About 5 to 18 V; 5 V works with Arduino
- Output
- Open-collector pulses (pull-up needed if none on board)
- YF-S201 range
- About 1 to 30 L/min, G1/2 inch thread
- Pulse factor
- About 7.5 pulses per second per L/min (calibrate)
- Wires
- Red +V, black GND, yellow signal
- Accuracy
- Typically within ±10 % uncalibrated; better after calibration
Wiring
Connect red to 5 V, black to GND and yellow to an interrupt pin (D2 on an Uno). If the module has no pull-up, add a 10 kΩ pull-up to your logic voltage. For a 3.3 V board, pull up to 3.3 V instead of 5 V; the hall sensor output only pulls low, so this is safe on most versions. Check yours with a meter first.
Code for flow rate and total litres
Count pulses in an interrupt and convert once a second.
const byte PIN = 2;
const float PULSES_PER_LITRE = 450.0; // calibrate this
volatile unsigned long pulses = 0;
float totalLitres = 0;
void onPulse() { pulses++; }
void setup() {
Serial.begin(9600);
pinMode(PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(PIN), onPulse, FALLING);
}
void loop() {
delay(1000);
noInterrupts(); unsigned long n = pulses; pulses = 0; interrupts();
float litres = n / PULSES_PER_LITRE;
totalLitres += litres;
Serial.print(litres * 60.0); Serial.print(" L/min, total ");
Serial.print(totalLitres); Serial.println(" L");
}Calibrating and fitting
- 1Run water through the sensor into a measuring jug and record the total pulses for, say, 2 litres.
- 2Divide pulses by litres and use that number in your code.
- 3Fit the sensor with the arrow in the flow direction and the turbine horizontal. Use PTFE tape on threads.
- 4Air bubbles, very low flow and debris all reduce accuracy; add a strainer before it.
- 5These sensors are not rated for drinking-water approval or billing. For hot water or food use, choose a sensor rated for it.
Common mistakes to avoid
- Using the datasheet pulse factor without calibrating.
- Fitting the sensor backwards against the arrow.
- Polling the pin instead of using an interrupt.
- Pulling the signal up to 5 V on a 3.3 V board.
- Using it below its minimum flow and getting no pulses.
Frequently asked questions
How many pulses per litre does a YF-S201 give?
About 450 in common datasheets, but calibrate yours with a jug.
Can I use it with ESP32?
Yes. Pull the signal up to 3.3 V and use any GPIO with an interrupt.
Does it work with hot water?
Standard plastic versions are rated for modest temperatures. Check the datasheet for the limit.
Why does it read zero at low flow?
The turbine needs a minimum flow to spin, about 1 L/min for the YF-S201.
Can I measure diesel or oil?
Not with a standard water sensor. Viscous or flammable fluids need a meter rated for them.
Parts for this guide
Search the store for the parts named above, or ask Geeko AI which one fits your project.
Terms in this guide
Projects that use it
Put this into practice: 20 step-by-step builds in our project library use parts from this guide.
Keep learning
Sources
Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.
