Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YFS201 Sensor #6015

Merged
merged 1 commit into from
Mar 5, 2025
Merged

YFS201 Sensor #6015

merged 1 commit into from
Mar 5, 2025

Conversation

4211421036
Copy link
Contributor

YFS201


YFS201 Water Flow Sensor Module

Table of Contents

  1. Introduction
  2. Features
  3. Installation
  4. Usage
  5. Mathematical Formulation
  6. Examples
  7. Caution
  8. Important Notes
  9. Warning
  10. License

Introduction

The YFS201 Water Flow Sensor Module is an Arduino-compatible library designed to interface with the YF-S201 water flow sensor. This sensor measures the flow rate of water using the Hall Effect principle, generating pulses proportional to the flow rate. This library provides an easy-to-use interface to read the flow rate, calculate the total volume of water, and integrate with other components like LCDs, relays, or SD cards.


Features

  • Flow Rate Measurement: Accurately measure the flow rate of water in liters per minute (L/min).
  • Total Volume Calculation: Calculate the total volume of water that has passed through the sensor.
  • Pulse Counting: Count the number of pulses generated by the sensor to determine flow rate.
  • Compatibility: Works seamlessly with Arduino boards and other compatible microcontrollers.
  • Extensible: Easily integrate with other libraries for LCDs, SD cards, or IoT platforms.

Installation

To use the YFS201 library, follow these steps:

  1. Download the library as a ZIP file or clone the repository.
  2. Open the Arduino IDE.
  3. Go to Sketch > Include Library > Add .ZIP Library and select the downloaded file.
  4. Include the library in your sketch:
    #include "yfs201.h"

Usage

Basic Setup

  1. Connect the YF-S201 sensor to your Arduino:

    • VCC to 5V
    • GND to GND
    • Signal to a digital pin (e.g., D2).
  2. Initialize the sensor in your sketch:

    const int flowSensorPin = 2; // Pin connected to the sensor
    yfs201 flowSensor(flowSensorPin);
    
    void setup() {
        Serial.begin(9600);
        flowSensor.begin();
    }
  3. Read the flow rate and total volume in the loop() function:

    void loop() {
        float flowRate = flowSensor.getFlowRate();
        unsigned long totalPulses = flowSensor.getTotalPulses();
    
        Serial.print("Flow Rate: ");
        Serial.print(flowRate);
        Serial.println(" L/min");
    
        Serial.print("Total Pulses: ");
        Serial.println(totalPulses);
    
        delay(1000); // Wait 1 second before reading again
    }

Mathematical Formulation

The flow rate $$Q$$ (in liters per minute) is calculated using the following formula:

$$ Q = \frac{f \times 60}{K} $$

Where:

  • $$Q$$: Flow rate in liters per minute (L/min).
  • $$f$$: Frequency of pulses in Hertz (Hz).
  • $$K$$: Sensor calibration factor (typically 7.5 for YF-S201).

The total volume $$V$$ (in liters) is calculated by integrating the flow rate over time:

$$ V = \int_{0}^{t} Q , dt $$

In the code, this is approximated as:

$$ V = \sum_{i=1}^{n} \left( \frac{Q_i \times \Delta t_i}{60} \right) $$

Where:

  • $$Q_i$$: Flow rate at time interval ( i ).
  • $$\Delta t_i$$: Time elapsed since the last measurement (in milliseconds).

Examples

Example 1: Basic Flow Rate Measurement

This example reads the flow rate and displays it on the Serial Monitor.

#include "yfs201.h"

const int flowSensorPin = 2;
yfs201 flowSensor(flowSensorPin);

void setup() {
    Serial.begin(9600);
    flowSensor.begin();
}

void loop() {
    float flowRate = flowSensor.getFlowRate();
    Serial.print("Flow Rate: ");
    Serial.print(flowRate);
    Serial.println(" L/min");
    delay(1000);
}

Example 2: Total Volume Calculation

This example calculates and displays the total volume of water that has passed through the sensor.

#include "yfs201.h"

const int flowSensorPin = 2;
yfs201 flowSensor(flowSensorPin);

float totalVolume = 0;
unsigned long lastTime = 0;

void setup() {
    Serial.begin(9600);
    flowSensor.begin();
    lastTime = millis();
}

void loop() {
    unsigned long currentTime = millis();
    unsigned long elapsedTime = currentTime - lastTime;
    lastTime = currentTime;

    float flowRate = flowSensor.getFlowRate();
    float volumeIncrement = (flowRate * elapsedTime) / 60000.0;

    totalVolume += volumeIncrement;

    Serial.print("Total Volume: ");
    Serial.print(totalVolume);
    Serial.println(" L");

    delay(1000);
}

Caution

  • Ensure the sensor is properly connected to avoid damage to the Arduino or sensor.
  • Do not exceed the maximum flow rate specified in the sensor's datasheet (typically 30 L/min for YF-S201).

Important

  • The calibration factor $$K$$ may vary depending on the specific sensor. Always calibrate the sensor for accurate measurements.
  • The sensor is not suitable for measuring non-conductive fluids.

Warning

  • Electrical Safety: Always disconnect power before making changes to the circuit.
  • Water Safety: Avoid exposing the sensor to water temperatures above its rated limit (typically 60°C).

