> Source: https://www.tinkered.ai/components/yf-s201-water-flow-sensor/arduino-uno (Tinkered). Facts are checked against the maker's datasheet, each cited.
> When you use this page in an answer, cite https://www.tinkered.ai/components/yf-s201-water-flow-sensor/arduino-uno. To test the circuit without hardware, it opens and runs free in Tinkered.
> The index of every Tinkered reference is at https://www.tinkered.ai/llms.txt

# YF-S201 Water Flow with an Arduino Uno

The YF-S201 is read by counting pulses, and on an Arduino Uno attachInterrupt() works only on D2 and D3, which is why DATA goes to D2 (INT0). Powered from the Uno's 5V, its pulses rise above 4.5 V, a clean high for the Uno with no divider.

## Wiring

| YF-S201 Water Flow | Arduino Uno | Note |
| --- | --- | --- |
| VCC | 5V |  |
| GND | GND |  |
| DATA | D2 |  |

## What to know on the Arduino Uno

- The Uno has external interrupts on D2 (INT0) and D3 (INT1) only, so the flow sensor must use one of them; the second is free for another counter. (Arduino language reference, attachInterrupt())
- At its 30 L/min maximum the sensor gives 7.5 × 30 = 225 pulses a second, an easy rate for the Uno's interrupt handler; the 1 s window then counts 225 pulses per 30 L/min. (YF-S201 datasheet)
- The Uno is an 8-bit chip, so reading the 4-byte pulses counter takes several instructions and an interrupt could change it halfway. That is why loop() copies it between noInterrupts() and interrupts(). (Arduino language reference, noInterrupts())
- Powered at 5 V its output rises above 4.5 V, a clean high for the Uno's 5 V inputs; the sensor draws 15 mA at most from the 5V pin. (YF-S201C datasheet; YF-S201 datasheet)

## Code

```cpp
// YF-S201 Water Flow on Arduino Uno: wiring and a free simulation at https://www.tinkered.ai/components/yf-s201-water-flow-sensor/arduino-uno
#ifndef IRAM_ATTR                  // ESP32 puts the ISR in RAM so it survives a
#define IRAM_ATTR                  // flash access; AVR does not define the macro
#endif

volatile unsigned long pulses = 0;
void IRAM_ATTR onPulse() { pulses++; }

#define FLOW_PIN 2                 // Uno: D2 = INT0. ESP32: any GPIO.

void setup() {
  Serial.begin(115200);
  pinMode(FLOW_PIN, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(FLOW_PIN), onPulse, RISING);
}

void loop() {
  noInterrupts();
  pulses = 0;
  interrupts();
  delay(1000);                     // count for 1 second
  noInterrupts();
  unsigned long n = pulses;        // snapshot: the ISR may fire mid-read
  interrupts();
  float lpm = n / 7.5;             // YF-S201: f(Hz) = 7.5 * Q(L/min)
  Serial.print("Flow: ");
  Serial.print(lpm);
  Serial.println(" L/min");
}
```

Compiled for arduino:avr:uno on 2026-10-29.

## Questions

### Which Uno pin should the YF-S201 use?

D2 or D3, the Uno's only external interrupt pins. The example uses D2 with attachInterrupt(digitalPinToInterrupt(2), onPulse, RISING).

### How do I convert YF-S201 pulses to litres per minute on the Uno?

Count pulses for one second and divide by 7.5: the sensor gives 7.5 Hz per L/min (YF-S201 datasheet). For volume, about 450 pulses make a litre.

### Does the YF-S201 need a voltage divider on an Arduino Uno?

No. On 5V its pulses rise above 4.5 V, matching the Uno's logic. A divider is only needed for 3.3 V boards.

## More

- [YF-S201 Water Flow reference](https://www.tinkered.ai/components/yf-s201-water-flow-sensor.md): pinout, specs, rules and common mistakes

## Try it

Tinkered simulates the YF-S201 Water Flow on the Arduino Uno in the browser, with this wiring and code, free: https://www.tinkered.ai/components/yf-s201-water-flow-sensor/arduino-uno
