Introduction:
In this project, we will interface YFS201 Hall Effect Water Flow Sensor with Arduino for measuring flow rate and volume of water or any other liquid. This is a very wonderful project that can be used in industry or at home or at water flow measurement application in water tap, tunnel, river, etc. Water Flow Sensor for Flow Rate & Volume Measurement using Arduino code along with the circuit diagram is explained below.
This project can be used to measure liquid flowing through a pipe or container or to create a control system based on the water flow rate or quantity. For example, you could use this while gardening to measure the amount of water used to water your plants, to prevent wastage. Or you can use it to make Water Dispenser Machine used in industry and drinks items.
Check the advance version of this Project to monitor Water Flow Rate & Volume Remotely: IoT Water Flow Meter using ESP8266
Water Flow Sensor for Flow Rate & Volume Measurement using Arduino:
Bill of Materials
S.N. | Components Name | Quantity | Purchase Links |
---|---|---|---|
1 | Arduino UNO Board | 1 | Amazon | AliExpress |
2 | YFS201 Hall Effect Water Flow Sensor | 1 | Amazon | AliExpress |
3 | 16x2 LCD Display | 1 | Amazon | AliExpress |
4 | Potentiometer 10K | 1 | Amazon | AliExpress |
5 | Connecting Wires | 20 | Amazon | AliExpress |
6 | Breadboard | 1 | Amazon | AliExpress |
Circuit Diagram:
Connect the LCD pin 1, 3, 5, 16 to GND & 2, 15 to 5V VCC. And then connect LCD pins 4,6,11,12,13,14 to Arduino digital pins D7, D6, D5, D4, D3, D2.
Connect YFS201 Hall Effect Water Flow Sensor VCC pins to 5V Power supply & GND to GND. Since it’s an analog sensor, so connect its analog pin to A0 of Arduino as shown in the figure above.
YFS201 Hall Effect Water Flow Sensor:
Introduction:
This sensor sits in line with your water line and contains a pinwheel sensor to measure how much liquid has moved through it. There’s an integrated magnetic hall effect sensor that outputs an electrical pulse with every revolution. The hall effect sensor is sealed from the water pipe and allows the sensor to stay safe and dry.
Check the YF-S201 Hall Effect Water Flow Meter / Sensor Datasheet
The sensor comes with three wires: red (5-24VDC power), black (ground), and yellow (Hall effect pulse output). By counting the pulses from the output of the sensor, you can easily calculate the water flow rate. Each pulse is approximately 2.25 milliliters. Note this isn’t a precision sensor, and the pulse rate does vary a bit depending on the flow rate, fluid pressure, and sensor orientation. It will need careful calibration if better than 10% precision is required. However, it’s great for basic measurement tasks!
Features of Flow Sensor:
Model: YF-S201
Sensor Type: Hall effect
Working Voltage: 5 to 18V DC (min tested working voltage 4.5V)
Max current draw: 15mA @ 5V
Output Type: 5V TTL
Working Flow Rate: 1 to 30 Liters/Minute
Working Temperature range: -25 to +80℃
Working Humidity Range: 35%-80% RH
Accuracy: ±10%
Maximum water pressure: 2.0 MPa
Output duty cycle: 50% +-10%
Output rise time: 0.04us
Output fall time: 0.18us
Flow rate pulse characteristics: Frequency (Hz) = 7.5 * Flow rate (L/min)
Pulses per Liter: 450
Durability: minimum 300,000 cycles
Working of YFS201 Hall Effect Water Flow Sensor:
The Water Flow Sensor for Flow Rate & Volume Measurement using Arduino works on the principle of the Hall effect. According to the Hall effect, a voltage difference is induced in a conductor transverse to the electric current and the magnetic field perpendicular to it. Here, the Hall effect is utilized in the flow meter using a small fan/propeller-shaped rotor, which is placed in the path of the liquid flowing.
The liquid pushes against the fins of the rotor, causing it to rotate. The shaft of the rotor is connected to a Hall effect sensor. It is an arrangement of a current flowing coil and a magnet connected to the shaft of the rotor, thus a voltage/pulse is induced as this rotor rotates. In this flow meter, for every liter of liquid passing through it per minute, it outputs about 4.5 pulses. This is due to the changing magnetic field caused by the magnet attached to the rotor shaft. We measure the number of pulses using an Arduino and then calculate the flow rate in liters per hour (L/hr) and total volume in Litre using a simple conversion formula
Source Code/Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
#include <LiquidCrystal.h> LiquidCrystal lcd(7, 6, 5, 4, 3, 2); int X; int Y; float TIME = 0; float FREQUENCY = 0; float WATER = 0; float TOTAL = 0; float LS = 0; const int input = A0; void setup() { Serial.begin(9600); lcd.begin(16, 2); lcd.clear(); lcd.setCursor(0,0); lcd.print(“Water Flow Meter”); lcd.setCursor(0,1); lcd.print(“****************”); delay(2000); pinMode(input,INPUT); } void loop() { X = pulseIn(input, HIGH); Y = pulseIn(input, LOW); TIME = X + Y; FREQUENCY = 1000000/TIME; WATER = FREQUENCY/7.5; LS = WATER/60; if(FREQUENCY >= 0) { if(isinf(FREQUENCY)) { lcd.clear(); lcd.setCursor(0,0); lcd.print(“VOL. :0.00”); lcd.setCursor(0,1); lcd.print(“TOTAL:”); lcd.print( TOTAL); lcd.print(” L”); } else { TOTAL = TOTAL + LS; Serial.println(FREQUENCY); lcd.clear(); lcd.setCursor(0,0); lcd.print(“VOL.: “); lcd.print(WATER); lcd.print(” L/M”); lcd.setCursor(0,1); lcd.print(“TOTAL:”); lcd.print( TOTAL); lcd.print(” L”); } } delay(1000); } |
Video Preview & Demonstration:
Check the advance version of this Project to monitor Water Flow Rate & Volume Remotely: IoT Water Flow Meter using ESP8266
38 Comments
FROM WHERE THE ELECTRICITY SUPPLY IS THERE
Use any 5 volt supply to 5v point on arduino
can be explained the function of the variable time, frequency, water, total and ls?
Dear sir water flow rate project practically very nice and I was making. Sir plz halp me for example- totaliser 100 ltr showing display then I power off then restart time why totalizer 0.00 showing? Any option shaving plz help me
I tried this with an alternate flow meter, could not get it to work.
Seems to be some discrepancies between the flow meter spec’ vs your text.
Where did you get the Frequency = 1000000/Time
1 sec = 10000000 microseconds
Hi
I want to build this device, and I would like to be ensure that the count is not lost if the power is lost.
I want to write to EEPROM when the Arduino detects power down – I’m not sure it is ok… because EEPROM cycle use is limited.
Could you help me?
Nice tutorial. It has some of the features that i want to include in my project. I need some advice from you.
Here i go
So i want to develop a water utility system where people can go to fetch water and insert their cards with some credit on them and when they do so, the system first accepts the payment before it dispenses the water equivalent to the credit paid. Any advice in terms of what hardware i need to accomplish that?
Use RFID System and a keypad.
Rfid for access controlling and keypad for selecting amount/volume of water that is to be drawn.
How to use keyboard for entering the value and how to use relay for controlling the water flow …Please help.
i want to convert the measured amount of water into its equivalent cost. Can you help me with the codes?
total cost = total volume of water/unit cost of 1 litre water
Hi Alex, great work … well done! thanks for it.
I have one question, I’m using a mechanical Water flow … (https://wtmeters.com/docProdotti/P-0000021.pdf) and sometimes I have a TIME value negative … Could you help me? Because I think this situation is not normal.
Regards
Hi
I saw your video and Arduino program.thanks for the information. I have a question regarding using 2 halleffect water flow sensors at a time for measuring the flow rate of hot and cold water flowing through 2 different pipelines. Here only A0 used. For this we need to use A1 too.Also if I don’t need to display the total amount ,what changes are to be made in the program.need to display H.W F/R and C.W F/R
In the programming section Remove the line that displays total amount. And to display flow rate sensed by analog pin A1, add the line similar to that of A0. You just need good programming skill.
Hi,thanks for the video and program. Please help me with a program for using 2 halleffect water flow sensors for measuring water flow rate through 2 different pipelines. Here we used only A0 .But for this we need to A0 and A1,right? instead of total flow we need to show H.W F/R and C.W F/R
Hot and cold water flow rate
Regards
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int W;
int X;
int Y;
int Z;
float TIME = 0;
float TIME2 = 0;
float FREQUENCY = 0;
float FREQUENCY2 = 0;
float WATER = 0;
float WATER2 = 0;
float LS = 0;
float LS2 = 0;
const int input1 = A0;
const int input2 = A1;
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(” HEAT EXCHANGER”);
lcd.setCursor(0, 1);
lcd.print(“Water Flow Meter”);
delay(2000);
pinMode(input1, INPUT);
pinMode(input2, INPUT);
}
void loop()
{
W = pulseIn(input1, HIGH);
X = pulseIn(input1, LOW);
TIME = W + X;
FREQUENCY = 1000000 / TIME;
WATER = FREQUENCY / 7.5;
LS = WATER / 60;
if (FREQUENCY >= 0)
{
if (isinf(FREQUENCY))
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Hw F/R :0.00 L/M”);
lcd.setCursor(0, 1);
lcd.print(“Cw F/R :0.00 L/M”);
}
{
Y = pulseIn(input2, HIGH);
Z = pulseIn(input2, LOW);
TIME2 = Y + Z;
FREQUENCY2 = 1000000 / TIME2;
WATER2 = FREQUENCY2 / 7.5;
LS2 = WATER2 / 60;
Serial.println(FREQUENCY);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Hw F/R:”);
lcd.print(WATER);
lcd.print(“L/M”);
lcd.setCursor(0, 1);
lcd.print(“Cw F/R:”);
lcd.print( WATER2);
lcd.print(“L/M”);
}
if (isinf(FREQUENCY2))
{
Serial.println(FREQUENCY2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Hw F/R :0.00 L/M”);
lcd.setCursor(0, 1);
lcd.print(“Cw F/R :0.00 L/M”);
}
}
delay(1000);
}
Correct or not?
waiting or reply
need help
where you make the circuit diagram ?
Hi
I have tried your code using the sensor. but it is not showing me exact reading. there is massive error. on pouring 350 milliliter. it shows as large as total vilumv of 23 liters..
can you please help me with this.??
I think the formula is wrong.
LS (liters per second) needs to be = (Freq x 60) / 7.5
the one configured here is
LS = Freq / (60 x 7.5)
what this TTL?
I want to set a water meter with consumption of water can be informed via sms by sending an sms from an office number
How to Program arduino uno with LCD for velocity and Discharge of water
Please Help me proram arduino uno with LCD to find the velocity and Discharge of water
why we are using 7.5 and 1000000 values in the code ?
Helo sir can i get a code that helps the flow sensor to read the flow of pressure passing through the valve ( i mean like if the valve is completely open the sensor will detect full pressure and give out a reading of 100% likewise if its half open the sensor will detect from the pressure and give out a reading for 50% also respectively for 75% and 25%.
Pls do a video about this flow sensor with a button and solve what is the problem with the given combination. I am currently using this device for my thesis and i needed to combine these two! pls help!!
Hi sir, how do I switch the code, instead of using lcd i”m just gonna use my laptop as a temporary monitor
hello,
i need the flowrate to start counting minimum flow to detect approximately 2l / h
Sir please provide a flow chart and block diagram
nothing is show on lcd is play
hi, thanks for useful tutorials
Although you mentioned the sensor is an analog sensor in this tutorial, it’s been considered as digital sensor in IoT water flow sensor tutorial.
I’m wondering what the reason is.
thanks
What computer language are you using?
obviously C++
Hi, this is a good site for me to start with on this project. I am using the 1602LCD unit with a PCF8574T unit attached to it so it will use SDA (serial data) and SCL (serial Clock) If you are familiar with this unit, could you redo the sketch to work with it please. Thank you
Hi
I’ve a similiar problem at Ganesh J G,
I need to use two flow sensor, for me it’s not important the flow rate but the volume, i’ll use them for estimate filter life for reverse osmose.
Problem is the accurancy with two sensor because they works sequentially and are affect of delay between of them, so I divide the delay at the end of sketch but not solve the problem, then also different flow rate affect the volume accurancy, do You have any idea to solve it?
Thank You
Here post my sketch
/* Contalitri basato su sensore SEA YF-S402
#include
#include
#include
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0);
// sensore litri output
int X;
int Y;
float TIME = 0;
float FREQUENCY = 0;
float WATER = 0;
float TOTAL = 0;
float LS = 0;
const int input = A0; // input sensore litri out
//____________________________________________
// sensore litri input
int G;
int H;
float TIME1 = 0;
float FREQUENCY1 = 0;
float WATER1 = 0;
float TOTAL1 = 0;
float LS1 = 0;
const int input1 = A1; // input sensore litri input
//______________________________________________
const int Preset = 6; //pulsante reset per cambio filtri
void setup() {
Serial.begin(9600);
u8g2.begin();
pinMode(input, INPUT); //setta la variabile di input A0
pinMode(input1, INPUT); //setta la variabile di input A1
pinMode(Preset, INPUT_PULLUP); //imposta la resistenza di pull-up
}
void loop() {
//_______________sezione sensore litri input___________________________
G = pulseIn(input1, HIGH);
H = pulseIn(input1, LOW);
TIME1 = G + H;
FREQUENCY1 = 1000000 / TIME1;
WATER1 = FREQUENCY1 / 73;
LS1 = WATER1 / 60;
if (FREQUENCY1 >= 0) {
if (isinf(FREQUENCY1)) {
//u8g2.clearBuffer();
u8g2.setFont(u8g2_font_courR12_tf);
u8g2.setCursor(2, 15);
u8g2.print(“Flow Meter”);
u8g2.setFont(u8g2_font_courR14_tf);
u8g2.drawStr(0, 35, “Li.”);
u8g2.setCursor(30, 35);
u8g2.print(TOTAL1);
u8g2.sendBuffer();
}
else {
TOTAL1 = TOTAL1 + LS1;
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_courR10_tf);
u8g2.drawStr(0, 10, “P.: “);
u8g2.setCursor(30, 10);
u8g2.print(WATER1);
u8g2.drawStr(75, 10, ” L/M”);
u8g2.drawStr(0, 30, “Li.”);
u8g2.setCursor(30, 30);
u8g2.print(TOTAL1);
u8g2.sendBuffer();
u8g2.clearBuffer();
}
}
delay (500);
//_________________ sezione sensore litri out________________________
X = pulseIn(input, HIGH);
Y = pulseIn(input, LOW);
TIME = X + Y;
FREQUENCY = 1000000 / TIME;
WATER = FREQUENCY / 73;
LS = WATER / 60;
if (FREQUENCY >= 0) {
if (isinf(FREQUENCY)) {
u8g2.setFont(u8g2_font_courR12_tf);
u8g2.setCursor(2, 15);
u8g2.print(“Flow Meter”);
u8g2.setFont(u8g2_font_courR14_tf);
u8g2.drawStr(0, 60, “Lo.”);
u8g2.setCursor(30, 60);
u8g2.print(TOTAL);
u8g2.sendBuffer();
}
else {
TOTAL = TOTAL + LS;
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_courR10_tf);
u8g2.drawStr(0, 45, “P.: “);
u8g2.setCursor(30, 45);
u8g2.print(WATER);
u8g2.drawStr(75, 45, ” L/M”);
u8g2.drawStr(0, 60, “Lo.”);
u8g2.setCursor(30, 60);
u8g2.print(TOTAL);
u8g2.sendBuffer();
u8g2.clearBuffer();
}
}
//____________________________________________________________
delay(500);
if (digitalRead(6) == LOW) { //interroga il pulsante di reset
delay(70);
TOTAL = 0; // azzera il contatore litri out
TOTAL1 = 0; // azzera il contatore litri input
}
}
A more question, volume is affected from flow, if have more flow also the volume is more why?
Please explain what is 7.5 ?