Sheekar Banerjee
Published © CC0

YF-S201 Water Flow Sensor and Arduino | Sheekar Banerjee

This project is about measuring water flow rate with YF-S201 Sensor and Arduino.

IntermediateShowcase (no instructions)7,134
YF-S201 Water Flow Sensor and Arduino | Sheekar Banerjee

Things used in this project

Hardware components

Arduino YF-S201 water Flow Sensor
×1
Arduino UNO
Arduino UNO
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit Diagram of YF-S201 Water Flow Sensor and Arduino

Code

Program of YF-S201 Sensor and Arduino

Arduino
//Coded and Tested By:
// Sheekar Banerjee, AI-ML-IOT Solution Engineer and Researcher

/*
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");
}
}

Credits

Sheekar Banerjee
0 projects • 6 followers
A motivated Computer Scientist & Engineer with years of experience over IoT, Robotic Systems, Machine Learning Algorithms and Software.
Contact

Comments

Please log in or sign up to comment.