The YF-S201 Water Flow Meter is a sensor designed to measure the flow rate of water through a pipe or hose. It operates by using a rotor that spins in response to water flow, with a hall-effect sensor that outputs a series of electrical pulses. These pulses can be counted to determine the volume of water that has passed through the meter. Common applications include irrigation systems, water conservation systems, and any application where water usage monitoring is necessary.
Pin Number | Description | Notes |
---|---|---|
1 | GND (Ground) | Connect to system ground |
2 | Signal Output (Pulse) | Connect to a digital input pin |
3 | VCC (Power Supply) | Connect to 5-18 VDC |
// Define the pin connected to the flow meter
const int flowPin = 2;
volatile int flowPulseCount; // Volatile because it's changed in an interrupt
void setup() {
Serial.begin(9600);
pinMode(flowPin, INPUT);
attachInterrupt(digitalPinToInterrupt(flowPin), pulseCounter, RISING); // Interrupt on rising edge of pulse
}
void loop() {
// Disable the interrupt while calculating flow rate and volume to prevent errors
noInterrupts();
int flowRate = flowPulseCount;
flowPulseCount = 0; // Reset pulse count after reading
interrupts();
// Calculate the flow rate in liters per minute (L/min)
// The factor 7.5 is calibration factor, adjust as necessary for your specific sensor
float flowRateLpm = (flowRate / 7.5);
Serial.print("Flow rate: ");
Serial.print(flowRateLpm);
Serial.println(" L/min");
// Delay for a second to get a stable reading
delay(1000);
}
// Interrupt service routine to count pulses from the flow meter
void pulseCounter() {
flowPulseCount++;
}
Q: Can the YF-S201 be used with hot water? A: The YF-S201 can be used with water up to 80°C. Beyond this temperature, the sensor may be damaged.
Q: How can I increase the accuracy of the sensor? A: Regular calibration and ensuring a full water pipe (no air) will help increase accuracy. Also, maintaining a steady flow rate during measurements is important.
Q: Is the YF-S201 Water Flow Meter food safe? A: The YF-S201 is not certified as food safe. It is intended for water measurement applications where food safety is not a concern.
Q: What is the lifespan of the YF-S201? A: The lifespan depends on usage conditions but it is generally designed for long-term use in typical water flow measurement applications. Regular maintenance and avoiding excessive water pressure can extend its lifespan.