Identify Waterflow Detection Using Arduino Uno

Here we are using the YF-S201 water flow sensor to identify whether the water flow has crossed the minimum level or not; these processes are controlled in the Arduino Micro Controller Kit

Introduction:

In my previous articles I explained about RainDrop Detection using the Arduino Uno and in this article I'll show you working with the water flow sensor to save our water using the Arduino.

These days we can see that a lot of water is being in all places. Water is a daily need of our lifeand we want to save it  for the next generations. There are many water flow techniques and different types of water flow measurements to measure the volume of water consumption, but these are costly. My article describes the idea for design and development of a low-cost solution for automatic water flow consumption using the micro controller Arduino Uno.

Requirements:
  • Arduino Uno
  • Bread Board
  • YF-S201 Water flow sensor
  • led                   
   
                                       Figure: Water flow sensor 
Connection:
 
 
 
Connecting water flow sensor to the arduino is pretty easy water flow sensor: 
  • Connect the Vcc to the Arduino 5v
  • Connect the Gnd to Gnd
  • Connect the Output pin (yellow) to the digitalpin 2
Led Connection
  • Anode pin to the 13 
  • Cathode pin to the Gnd   
Programming
  1. volatile int fan;  
  2. int calc;  
  3. int sensor=7;  
  4. int led=13;  
  5. void wfs()  
  6. {  
  7.   fan++;  
  8. }  
  9. void setup()  
  10. {  
  11.   pinMode(led,OUTPUT);  
  12.   pinMode(sensor,INPUT);  
  13.   Serial.begin(9600);  
  14.   attachInterrupt(0,wfs,RISING);  
  15. }  
  16. void loop()  
  17. {  
  18.   fan=0;  
  19.   sei();  
  20.     
  21.   delay(1000);  
  22.   cli();  
  23.   calc=(fan*60/7.5);  
  24.   if(fan > 40)  
  25.   {  
  26.     digitalWrite(led,HIGH);  
  27.   }  
  28.   else {  
  29.     digitalWrite(led,LOW);  
  30.   }  
  31.   Serial.print(calc,DEC);  
  32.   Serial.print("L/hour\r\n");  
  33. }   
Explanation
 
Declaring the variable as fan in the volatile int data type volatile means it is a qualifier and it is applied to the variable. When it declares it tells the compiler that the value of the variable may change any time without any action that had been taken to the code and declare the another variable called calc as integer datatype and declare the another variable sensor and initialize the value to the variable void wfs(). This is the one type of the function that the interrupt calls fan++ is one type of the increment conditions to repeat the function based upon our conditions that get false and it is used to measure the rising and falling edge of the hall effect sensors signal. Then we move to our default functions called void setup() and void loop().
 
Void Setup()
 
In Setup() function here we set our pinMode as INPUT because the value of the sensor is given to digital pin 7 as INPUT in the Arduino. Set the BaudRate(9600) for data transfer between PC and Arduino board and attach the interupt 0, wfs, RISING.
 
Arduino Boards and Digital Pin usable for interrupts

1Uno, Nano, Mini, other 328-based2, 3
2Micro, Leonardo, other 32u4-based0, 1, 2, 3, 7
3Zero, MKR1000 all digital pins, except 4 Dueall digital pins
4Mega, Mega2560, MegaADK2, 3, 18, 19, 20, 21

Interrupts 

The interrupts are useful for making things happen automatically in microcontroller program and it is used to solve the timing problem.
 
Syntax:
 
The basic syntax is used to attach the interrupt:
 
attachInterrupt(digitalPinToInterrupt(Pin), ISR, mode)
 
Void loop()
 
This is an important function in Arduino; it is otherwise called as the condition function based up on our conditions the functions and the components will be work in the Arduino board. Set the fan variable to "0" and it is ready for the calculation; Sei is the one type of the function it is used to enable the interrupts and make some delay time as 1000 Cli is another function used to disable the interrupts. Here we want to use the some mathematical operations such as:
 
calc=(fan*60/7.5)
 
(Pulse frequency * 60)/7.5Q =Flow Rate in L hour if the value > 40 the led will be ON else it i'll be the OFF condition
 
Then we want to print the values such as cal and DEC and L/hr 

Conclusion
 
And finally, we made a water flow sensor using the Arduino.
 
Read more articles on Arduino: