Water Flow Sensor YF-S201 Arduino Interface

3,340 views

To monitor the amount of water being supplied and used, the rate of flow of water has to be measured. Water flow sensors are installed at the water source or pipes, to measure the rate of flow of water and calculate the amount of water flowing through the pipe. The rate of flow of water is measured, as liters per hour or cubic meters. It is very simple to measure the water or liquid flow, by using the water flow sensor YF-S201 with Arduino.

Here this article helps you to build a water flow meter, to measure the volume of water flow through pipelines. And describes how the water flow sensor works, and then how to interface the water flow sensor with Arduino.

How water flow Sensor Works

The water flow sensor consists of a plastic valve, from which water can pass. A water rotor along with a Hall Effect sensor is present, which senses and measures the water flow. When water flows through the valve, it rotates the rotor. By this, the change can be observed in the speed of the motor. This change is calculated as output as a pulse signal by the Hall Effect sensor. Thus, the rate of flow of water can be measured. Now here a turbine wheel embedded with a magnet is placed on a closed plastic envelope, and a Hall effect sensor is placed. When the water flows through the pipeline, it makes the turbine wheel rotate. Hence the magnet flux interferes with the hall sensor, and the rate of interference depends on the speed of water flow. So the hall effect sensor produces pulse signal output, this pulse output can be calculated as water volume.

YF-S201 water flow sensor

YF-S201 is a water sensor designed, to measure the flow rate and volume of the desired fluid through the pipelines. It is a low-cost water flow sensor, that consists of a copper body and a water rotor. In addition to this, it also contains an internal circuit of the Hall Effect sensor, that works on the principle of electromagnetism and provides pulses at the output pin. It is a power-friendly and MCU-compatible device, with a flow rate of a maximum of 30 liters per minute. A small device with high accuracy finds its application, from DIY projects to the industry for flow measurement. It has only three wires and can be easily interfaced between any microcontroller and Arduino board. It requires only +5V Vcc and gives pulse output, the sensor needs to be tightly fitted between water pipelines.

Hardware Required

S. NoComponentValueQty
1Arduino UNO1
2USB Cable Type A to B1
3Jumper Wires
4Water Flow Sensor YF-S2011

Arduino Hookup

Connect the +5V wire to Arduino power pin 5V and the GND pin to GND. Then connect the signal pin to digital pin D2. This sensor has a control circuit, hence there is no need for a pull-up resistor. Some sensor requires pull-up resistors, refer to the datasheet of the water flow sensor before concluding hookup.

Arduino Code for Water Flow Meter

/*
Arduino Water flow meter
YF- S201 Hall Effect Water Flow Sensor
Water Flow Sensor output processed to read in litres/hour
*/
volatile int flow_frequency; // Measures flow sensor pulses
unsigned int l_hour; // Calculated litres/hour
unsigned char flowsensor = 2; // Sensor Input
unsigned long currentTime;
unsigned long cloopTime;
void flow () // Interrupt function
{
   flow_frequency++;
}
void setup()
{
   pinMode(flowsensor, INPUT);
   digitalWrite(flowsensor, HIGH); // Optional Internal Pull-Up
   Serial.begin(9600);
   attachInterrupt(0, flow, RISING); // Setup Interrupt
   sei(); // Enable interrupts
   currentTime = millis();
   cloopTime = currentTime;
}
void loop ()
{
   currentTime = millis();
   // Every second, calculate and print litres/hour
   if(currentTime >= (cloopTime + 1000))
   {
      cloopTime = currentTime; // Updates cloopTime
      // Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min.
      l_hour = (flow_frequency * 60 / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flowrate in L/hour
      flow_frequency = 0; // Reset Counter
      Serial.print(l_hour, DEC); // Print litres/hour
      Serial.println(" L/hour");
   }
}

Applications

  • Coffee Machines
  • Water Recycling plants
  • Mining Industry (Chemical industry)
  • Smart irrigation system
  • Automatic water dispensers