1/8 Inch Water Flow Sensor YF-S401
1/8 Inch Water Flow Sensor YF-S401
The 1/8 Inch Water Flow Sensor YF-S401 is a digital flow sensor designed to measure the flow rate of liquids, specifically water, in industrial, commercial, and residential applications. This sensor is ideal for monitoring water usage, detecting leaks, and optimizing water resource allocation in various systems.
The YF-S401 sensor measures the flow rate of water by detecting the rotational speed of a magnetic-driven rotor, which is proportional to the flow rate. The sensor outputs a digital pulse signal, allowing for easy integration with microcontrollers, Arduino boards, and other electronic devices.
0.5-30 L/min
5% of reading
Digital pulse signal
1-100 Hz (dependent on flow rate)
5V DC
<20 mA
0C to 80C (32F to 176F)
-20C to 80C (-4F to 176F)
0% to 80% RH (non-condensing)
1/8 inch
Brass with PVC or POM options
approximately 50g
22 mm x 17 mm x 14 mm (L x W x H)
Complies with EU health, safety, and environmental protection standards
Complies with EU restriction of hazardous substances in electrical and electronic equipment
Complies with US and Canadian safety standards for industrial control equipment
Monitor water usage and detect leaks in industrial processes and equipment
Track water consumption and optimize water resource allocation
Monitor and control water flow in irrigation systems
Use as a precise flow measurement tool in laboratory and research applications
1/8 Inch Water Flow Sensor YF-S401 DocumentationOverviewThe 1/8 Inch Water Flow Sensor YF-S401 is a digital flow sensor designed to measure the flow rate of fluids, particularly water, in various applications. This sensor is ideal for monitoring water consumption, detecting leaks, and controlling fluid flow in industrial, commercial, and residential settings.Technical SpecificationsOperating voltage: 5V DC
Current consumption: 15mA
Flow range: 1-30 L/min
Accuracy: 5%
Resolution: 0.1 L/min
Response time: 1s
Output: Digital pulse signal
Connector: 3-pin JST connectorExample 1: Basic Water Flow Measurement using ArduinoThis example demonstrates how to use the YF-S401 sensor to measure water flow rate using an Arduino board.Hardware RequirementsArduino Uno or compatible board
1/8 Inch Water Flow Sensor YF-S401
Breadboard and jumper wiresSoftware RequirementsArduino IDE (version 1.8.x or later)Code
```c++
const int flowSensorPin = 2; // Digital pin 2 for pulse inputvolatile int pulseCount = 0;void setup() {
Serial.begin(9600);
pinMode(flowSensorPin, INPUT);
attachInterrupt(digitalPinToInterrupt(flowSensorPin), pulseCounter, RISING);
}void loop() {
pulseCount = 0;
delay(1000); // Take a 1-second sample
detachInterrupt(digitalPinToInterrupt(flowSensorPin));
float flowRate = (pulseCount / 7.5); // Convert pulses to L/min
Serial.print("Flow rate: ");
Serial.print(flowRate, 2);
Serial.println(" L/min");
attachInterrupt(digitalPinToInterrupt(flowSensorPin), pulseCounter, RISING);
}void pulseCounter() {
pulseCount++;
}
```
Example 2: Water Leak Detection using Raspberry PiThis example demonstrates how to use the YF-S401 sensor to detect water leaks using a Raspberry Pi.Hardware RequirementsRaspberry Pi (any model)
1/8 Inch Water Flow Sensor YF-S401
Breadboard and jumper wiresSoftware RequirementsRaspbian OS (latest version)
Python 3.x (built-in with Raspbian)Code
```python
import RPi.GPIO as GPIO
import time# Set up GPIO library
GPIO.setmode(GPIO.BCM)# Define flow sensor pin
FLOW_SENSOR_PIN = 17# Set up flow sensor pin as input
GPIO.setup(FLOW_SENSOR_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)# Set up pulse counter
pulse_count = 0def pulse_counter(channel):
global pulse_count
pulse_count += 1# Set up interrupt on rising edge
GPIO.add_event_detect(FLOW_SENSOR_PIN, GPIO.RISING, callback=pulse_counter, bouncetime=200)while True:
time.sleep(1) # Take a 1-second sample
flow_rate = pulse_count / 7.5 # Convert pulses to L/min
pulse_count = 0
if flow_rate > 5: # Adjust threshold value as needed
print("Water leak detected!")
else:
print("No water leak detected.")
```
Example 3: Water Flow Monitoring using ESP8266This example demonstrates how to use the YF-S401 sensor to monitor water flow rate using an ESP8266 board.Hardware RequirementsESP8266 board (e.g., NodeMCU)
1/8 Inch Water Flow Sensor YF-S401
Breadboard and jumper wiresSoftware RequirementsArduino IDE (version 1.8.x or later) with ESP8266 supportCode
```c++
#include <WiFi.h>const int flowSensorPin = D5; // Digital pin D5 for pulse inputvolatile int pulseCount = 0;WiFiClient client;void setup() {
Serial.begin(9600);
pinMode(flowSensorPin, INPUT);
attachInterrupt(digitalPinToInterrupt(flowSensorPin), pulseCounter, RISING);
// Connect to WiFi and initialize client
WiFi.begin("your_wifi_ssid", "your_wifi_password");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
client.setServer("your_server_ip", 80);
}void loop() {
pulseCount = 0;
delay(1000); // Take a 1-second sample
detachInterrupt(digitalPinToInterrupt(flowSensorPin));
float flowRate = (pulseCount / 7.5); // Convert pulses to L/min
Serial.print("Flow rate: ");
Serial.print(flowRate, 2);
Serial.println(" L/min");
// Send data to server using HTTP POST
client.print("POST /update HTTP/1.1
");
client.print("Host: your_server_ip
");
client.print("Content-Type: application/x-www-form-urlencoded
");
client.print("Content-Length: ");
client.print( String("flow_rate=").concat(String(flowRate, 2)));
client.print("
");
client.stop();
attachInterrupt(digitalPinToInterrupt(flowSensorPin), pulseCounter, RISING);
}void pulseCounter() {
pulseCount++;
}
```
These examples demonstrate the basic usage of the 1/8 Inch Water Flow Sensor YF-S401 in different contexts. You can modify the code to suit your specific requirements and integrate it with other IoT components for more complex applications.