Part

Water flow sensor, YF-S201

A pinwheel and a Hall sensor in a pipe: SIG pulses 7.5 times a second per liter a minute. Also the YF-S401, YF-B10 and YF-DN50.

See every part
  • 3 pins
  • 2 settings
  • In 2 projects
  • In 1 lesson
Drawn live by the editor's own code, at the size you see it.
Water flow sensor, YF-S201 as drawn in the Mokxi simulator
At a glance

The Water flow sensor, YF-S201 in brief

What it is, and every setting the properties panel gives it.

The YF-S201 is a Hall effect water flow sensor: a pinwheel in a pipe pulses SIG as the water turns it, 7.5 pulses a second for every liter a minute, which is 450 pulses a liter. The pins are VCC, 5 V to 18 V, GND and SIG. The model property also offers the YF-S401, the brass YF-B10 and the YF-DN50, each with its own formula, and the flow property is the flow it starts with in liters a minute. SIG is high over 4.5 V and low under 0.5 V on 5 V, 50 percent duty, an open collector with a 10 k pull-up to VCC inside. The slider in the window sets the flow and the wheel turns with it. Real accuracy of 3 to 10 percent is not modeled.

Family
Sensors
Pins
3
model
YF-S201 (or YF-S401, YF-B10, YF-DN50)
flow
0
Pins

3 pins

Named as the editor names them, so a wire lands where you expect it.

Pin
What it does
VCC
Supply, the red wire: 5 V to 18 V on a YF-S201, 5 V to 12 V on a YF-S401, 3.5 V to 24 V on a YF-B10 or YF-DN50.
GND
Ground, the black wire.
SIG
The pulses, the yellow wire.
How to use it

How to read a YF-S201 water flow sensor with an Arduino

VCC goes to the Uno’s 5 V, GND to ground and SIG to pin 2, which is an interrupt pin. The sensor makes 7.5 pulses a second for each liter a minute, so a sketch counts the pulses on an interrupt and divides. Do not count them in loop() with digitalRead(): at 30 L/min the sensor makes 225 pulses a second.

This sketch counts falling edges, and once a second turns the new pulses into the flow, pulses a second times 2/15 in L/min, and the total, 450 pulses to the liter. A 16x2 LCD on its I2C backpack, SDA on A4 and SCL on A5, shows both. Drag the flow slider and the wheel and the numbers follow.

Part pin
Board pin
VCC
5V
GND
GND
SIG
Pin 2

The pull-up inside goes to VCC, so SIG swings to whatever you power the sensor from. From 12 V it puts 12 V pulses on a board pin, so run it from 5 V.

Water meterlive0.000 s 0.00x
Click to open it in the editor
This is the simulator itself, running here. Click anything to open it in the editor.
Count pulses on an interrupt
const int SENSOR = 2;
volatile unsigned long pulses = 0;
unsigned long counted = 0;
unsigned long lastSecond = 0;

void onPulse() {
  pulses++;
}

void setup() {
  Serial.begin(115200);
  pinMode(SENSOR, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(SENSOR), onPulse, FALLING);
  lastSecond = millis();
}

void loop() {
  if (millis() - lastSecond < 1000) return;
  lastSecond += 1000;
  noInterrupts();
  unsigned long all = pulses;
  interrupts();
  unsigned long thisSecond = all - counted;
  counted = all;
  unsigned long tenths = thisSecond * 4 / 3;   // tenths of a liter a minute
  unsigned long ml = all * 20 / 9;             // 450 pulses a liter
  Serial.print("flow ");
  Serial.print(tenths / 10);
  Serial.print('.');
  Serial.print(tenths % 10);
  Serial.print(" L/min, total ");
  Serial.print(ml);
  Serial.println(" ml");
}
Common errors

Common Water flow sensor, YF-S201 errors and fixes

What goes wrong
The fix
The count is far too low.
Counting in loop() with digitalRead() misses pulses. Use attachInterrupt() on pin 2 or 3.
The flow is wrong for a different sensor.
Each model has its own factor: F = 7.5 x Q on the YF-S201, 98 x Q on the YF-S401, 8 x Q minus 4 on the YF-B10 and 0.2 x Q on the YF-DN50.
SIG reaches 12 V.
The pull-up inside goes to VCC. Powered from 12 V, SIG pulses to 12 V, so run it from 5 V.
Questions

Questions and answers

How many pulses a liter does the YF-S201 make?

450, since the frequency in hertz is 7.5 times the flow in liters a minute.

What flow range does the YF-S201 measure?

1 to 30 liters a minute.

Which Arduino pin should the flow sensor use?

An interrupt pin, 2 or 3 on an Uno, so each pulse is counted with attachInterrupt().

How it is modeled

What is true about the Water flow sensor, YF-S201, here

In its help article’s own words: what the simulation gets right, and where it stops.

Modeled

From the spec sheets and listings, which are all the paperwork there is:

Model Pipe Formula (F in Hz, Q in L/min) Pulses a liter Range
YF-S201 G1/2 F = 7.5 x Q 450 1 to 30 L/min
YF-S401 1/8 inch F = 98 x Q 5880 0.3 to 6 L/min
YF-B10 G1, brass F = 8 x Q - 4 about 476 2 to 50 L/min
YF-DN50 G2 F = 0.2 x Q 12 10 to 200 L/min

The YF-S401's figures are DFRobot's (SEN0216). The YF-B10's are the SEA listing's and most sellers'; an older one-page sheet gives 6 x Q - 8, so calibrate a real one. Under 0.5 L/min its formula gives no pulses, and neither does the model.

The output. High over 4.5 V and low under 0.5 V on 5 V, 50% duty: an open collector with a pull-up inside, here 10 kohm to VCC (an assumption). A sketch's own INPUT_PULLUP changes nothing.

Not modeled

A real sensor's accuracy, 3 to 10% (the model's pulses are exact, so calibrate a real one with a measuring jug); the low flow at which a real wheel stops turning; the water pressure; and a wheel that spins on for a moment after the tap closes.

From Water flow sensor, YF-S201, in full.

Projects

See the Water flow sensor, YF-S201 in a project

2 built-in projects use it. Each opens in the editor, already wired.

Lessons

Where it turns up in a lesson

One lesson places it in its own circuit.

Boards

The boards it is shown on

This board has a built-in project with the Water flow sensor, YF-S201 in it.

Wire up the Water flow sensor, YF-S201

Open the editor and push it into the breadboard. It is free, and it runs on your own machine.