Connect the sensor’s pulse output to an interrupt-capable Arduino input, count pulses while water flows, and convert the measured frequency using the factor for your exact sensor. For the common YF-S201 example, Seeed Studio specifies 450 pulses per liter, which gives a nominal flow rate of frequency in hertz divided by 7.5. That factor is not universal; calibrate the installed sensor against a measured volume before relying on its readings.
How does an Arduino water flow sensor work?
A common sensor such as the YF-S201 contains a rotor and magnet. Water turns the rotor, and the changing magnetic field triggers a Hall-effect sensor that emits electrical pulses. Arduino counts those pulses over time: pulse frequency indicates flow rate, while accumulated pulses estimate total volume. Seeed Studio explains this mechanism in its water-flow sensor guide.
As an Amazon Associate I earn from qualifying purchases.
What should you check before connecting it?
Confirm the model and read its own wiring and operating specifications before powering it. For the cited YF-S201 listing, HobbyTronics identifies red as supply, black as ground, and yellow as pulse output. Its listing gives an operating range of 5–18 V, with 4.5 V as the minimum tested, consumption up to 15 mA at 5 V, and a 5 V TTL output. It lists a flow range of 1–30 L/min, ±10% accuracy, and a maximum water pressure of 2.0 MPa. These are listing-specific specifications, not guarantees for every YF-S201 or other flow sensor. See the HobbyTronics YF-S201 specifications and verify that the output is safe for your particular Arduino input.
- A sensor that matches your expected flow range and plumbing connections.
- An Arduino input that supports the interrupt method you plan to use; interrupt-capable pins vary by board.
- Compatible supply and signal logic levels, plus a shared ground between sensor and Arduino.
- Any pipe adapters needed to match the sensor’s fittings to your plumbing.
A YF-S201 is one possible choice, not the only sensor design. For example, Seeed lists a different sensor with a 1–25 L/min range and a stated factor of F=(11 × Q), where Q is in L/min. The YF-S201 listing instead gives F=7.5 × Q. Check the exact model documentation rather than transferring a pulse factor or range from one sensor to another.
#1 Best Overall
- NPT Thread
- 1-30L/min
- The Water Flow Sensor is light, has a nimble outline, small, and is easy to install—the bearings used in the rotating part.
- There is an integrated magnetic hall effect sensor that outputs an electrical pulse with every revolution. The hall effect sensor is sealed from the water pipe and allows the sensor to stay safe and dry.
- Installed by flow direction in the product, otherwise, there is no signal output.
How do I connect a water flow sensor to Arduino?
For the cited YF-S201 wiring convention, connect its supply and ground leads as specified for your unit, then connect its pulse lead to an interrupt-capable digital input. Seeed’s ATmega328-based example and an Arduino Project Hub Uno Rev3 example use digital pin 2; other boards may assign interrupts differently. Check your board’s pin mapping before choosing a pin. See Seeed’s connection example and the Arduino Project Hub example.
- Turn off power while wiring. Connect sensor supply and ground according to the exact sensor documentation; connect sensor ground to Arduino ground.
- Connect the pulse output to a digital pin that supports the interrupt configuration for your board. Pin 2 is used in the cited Uno/ATmega328 examples, but is not universal.
- Check the sensor output voltage against the Arduino input’s allowed logic levels before connecting or powering the circuit.
- Upload the pulse-counting sketch below, open Serial Monitor at 9600 baud, and run water through the sensor to see whether counts increase.
How do I count pulses and calculate flow?
Use an interrupt handler to count rising edges, then read and reset the count in the main loop at a fixed interval. Seeed notes that polling repeatedly with digitalRead() can miss pulses when the program is busy; its example uses an interrupt and reports results over Serial at 9600 baud. This sketch follows that approach for an Uno-style board using pin 2 and the cited YF-S201 factor.
Rank #2
- ★Mainly used for water testing, water cooling system
- ★Application: Water heaters, credit card machines, water vending machine, flow measurement device
- ★High amplitude: ≥ 4.6V
- ★Low amplitude: ≤ 0.5V
- ★Electric strength: 1250V/min
volatile unsigned long pulseCount = 0;
unsigned long lastSample = 0;
const byte flowPin = 2;
void countPulse() {
pulseCount++;
}
void setup() {
Serial.begin(9600);
pinMode(flowPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(flowPin), countPulse, RISING);
lastSample = millis();
}
void loop() {
const unsigned long sampleMs = 1000;
unsigned long now = millis();
if (now - lastSample >= sampleMs) {
noInterrupts();
unsigned long pulses = pulseCount;
pulseCount = 0;
interrupts();
float seconds = (now - lastSample) / 1000.0;
float frequencyHz = pulses / seconds;
float flowLMin = frequencyHz / 7.5; // cited YF-S201 nominal factor
Serial.print("Flow: ");
Serial.print(flowLMin, 2);
Serial.println(" L/min");
lastSample = now;
}
}
The example assumes the pulse output is compatible with the board and that INPUT_PULLUP and rising-edge detection suit the particular sensor and wiring. If counts do not behave as expected, consult the sensor’s output specification and the board’s input requirements rather than treating these settings as universal.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
For the YF-S201 factor stated by Seeed Studio in 2022, 450 pulses represent one liter. If f is pulses per second (Hz), the nominal conversions are:
Rank #3
- The flow sensor mainly consists of a plastic valve body, a water flow rotor assembly, and a Hall sensor.
- The product has a lightweight and flexible appearance, small size, and is easy to install. The impeller is internally inlaid with stainless steel beads, which is wear-resistant. Design of lines and isolation from water.
- Valve body is made of transparent material to facilitate observation of water flow and rotor conditions. All raw materials meet testing standards.
- Working voltage range: black version DC3.5-12V; Transparent DC3.5-24V; Load capacity: ≤ 10 mA (DC 5V); Allowable pressure resistance water pressure below 1.75Mpa
- Scope of application: Suitable for water heaters, card readers, automatic water dispensers, and other flow metering equipment
- Flow in L/min: f ÷ 7.5.
- Flow in L/hour: f × 60 ÷ 7.5.
- Accumulated volume in liters: total pulses ÷ 450.
For example, 75 pulses per second corresponds to a nominal 10 L/min under that YF-S201 factor. A one-second sample is convenient for a display, but low flow may produce few pulses in that short interval, making readings coarse or jumpy. Averaging counts over a longer interval can provide a steadier estimate.
How do I calibrate a YF-S201?
The 450-pulses-per-liter figure is a nominal conversion, not a guaranteed result for every unit and installation. The YF-S201 listing describes the output as approximate and says careful calibration is needed for better than 10% precision. To calibrate, route a known measured volume through the installed sensor, record the pulse total, and calculate the installed factor:
Rank #4
- ★Food grade: Liquid passed through is safe to drink.
- ★G1/4 inch Quick-Connect: Easy installation and removal, suitable for 1/4" tube and works with most Reverse Osmosis filtration systems.
- ★Flow range:0.3-10L/min, working voltage range: DC 5-18V.
- ★Waterproof, heat resistance, pressure resistance, cold resistance.
- ★Sensor: Hall effect. Application:water heater thermostat, water purifier, boiler, water dispensers, coffee machines, smart card equipment, the boiler and so on.
calibrated pulses per liter = counted pulses ÷ measured liters
Free tools Windows power users keep installed
One-click scans. No signup required.
Use that measured factor in the volume calculation; for flow rate, derive a matching factor from pulse frequency and the measured flow or volume over time. Repeat the measurement if practical and use the same plumbing arrangement and operating conditions as the intended application. The available product and tutorial sources do not establish one calibration value that applies to all units.
Best Value
- Connect to G1/2 inch BSPT male thread, hall effect
- Flow range:1-30L/min, Water Pressure: ≤1.75Mpa
- Working voltage: DC 5-24 V, F=(7.5*Q)±2%, Q=L/Min
- Material: food grade plastic, all raw materials conform to the ROHS test standard
- Wide application: It is mainly used in water heater, coffee machine, water purifier, drinking fountain, beverage machine, campus smart card equipment, etc.
How should the sensor be installed in the plumbing?
Follow the instructions for the exact sensor version. For DFRobot’s Gravity YF-S201 guidance, the recommended setup uses a 20 mm rifled pipe, vertical installation tilted no more than five degrees, avoids corrosive chemicals, and limits liquid temperature to below 120°C. Those are product-specific recommendations; consult DFRobot’s Gravity YF-S201 documentation for that model and the manufacturer’s documentation for other versions.
Quick Recap
What should I check if readings are wrong?
- No pulses or a zero reading: Check sensor power, a shared ground, water movement through the sensor in the indicated direction, and the signal connection. Confirm the selected pin supports the configured interrupt and that the sensor’s output levels are compatible with the board.
- Implausible flow or volume: Verify the exact model and its pulse factor before changing the calculation. A factor for a different sensor can produce systematically wrong readings.
- Unsteady readings at low flow: Collect pulses over a longer interval to reduce the effect of small pulse counts in each sample.
- Persistent disagreement with a measured amount: Calibrate the installed sensor against a known volume and update the pulses-per-liter factor.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