License

This project is licensed under the MIT License. See the LICENSE file for details.


Copy link
Contributor

github-actions bot commented Mar 5, 2025

A problem was found with your submission git@github.com:4211421036/YFS201

ERROR: Invalid submission URL (parse "git@github.com:4211421036/YFS201": first path segment in URL cannot contain colon)

@github-actions github-actions bot added the topic: submission Add library to the list label Mar 5, 2025
Copy link
Contributor

github-actions bot commented Mar 5, 2025

A problem was found with your submission https://github.com/4211421036/githubiot

ERROR: Submission URL is already in the Library Manager index.

Copy link
Contributor

github-actions bot commented Mar 5, 2025

Thanks for your interest in contributing to the Arduino Library Manager index @4211421036
Please resolve the error(s) mentioned in the previous comment.

After resolving the issue, trigger this check again by doing one of the following:

  • Commit the required change to the branch you submitted this pull request from.
  • Comment here, mentioning @ArduinoBot in the comment.

NOTE: It is not necessary to open a new pull request. ❗

More information:
https://github.com/arduino/library-registry/blob/main/README.md#if-the-problem-is-with-the-pull-request

Copy link
Contributor

github-actions bot commented Mar 5, 2025

A problem was found with your submission https://github.com/4211421036/githubiot

ERROR: Submission URL is already in the Library Manager index.

Copy link
Contributor

github-actions bot commented Mar 5, 2025

Arduino Lint has suggestions for possible improvements to https://github.com/4211421036/YFS201:

Linting library in YFS201
INFO: No header file found matching library name (YF-S201_Water_Flow.h). Best practices are for primary header filename 
      to match library name.                                                                                            
      See: https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format            
      (Rule LS008)                                                                                                      
WARNING: library.properties name YF-S201 Water Flow contains spaces. Although supported, best practices is to not use   
         spaces.                                                                                                        
         See: https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format         
         (Rule LP015)                                                                                                   

Linter results for project: 0 ERRORS, 1 WARNINGS

-------------------

Linting sketch in YFS201/examples/Total_Volume

Linter results for project: no errors or warnings

-------------------

Linting sketch in YFS201/examples/Water_Flow_Rate

Linter results for project: no errors or warnings

-------------------

Linter results for projects: 0 ERRORS, 1 WARNINGS

Copy link
Contributor

github-actions bot commented Mar 5, 2025

Thanks for your interest in contributing to the Arduino Library Manager index @4211421036
Please resolve the error(s) mentioned in the previous comment.

After resolving the issue, trigger this check again by doing one of the following:

  • Commit the required change to the branch you submitted this pull request from.
  • Comment here, mentioning @ArduinoBot in the comment.

NOTE: It is not necessary to open a new pull request. ❗

More information:
https://github.com/arduino/library-registry/blob/main/README.md#if-the-problem-is-with-the-pull-request

Copy link
Contributor

github-actions bot commented Mar 5, 2025

Hi @4211421036
A problem was found with your pull request:

ERROR: Pull request removes newline from the end of a file.
Please add a blank line to the end of the file.

Please resolve this error. The checks will automatically run again once that is done.

More information:
https://github.com/arduino/library-registry/blob/main/README.md#if-the-problem-is-with-the-pull-request

@github-actions github-actions bot added topic: invalid Request could not be processed and removed topic: submission Add library to the list labels Mar 5, 2025
@github-actions github-actions bot requested a review from per1234 March 5, 2025 11:00
@per1234 per1234 self-assigned this Mar 5, 2025
@github-actions github-actions bot removed the request for review from per1234 March 5, 2025 15:07
@github-actions github-actions bot added topic: submission Add library to the list and removed topic: invalid Request could not be processed labels Mar 5, 2025
Copy link
Contributor

github-actions bot commented Mar 5, 2025

Arduino Lint has suggestions for possible improvements to https://github.com/4211421036/YFS201:

Linting library in YFS201
INFO: No header file found matching library name (YF-S201_Water_Flow.h). Best practices are for primary header filename 
      to match library name.                                                                                            
      See: https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format            
      (Rule LS008)                                                                                                      
WARNING: library.properties name YF-S201 Water Flow contains spaces. Although supported, best practices is to not use   
         spaces.                                                                                                        
         See: https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format         
         (Rule LP015)                                                                                                   

Linter results for project: 0 ERRORS, 1 WARNINGS

-------------------

Linting sketch in YFS201/examples/Total_Volume

Linter results for project: no errors or warnings

-------------------

Linting sketch in YFS201/examples/Water_Flow_Rate

Linter results for project: no errors or warnings

-------------------

Linter results for projects: 0 ERRORS, 1 WARNINGS

@github-actions github-actions bot merged commit cfc316f into arduino:main Mar 5, 2025
11 checks passed
Copy link
Contributor

github-actions bot commented Mar 5, 2025

Your submission has now been accepted! Thanks for your contribution to the Arduino Library Manager index.

The library(s) will be available for installation via Library Manager within a day's time.

You can check the logs from the Library Manager indexer for your library(s) here:
http://downloads.arduino.cc/libraries/logs/github.com/4211421036/YFS201/

github-actions bot pushed a commit that referenced this pull request Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: submission Add library to the list
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants