arduino lcd displays flow meter gpm and total factory
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)
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
This project was done for a Friend Of a Friend. He needs to monitor water flow rate and quantity for his solar heating projects. He is mainly interested in this two inch sensor but also sent along a small plastic hose bib type similar to the Adafruit 828. Both of these sensors are turbine types, water flow spins a plastic wheel which magnetically triggers a pulse output proportional to the speed at which the wheel is turning. There’s lots of these sensors made for irrigation and industrial processes. The display is sometimes called a “Totalizer”.
The electrical interface on the small flow meter has 3 wires, power, ground, and pulse output – relatively simple to connect to the microcontroller. But the large device has only 2 wires. It signals a pulse by shunting power to ground through a low resistance. The display must sense a pulse by looking for an increase in supply current. I designed an interface circuit that works with either unit by changing an option jumper. I constructed the interface circuit on a small piece of project board from Radio Shack (RIP). The positive supply feeds through a resistor which produces enough voltage drop when the large sensor is pulsing to trigger a digital low at the Arduino. The series resistor value is low enough that the power feed is still adequate for the small plastic sensor, so the option jumper just selects where to pick off the pulse signal. A series resistor and zener diode make sure the voltage ratings of the Arduino input pin are not exceeded. It’s a bad thing to overvolt an Arduino pin, please Don’t Ask Me How I Know This.
In this photo you can see the interface board soldered down near the front of the Altoids tin. I use “L” shaped bits cut from a paper clip, soldered to the board ground, and to the ground plane. The same technique anchors the Arduino board.
At first I worked up the circuit on a solderless bread board using code from the Adafruit web site. When satisfied with the results, I went ahead with building the Altoids tin prototype. The Arduino variant I used is a Sparkfun Pro Mini 5 Volt. It takes up little space and has a 5 volt regulator with enough capacity to run the 16×2 LCD. An LED and two push buttons protrude through the lid, these are regular 6mm square PCB buttons. I solder one side directly to the lid, the other side of the switch is supported by a bit of PCB material and a piece of paper clip wire.
This photo shows the LED and the Reset button. Note the bit of PC board on the high side of the switch has a groove filed across so the grounded paper clip is isolated from the signal connection.
This photo shows the Function switch. It’s hard to see, but there is a 0.05 ufd surface mount capacitor soldered between the signal side and ground. That capacitor is part of my debounce strategy.
The Liquid Crystal Display itself mounts on four 2-56 screws. The screw heads are soldered directly to the lid. I attached a 10k Pot for contrast adjustment to the back of the LCD and it’s legs are used as tie points for 5v and ground wiring to the rest of the display.
If I have to build another one of these, I might glue the Arduino board to the back of the LCD which will greatly reduce the wiring between lid and box.
There is a power jack for 9 or 12 volt DC input, and a 3 conductor phone jack to connect the turbine sensor. These are epoxyed to the box. Connection to the sensor plug is as follows:
Almost all of the turbine type flow sensors I looked at have two calibration factors specified: a “K” factor and an “offset”. During calibration the manufacturer measures the pulse rate outputs for a number of precise flow rates. These are plotted but since the turbine has some friction, the graph will not be linear especially at the low end and a linear regression is done to get a best fit straight line. The “K” factor represents the slope of the fitted line and has a dimension of pulses per unit volume moved. Offset represents the small amount of liquid flow required to start the turbine moving. You can assume that if any pulses are arriving at all, at least the offset volume of liquid is moving. The 228PV manual specifies:
In general, this formula applies to any measurement unit. It would be possible to convert a gallons display to liters by just scaling the K and offset factors by the constant liters/gallon. The Adafruit example sketch uses this method but measures pulse period in 1 millisecond increments which creates large gaps in the data if the pulse rate is over 100 Hz. At 200 Hz the pulse period will be 5 milliseconds, so a 1 millisecond period change is a 20 percent jump!
Adafruit states their sketch is just an example to verify their sensors functionality but I felt higher accuracy at large flow rates was essential. An internet search turned up several sketches using a direct interrupt to count pulses. The sensor pulse train is applied to pin 2 or 3, fires on the rising edge of a pulse and calls an Interrupt Service Routine like:
Can’t get much simpler than that. Run this for exactly one second and you have counted pulses per second. Apply to the above formula and get volume units transfered in that second. Accumulate that many units each second to find total volume transferred. So the code to actually calculate rate and volume is easy. I exorcised most of the Adafruit code and added my own formulas. I also added a line in the ISR to blink the LED along with the incoming pulses.
But this display needs to operate with multiple types of flow sensors. So I had to code an arrangement to set and permanently store K and Offset for whatever sensor was plugged in. That turned out to be the most complicated part of the sketch. I use the Function button to do this, taking advantage of the Arduino setup section which is only executed on a reboot. Holding Function down while resetting the processor starts set mode.
To make this a little easier, I added code to blink the LED if the button is held between 2 and 4 seconds, and turn on the LED solid if held more than 4 seconds. I hope this is no more annoying than setting a cheap digital watch.
This photo is the normal running display entered after exiting set mode, or on a processor reset. The first line records units moved per second, where units is in whatever the given K factor uses. Both the Adafruit sensors have factors specified in Liters/Second. The 228PV I’m working with uses units of Gallons per minute. The water meter on my house here measures in cubic feet. You have to consult the sensor data sheet.
I’ve constructed a second unit. This one is built in a nice looking Extruded Aluminum box from Adafruit. I thought the better enclosure would make construction easier. I was wrong. Because it can’t be opened you can’t reach in and solder anything, and you lose the convenience of soldering anything needing a ground directly to the tin box. That means wires have to be attached to every terminal, brought to a common point and spliced. I did try soldering the Pro Mini to the back of the LCD and that works but the contrast pot had to be wired out so the assembly didn’t save much wiring. This photo shows the completed display with K factor set to 1.0 and a 2000 Hz crystal controlled signal applied to the sense input:
Most of these flow sensors will have specified somewhere in the data sheet, a K factor and offset. What the manufacturer does is plot flow in output pulses per second (frequency) against flow volume through the sensor at a number of flow rates. Then they do a linear regression on the data to get a best fit straight line. An example is Fig 1 in http://www.hofferflow.com/datasheets/miniflow2.pdf.
There does not seem to be a standard for how K factor is presented. Sensors output a pulse stream at a frequency proportional to the flow volume as calibrated, this can be measured. With some sensors, you multiply the pulse frequency by the K factor to obtain a volume rate. Others however, require you to divide the pulse frequency by K.
In the sketch, I added a way to switch between these two methods by using the first character of the K factor. If this character is a “*”, the incoming pulse rate will be multiplied by the K factor, If the first character is “/” pulse rate will be divided by K. You may see a formula in the sensor data sheet like Freq = (Flowrate * K) – offset. Since we measure Frequency and need to display Flowrate, the formula is rearranged toFlowrate = (Freq + offset) / K and the K factor needs to be set to type “/”. Other sensors present Freq = (Flowrate / K) – offset. Rearranging that formula gives Flowrate = (Freq – offset) * K and you would set the K type to multiply, “*”. If the sensor documentation is not clear, just try it out. If the multiply/divide indicator is wrong, you will probably get totally unreasonable flows displayed. If so try changing the type indicator.
This economy water flow meter is an ideal alternative to traditional water meters. The TM Series water meters offer flow rate and flow total indication that help monitor water flow in waste water applications, water treatment, and sub-metering applications.
remove the next two lines and just divide flowRate by 1000. You will now have the number of liters. You can then multiply by the price per liter. You may want to adjust the duration the measurement is done.
You most certainly can use an internal pullup on the Arduino to simplify the wiring but we use a physical resistor as it is much easier to explain the basics of how a pull-up resistor works when you have to connect the wires yourself.
– I would like to put a set point to stop water flow at a certain value. For example, valve opens, water flows and passes sensor. After 100ml, valve closes. Is it possible??? Sorry… , Arduino newbie