Skip to content

Fluid / Flow · Arduino Uno guide

Interfacing YF-S201 Water Flow Sensor with Arduino Uno

Measures liquid flow rate for smart water meters and irrigation systems.

Updated November 14, 2026 Arduino C++None — built-in attachInterrupt()

YF-S201 practical reference

The YF-S201 is a Hall-effect water flow sensor built around a small plastic turbine: as water flows through the housing, the internal rotor spins and a Hall sensor generates a pulse train whose frequency is proportional to the flow rate. It's the standard low-cost sensor for DIY water meters, irrigation controllers, and smart plumbing projects, letting a microcontroller calculate liters-per-minute simply by counting pulses per second.

Key specifications

  • Sensor type: Hall-effect turbine flow sensor
  • Operating voltage: 5 V–24V DC (5V is standard for microcontroller projects)
  • Operating current: ~15 mA
  • Flow rate range: 1–30 liters per minute
  • Output: Digital pulse train, frequency proportional to flow rate
  • Pulse-to-flow formula: Frequency (Hz) ≈ 7.5 × flow rate (L/min), per manufacturer datasheet
  • Max working pressure: ~1.75 MPa
  • Pipe fitting: 1/2 inch (G1/2) threaded connections, inline installation
  • Interface: Single digital pin, read via pulse counting or an interrupt

Pinout and connection notes

Attach the signal wire to an interrupt-capable pin and count pulses over a fixed time window (e.g. 1 second) to compute flow rate using the ~7.5 pulses-per-liter-per-minute constant from the datasheet; because the sensor is a mechanical turbine, always install it with the flow direction arrow molded into the housing matching the actual water flow direction.

  • Red (VCC): Power, 5–24V DC
  • Black (GND): Ground
  • Yellow (Signal): Pulse output — connect to a digital input pin, ideally interrupt-capable

Integration checklist

  1. Confirm the exact part number and breakout-board revision.
  2. Verify supply voltage, current demand, logic levels, and signal direction against the datasheet.
  3. Check controller pin assignments and bus address or interface mode against the example code.
  4. Power up with external loads disconnected, then test signals before full integration.
  5. If readings or communication fail, check power and ground first, then pin mapping, interface settings, and library initialization.

Troubleshooting and reproducibility

Record the board used, wiring, library/version, supply arrangement, and measured behavior. Use the selected board-specific wiring example as the source of truth. Never assume visually similar modules share identical voltage tolerance or pin order.

Flow calibration and installation checks

The pulse-to-volume relationship is specific to the sensor, rotor, fluid path, and operating range. Treat a published pulses-per-litre factor as a starting point, not a guarantee for every unit. Collect a known volume at a steady flow, count pulses over the same interval, and calculate a calibration factor for that sensor and plumbing arrangement. Repeat at more than one flow rate if accuracy across the range matters.

Mount the sensor in the direction shown by its body arrow and follow the manufacturer's requirements for pipe orientation, pressure, filtration, and water quality. Trapped air, turbulence, debris, leaks, and a partially blocked rotor can change the pulse rate. Secure plumbing so hose movement does not stress the sensor body or electrical leads.

For a microcontroller, count pulses with an interrupt or hardware counter and keep the interrupt routine short. Use a suitable pull-up and confirm the output voltage is safe for the selected GPIO; output stages and cable lengths vary. If the count is zero, check supply, ground, signal pin, pull-up, and actual water flow. If the count is noisy, inspect grounding, cable routing, interference, and pulse filtering before changing calibration. This is not a certified billing meter or leak-protection device.

Wiring & code

Setting up YF-S201 with Arduino Uno

Library

None — built-in attachInterrupt() by —

No library needed; uses core Arduino interrupt functions.

Wiring

Component pinArduino Uno pinNote
Red (VCC)5V
Black (GND)GND
Yellow (Signal)D2Hall-effect pulse output — must use an interrupt-capable pin (2 or 3 on the Uno).
sketch.ino
#include <Arduino.h>
#define FLOW_PIN 2

volatile unsigned long pulseCount = 0;

void countPulse() {
  pulseCount++;
}

void setup() {
  Serial.begin(9600);
  pinMode(FLOW_PIN, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(FLOW_PIN), countPulse, FALLING);
}

void loop() {
  static unsigned long lastMillis = 0;
  if (millis() - lastMillis >= 1000) {
    noInterrupts();
    unsigned long count = pulseCount;
    pulseCount = 0;
    interrupts();
    lastMillis = millis();

    // YF-S201 datasheet constant: frequency (Hz) ≈ 7.5 * flow rate (L/min)
    float flowLpm = count / 7.5;
    Serial.print(F("Flow: ")); Serial.print(flowLpm);
    Serial.println(F(" L/min"));
  }
}
  • The 7.5 pulses-per-litre-per-minute constant is the commonly cited YF-S201 datasheet figure, but individual units vary — for billing-grade or dosing-critical accuracy, calibrate against a known measured volume rather than trusting the constant as-is.
  • Must use pin 2 or 3 on an Uno (the only interrupt-capable pins) — polling this signal in the main loop instead of using an interrupt will miss pulses at any meaningful flow rate.
  • Rated for water only, up to about 120psi and 80°C — check the datasheet before using with other liquids or high-pressure lines.

Keep learning

Related guides & projects