Contents

Interfacing YF-S201C Transparent Flow Sensor with Arduino

YF-S201C Water Flow Sensor Features

YF-S201C is a sensor used to measure the water flow. This water flow sensor mainly consists of a plastic valve body, rotor assembly, and hall effect sensor. This module works based on the hall magnetic effect. So when water flows through the rotor assembly, the rotor will rotate and the hall effect sensor will produce an electric pulse. By counting these generated pulses, the amount of water passing through the sensor can be calculated.
The measuring range of water flow is 1-30 L / Min and its maximum pressure is up to 1.75 MPa. Each pulse is approximately equivalent to 2.25 ml.

Note
You can use this formula to calculate the amount of liters passed per unit time: frequency (Hz) = 7.5 * Q (L / Min).
Note

Pay attention to the arrow mark on the module for water path.

You can download the datasheet of this module here.  

YF-S201C Water Flow Sensor Pinout

This sensor has 3 wires: Red, black and yellow:

  • VCC: Module power supply – 5 to 24 V
  • GND: Ground
  • OUT: Pulse output

You can see pinout of this module in the image below.

Required Materials

Hardware Components

Arduino UNO R3 × 1
YF-S201C Water Flow Sensor × 1
Male to Male jumper wire × 1

Software Apps

Arduino IDE

Interfacing YF-S201C Water Flow Sensor with Arduino

Step 1: Circuit

The following circuit shows how you should connect Arduino to YF-S201C sensor. Connect wires accordingly.

Step 2: Code to measure the volume of water in liters

Upload the following code to Arduino.

    /*
  YF-S201C-Water-Flow-Sensor
  made on 14 oct 2020
  by Amir Mohammad Shojaee @ Electropeak
  
Home
*/ double flow; //Liters of passing water volume unsigned long pulse_freq; void setup() { pinMode(2, INPUT); Serial.begin(9600); attachInterrupt(0, pulse, RISING); // Setup Interrupt } void loop () { flow = .00225 * pulse_freq; Serial.print(flow, DEC); Serial.println("L"); delay(500); } void pulse () // Interrupt function { pulse_freq++; }

In this code, we measured the water volume passing through the sensor. As mentioned above, the approximate rate of water passing per pulse is 0.00225. Multiplying this number by the number of pulses gives us the volume of water in liters. Counting pulse number was done using interrupt.

The result can be seen here:

Step 3: Code to measure the flow rate of water in liters per minute

Upload the following code to your Arduino.

    /*
  YF-S201C-Water-Flow-Sensor
  modified on 14 oct 2020
  by Amir Mohammad Shojaee @ Electropeak
  
Home
based on www.hobbytronics.co.uk examples */ double flow; //Water flow L/Min int flowsensor = 2; unsigned long currentTime; unsigned long lastTime; unsigned long pulse_freq; void pulse () // Interrupt function { pulse_freq++; } void setup() { pinMode(flowsensor, INPUT); Serial.begin(9600); attachInterrupt(0, pulse, RISING); // Setup Interrupt currentTime = millis(); lastTime = currentTime; } void loop () { currentTime = millis(); // Every second, calculate and print L/Min if(currentTime >= (lastTime + 1000)) { lastTime = currentTime; // Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min. flow = (pulse_freq / 7.5); pulse_freq = 0; // Reset Counter Serial.print(flow, DEC); Serial.println(" L/Min"); } }

In this code, the flow rate of water passing through the sensor is measured in liters per minute. The flow rate is calculated and displayed every one second.

The result can be seen here:

Liked What You See?​
Get Updates And Learn From The Best​

Comments (3)

  • Gilbert Hersschens Reply

    Hi,
    I plan to use this sensor with ESP8266, which is 3.3V technology. Will this sensor function reliably when supplied with a voltage between 3 and 4V?
    If not, is it possible to replace the Hall sensor by another one which is compatible with 3.3V?

    December 18, 2021 at 2:22 pm
    • Mehran Maleki Reply

      Hi,
      Actually not. It needs to be supplied with a voltage between 5 and 24 volts. Also in’t no easy job replacing the internal Hall sensor of this module with another one. One thing you can do is to use a separate power supply for the YF-S201C module.

      December 19, 2021 at 5:41 am
  • Otabek Reply

    Can we use zlan6842 8 port i/o controller? if yes, could you assist please

    Thanks beforehand

    September 4, 2022 at 5:00 pm

Leave a Reply

Your email address will not be published. Required fields are marked *