Water Flow Sensor YF-S201 Arduino Interface

It is Very simple to Measure the water or liquid flow by using water flow sensor YF-S201 with Arduino, this Article describes about the water flow sensor and How the water flow sensor works then how to interface water flow sensor with Arduino.




To take control on volume we need to measure, water is essential to every thing, here this article helps you to built water flow meter to measure the volume of water flow through pipelines.

How water flow Sensor Works

This illustration gives detailed working method of hall effect sensor based water flow sensor, a turbine wheel embed with magnet is placed on a closed plastic envelop and a Hall effect sensor placed, When the water flows through the pipeline, it makes the turbine wheel to rotate and hence the magnet flux interferes the hall sensor, the rate of interference is depends on the speed of water flow, so the hall effect sensor produce pulse signal output, this pulse output can be calculated as water volume.

YF-S201 water flow sensor

This water flow sensor has only three wires and it 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 pipeline.

Arduino Hookup

Connect the +5V wire to Arduino power pin 5V and Ground pin to Gnd then connect Signal pin to Digital pin D2, this sensor has control circuit hence there is no need for pull up resistor, some sensor requires pull up resistors refer datasheet of 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");
   }
}

 



Add a Comment

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