The YF-S201 Water Flow Meter is an electronic sensor designed to measure the rate of water flow through a pipe. It operates by using a rotor that spins in response to water flow, with a hall-effect sensor that outputs electrical pulses corresponding to the flow rate. This component is commonly used in irrigation systems, water conservation systems, beverage dispensing, and other applications where monitoring water consumption is essential.
Pin Number | Description | Notes |
---|---|---|
1 | GND (Ground) | Connect to system ground |
2 | VCC (Power Supply) | 5 to 18 V DC |
3 | Signal Output | Outputs pulse signal |
// Define the pin connected to the flow meter
const int flowPin = 2;
// Count of pulses from the flow meter
volatile int flowPulseCount = 0;
// Interrupt Service Routine for flow meter
void flowISR() {
flowPulseCount++;
}
void setup() {
Serial.begin(9600);
pinMode(flowPin, INPUT);
// Attach interrupt to the ISR, triggered by a RISING pulse
attachInterrupt(digitalPinToInterrupt(flowPin), flowISR, RISING);
}
void loop() {
// Disable interrupt when calculating flow rate
noInterrupts();
int flowPulseCountCopy = flowPulseCount;
flowPulseCount = 0;
interrupts();
// Calculate the flow rate in liters per minute
// Pulse frequency (Hz) = 7.5 * Flow rate (L/min)
float flowRate = flowPulseCountCopy / 7.5;
Serial.print("Flow rate: ");
Serial.print(flowRate);
Serial.println(" L/min");
// Wait for 1 second before reading again
delay(1000);
}
Q: Can the YF-S201 be used with hot water? A: The sensor can operate within a temperature range of -25 to +80°C. It is suitable for hot water applications within this range.
Q: How can I increase the accuracy of the sensor? A: Ensure proper installation, avoid air bubbles in the line, and use a consistent power supply. Calibration with a known volume of water can also improve accuracy.
Q: Is the YF-S201 sensor waterproof? A: The sensor is designed to measure water flow within a pipe and is typically water-resistant. However, the electronic components should not be submerged or exposed to moisture.