


The YF-S201 is a type of water flow sensor that is often used in various projects to measure the flow rate of liquids, such as water. It uses a Hall effect sensor to detect the flow of water through the pipe and generates pulses corresponding to the flow rate.
Here’s a simple example to measure flow rate using Arduino:
int flowPin = 2; // Pin where the signal wire is connected
volatile int flowCount = 0;
float flowRate = 0.0;
unsigned long lastTime = 0;
void setup() {
Serial.begin(9600);
pinMode(flowPin, INPUT);
attachInterrupt(digitalPinToInterrupt(flowPin), countPulse, RISING);
}
void loop() {
unsigned long currentTime = millis();
if (currentTime - lastTime >= 1000) { // Update every second
flowRate = flowCount; // Flow rate in pulses per second (Hz)
Serial.print("Flow rate: ");
Serial.print(flowRate);
Serial.println(" pulses/second");
flowCount = 0;
lastTime = currentTime;
}
}
void countPulse() {
flowCount++;
}
This code counts the pulses from the flow sensor, which is connected to a digital pin of the Arduino. The flow rate in pulses per second is then printed every second.
Origin:- China
Brand:- Generic