Water flow sensor, YF-S201

A pipe section with a magnet on a pinwheel and a Hall sensor outside it, and three wires. Aliases: YF-S201, Hall flow meter, water flow meter.

Water through the pipe turns the wheel, and each turn passes the magnet by the Hall sensor, which pulls SIG low and lets it go: a square wave whose frequency is the flow. The sketch counts the pulses on an interrupt and divides.

Pins

Pin What it does
VCC Supply, 5 V to 18 V, the red wire.
GND Ground, the black wire.
SIG The pulses, the yellow wire.

Properties

flow is the flow it starts with, in liters a minute, 0 to 30.

While it runs

The slider is the flow through the pipe, and the wheel in the window turns with it.

What the model gets right

From the listings, which are all the paperwork there is:

The formula. F = 7.5 x Q: the pulses a second for a flow of Q liters a minute. So 450 pulses make a liter, which is the number a water meter sketch divides by.

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.

The range. 1 to 30 liters a minute.

What it does not model

A real sensor's accuracy, about 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.

Common mistakes

Powering it from 12 V with SIG straight into a 5 V board: the pull-up inside goes to VCC, so the pulses then reach 12 V. Run it from 5 V.

Counting pulses in loop() with digitalRead(). At 30 L/min that is 225 pulses a second; use attachInterrupt().

See it in action

Water meter shows the flow and the liters so far on an I2C LCD. Open it at /templates.