arduino lcd displays flow meter gpm and total quotation
This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.
This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.
If they are fast or you have delays in your code, you should use an interrupt. There are 3 available from the UNO. Int 0 (D2), Int 1 (D3) and ICP1 (D8).
If they are very fast (>1Khz), only the ICP1 should be used, in conjunction with timer 1. This is useful for frequency or RPM measurement (in general flowmeters are not that fast)
Flow rate and volume helps tell the amount of fluid going into, or through a particular vessel. For certain process automation applications, this simple-sounding fluid measurement task is so critical to the success of the project that, failure to get it right, could bring the entire process to its knees. This is why for today’s tutorial, I thought it will be cool to look at this nice water flow sensor; the YF-S201, and its use in an Arduino based project.
The sensor uses the principles of electromagnetism, such that, when liquids flow through the sensor, the flow action impacts the fins of a turbine in the sensor, causing the wheel to spin. The shaft of the turbine wheel is connected to a hall effect sensor so that with every spin, a pulse is generated, and by monitoring that pulse with a microcontroller, the sensor can be used in determining the volume of fluid passing through it.
As the microcontroller for today, we will use the Arduino Uno. The Uno will be used to count the number of pulses detected over time and calculate the flow rate (in liters/hour) and total volume of fluid that has passed through it using the total number of pulses. The result, flow rate and volume, will then be displayed on a 16×2 LCD so as to provide a visual feedback to the user. If the 16×2 LCD is not available, you can view the data over the Arduino Serial Monitor.
To make reading the sensor and calculating flow easy, the interrupt feature of the Atmega328p on the Ardunio is employed, as such, the signal pin of the YF-S201 is connected to one of the interrupt-enabled IOs of the Uno (in this case, pin D2). The LCD, on the other hand, is connected in a 4-bit mode to the Arduino. To save some time on connections, you could also decide to use an I2C enabled version of the 16×2 LCD display. For this, you will only need to connect 4 wires from the display to the Arduino. It will, however, call for some modification in the code, so be sure you can handle it before making that decision.
The idea behind the sketch is simple: monitor the signal pin of the YF-S201 to detect when the hall sensor is triggered (flow is detected) and increment a variable to show the increased inflow. However, to do that efficiently and accurately, we will use the interrupt feature of the Arduino such that whenever the hall sensor detects the rotating magnet, a rising edge interrupt is fired and registered by the Arduino. The total number of interrupts fired over a particular time is then used in generating the flowrate and the total volume of liquid that has traveled through the flow meter.
Since the flow determination is pretty straight forward, the only library we will use for this tutorial is the Arduino Liquid Crystal library. The library contains functions that make it easy to interface the 16×2 LCD with an Arduino. The library is included with the Arduino IDE but in case it’s not, it can be installed via the Arduino IDE Library Manager.
It is followed by the declaration of some variables that will be used to store data later and the creation of an instance of the liquid crystal library.
Next, we create the flow() function. This function is called whenever the interrupt is detected and it will increment the flow counter which will serve as an indication of the flow rate.
Next, we declare the Arduino pin to which the signal pin of the flow sensor is connected, as an input pin. We create a pull-up on the pin by setting it “HIGH” and set up a “Rising” edge interrupt on it with the flow() function we created earlier as the callback.
We wrap up the setup function by calling the millis() function to keep track of the time since flow rate as a measure of the flow within a particular time frame.
The loop starts by comparing how much time has elapsed since the last loop. The flow frequency, obtained via the interrupt action, is then divided by time (in minutes) and the value is displayed as the flowrate. The value is also added to the existing volume(vol) and displayed as the total volume of fluid that has passed through the sensor.
Go over your connections to be sure everything is as it should be. With this done and the code complete, connect the hardware to your computer and upload the code to the Arduino board. If successful, you should see the display come up as shown in the image below.
Connect some pipes to it using whatever means is easy for you and pass some water through the flow sensor. You should see the flowrate being displayed on your screen, vary with the intensity of water flow, and you should also see the volume increase as more water flows through it.
If you don’t have the tubes/pipes for water around at that instant, you can blow some air into the sensor. You should hear the rotor in spin and the values on the LCD should increase.
Flowrate/ volume metering is a very important part of several industrial and even individual consumer processes. It provides to not only monitor consumption but also meter supply and I believe applications like smart water meters and automated fluid dispensers should give you tons of insights into how this seemingly basic project could be transformed into an amazing super useful product.
If you have ever visited large scale manufacturing companies, the first thing you will notice is that they are all automated. Soft Drink Industries and Chemical industries have to constantly measure and quantify the liquids that they are handling during this automation process, and the most common sensor used to measure the flow of a liquid is a Flow Sensor. By using a flow sensor with a microcontroller like Arduino, we can calculate the flow rate, and check the volume of liquid that has passed through a pipe, and control it as required. Apart from manufacturing industries, flow sensors can also be found in the agriculture sector, food processing, water management, mining industry, water recycling, coffee machines, etc. Further, a water flow sensor will be a good addition to projects like Automatic Water Dispenser and Smart Irrigation Systemswhere we need to monitor and control the flow of liquids.
In this project, we are going to build a water flow sensor using Arduino. We will interface the water flow sensor with Arduino and LCD, and program it to display the volume of water, which has passed through the valve. For this particular project, we are going to use the YF-S201 water flow sensor, which uses a hall effect to sense the flow rate of the liquid.
The sensor has 3 wires RED, YELLOW, and BLACK as shown in the figure below. The red wire is used for supply voltage which ranges from 5V to 18V and the black wire is connected to GND. The yellow wire is used for output(pulses), which can be read by an MCU. The water flow sensor consists of a pinwheel sensor that measures the quantity of liquid that has passed through it.
The working of the YFS201 water flow sensor is simple to understand. The water flow sensor works on the principle of hall effect. Hall effect is the production of the potential difference across an electric conductor when a magnetic field is applied in the direction perpendicular to that of the flow of current. The water flow sensor is integrated with a magnetic hall effect sensor, which generates an electric pulse with every revolution. Its design is in such a way that the hall effect sensor is sealed off from the water, and allows the sensor to stay safe and dry.
According to YFS201 Specifications,the maximum current it draws at 5V is 15mA, and the working flow rate is 1 to 30 liters/minute. When the liquid flows through the sensor, it makes contact with the fins of the turbine wheel, which is placed in the path of the flowing liquid. The shaft of the turbine wheel is connected to a hall effect sensor. Due to this, whenever water flows through the valve it generates pulses. Now, all we have to do is to measure the time for the pluses or to count the number of pulses in 1 second and then calculate the flow rates in liter per hour (L/Hr) and then use simple conversion formula to find the volume of the water which had passed through it. To measure the pulses, we are going to use Arduino UNO. The pic below shows you the pinout of the water flow sensor.
The water flow sensor circuit diagram is shown below to interface a water flow sensor and LCD (16x2) with Arduino. If you are new to Arduino and LCDs, you can consider reading this Interfacing Arduino and LCD Article.
The connection of the water flow sensor and LCD(16x2) with the Arduino is given below in table format. Note that the pot is connected in between 5V and GND and pot’s pin 2 is connected with the V0 pin of the LCD.
We are using the header file of the LCD, which eases our interfacing the LCD with Arduino, and the pins 12,11,5,4,3,9 are allotted for data transfer between LCD and Arduino. The sensor"s output pin is connected to pin 2 of Arduino UNO.
This function is an interrupt service routine and this will be called whenever there is an interrupt signal at pin2 of Arduino UNO. For every interrupt signal, the count of the variable flow_frequency will be increased by 1. For more details on the interrupts and their working, you can read this article on Arduino interrupts.
In the void setup, we tell the MCU that the pin 2 of the Arduino UNO is used as INPUT by giving command pinMode(pin, OUTPUT). By using attachInterrupt command, whenever there is a rise in the signal at pin 2, the flow function is called. This increases the count in the variable flow_frequency by 1. The current time and cloopTime are used for the code to run in every 1 second.
The if function ensures that for every one second the code inside it runs. In this way, we can count the number of frequencies produces by the water flow sensor per second. The flow rate pulse characteristics from the datasheet are given that frequency is 7.5 multiplied by flow rate. So the flow rate is frequency / 7.5. After finding flow rate which is in liters/minute, divide it by 60 to convert it into liter/sec. This value is added to the vol variable for every one second.
In our project, we connected the water flow sensor to a pipe. If the output valve of the pipe is closed, the output of the water flow sensor is zero (No pulses). There will be no interrupt signal seen at the pin 2 of the Arduino, and the count of the flow_frequency will be zero. In this condition, the code which is written inside the else loop will work.
If the output valve of the pipe is opened. The water flows through the sensor, which in turn rotates the wheel inside the sensor. In this condition, we can observe pulses, which are generated from the sensor. These pulses will act as an interrupt signal to the Arduino UNO. For every interrupt signal(rising edge), the count of the flow_frequency variable will be increased by one. The current time and cloopTIme variable ensure that for every one second the value of the flow_frequency is taken for calculation of flow rate and volume. After the calculation is finished, the flow_frequency variable is set to zero and the whole procedure is started from the beginning.
The complete working can also be found in the video linked at the bottom of this page. Hope you enjoyed the tutorial and enjoyed something useful, if you have any problems, please leave them in the comment section or use our