Flow meter: all you need to know

caudalímetro

Measuring the flow of fluid or consumption is important in some cases, and for this you need a flowmeter. For example, if you follow Formula 1, you will know that the FIA forces teams to use a flowmeter in the engine to detect the consumption that each team makes in their cars and thus avoid possible traps by injecting more flow to get more power in some moments or how the oil is used to burn the engine .

But outside of F1 you may be interested in having one of these devices to know what consumption of water or any other liquid a system has, or also to determine the flow rate of a tube that is extracted from a tank to determine when it is consumed, automated garden irrigation systems, etc. The applications of these elements are many, you can set the limit yourself.

Flowmeter or flowmeter

As you should know, the flow rate is the amount of a liquid or fluid circulating in a pipe or hose per unit of time. It is measured in units of volume divided by unit of time, such as liter per minute, liter per hour, cubic meter per hour, cubic meters per second, etc. (l/min, l/h, m³/h, …).

What is a flow meter?

The flowmeter or fluid meter is the device that is capable of measuring that amount of flow through a pipe. There are several models and manufacturers that can be easily integrated with Arduino. That flow rate will depend on several factors, such as pipe section and supply pressure.

By controlling these two parameters and with a flow meter that measures the flow, you can have a sophisticated control system for the fluids. Very useful for home automation or other electronic and even industrial projects. For home projects, the makers have well known models such as the YF-S201, FS300A, FS400A, etc.

Flowmeter types

In the market you will find several types of flow meters according to the use you give and the budget you want to invest. In addition, some of them are specific to a fluid, such as water, fuel, oil, others have more or less accuracy, with prices ranging from a few euros to thousands of euros in some very advanced industrial level:

  • Mechanical flow meter: it is a very typical meter that everyone has in the house to measure the water they consume in their meters. The flow turns a turbine that moves an axis that is connected to a mechanical meter that accumulates the readings. As it is mechanical, in this case it cannot be integrated with Arduino.
  • Ultrasound flow meter: widely used in industry, but extremely expensive for domestic use. It can measure the flow by means of the time it takes for an ultrasound to pass through the fluid to be measured.
  • Electromagnetic flow meter: also used in industry for pipes up to 40 inches and high pressures. They are very expensive and use an electromagnetic system for measurement.
  • Electronic turbine flow meter: low cost and very accurate. These are the ones you can easily integrate with your Arduino and are used for the domestic environment as well. They use a turbine with blades that turns when the fluid flow passes through it and a Hall effect sensor will calculate the flow according to the RPMs it reaches in the turn. The problem is that as they are intrusive they have high pressure loss and suffer deterioration in their parts, so they will not last long .

 

Considering that we are interested in electronics, we will continue to study these…

Flowmeters for Arduino and where to buy

The electronic type flow meters used at Arduino, such as the YF-S201, YF-S401, FS300A, and FS400A, have a plastic housing and a rotor with blades inside, as I mentioned before. A magnet attached to the rotor and the rotation of it, by Hall effect, will determine the flow or consumption you are measuring at each moment. The output of the sensor will be a square wave with a frequency proportional to the flow through it.

The so-called conversion factor K between frequency (Hz) and flow (l/min) depends on the parameters given to the sensor by the manufacturer, therefore, it is not the same for all of them. In the datasheets or model information you buy you will have these values so you can use them in the Arduino code. The accuracy will not be the same either, although usually these for Arduino will vary between 10% above or below the current flow rate.

The recommended models are:

  • YF-S201: has a connection for 1/4″ pipe, to measure flow between 0.3 to 6 liters per minute. The maximum pressure it tolerates is 0.8 MPa, with maximum fluid temperatures up to 80ºC. Its voltage works between 5-18v.
  • YF-S401: in this case, the connection to the pipe is 1/2″, although you can always use converters. The flow rate measured is from 1 to 30 l/min, with pressures up to 1.75 MPa and fluid temperatures up to 80ºC. Its voltage, however, is still 5-18v.
  • : same voltage and same maximum temperature as above. In this case with 3/4″ pipes, with maximum flow from 1 to 60 l/min and pressures of 1.2 MPa.
  • : it also maintains voltage and maximum temperature with respect to its alternatives, also the maximum flow and pressure are the same as for the FS300A. The only thing that varies is that the tube is 1 inch.

You must choose the one you are most interested in for your project…

Integration with Arduino: a practical example

Arduino connected to the flow meter

The connection of your flow meter is very simple. They usually have 3 wires, one for flow data collection and two for power. The data wire can be connected to the Arduino input of your choice and then the sketch code can be programmed. And the power cables, one to the 5V and one to GND, and that would be enough to start working.

But in order for it to have any kind of function, you must first create the code in Arduino IDE. There are many ways to use this flow sensor, and also many ways to program it, but here is a simple and practical example for you to see how it works:


const int sensorPin = 2;
const int measureInterval = 2500;
volatile int pulseConter;
 
// If you're going to use the YF-S201, as in this case, it's 7.5.
// But if you are going to use another one like the FS300A you should substitute the value with 5.5, or 3.5 in the FS400A, etc.
const float factorK = 7.5;
 
void ISRCountPulse()
{
   pressConter++;
}
 
float GetFrequency()
{
   pressConter = 0;
 
   interrupts();
   delay(measureInterval);
   noInterrupts();
 
   return (float)pulseConter * 1000 / measureInterval;
}
 
void setup()
{
   Serial.begin(9600);
   attachInterrupt(digitalPinToInterrupt(sensorPin), ISRCountPulse, RISING);
}
 
void loop()
{
   // This gives the frequency in Hz
   float frequency = GetFrequency();
 
   // And this is how the flow in litres per minute is calculated
   float flow_Lmin = frequency / K-factor
 
   Serial.print("Frequency obtained: ");
   Serial.print(frequency, 0);
   Serial.print(" (Hz)tCflow: ");
   Serial.print(flow_Lmin, 3);
   Serial.println(" (l/min)");
}

And if you want to get the consumption, then you can use this other code, or combine both to have both… For the consumption, you have to integrate the flow achieved with respect to time:


const int sensorPin = 2;
const int measureInterval = 2500;
volatile int pulseConter;
 
// For the YF-S201 it is 7.5, but remember to modify it to the k-factor of your model
const float factorK = 7.5;
 
float volume = 0;
long t0 = 0;
 
 
void ISRCountPulse()
{
   pressConter++;
}
 
float GetFrequency()
{
   pressConter = 0;
 
   interrupts();
   delay(measureInterval);
   noInterrupts();
 
   return (float)pulseConter * 1000 / measureInterval;
}
 
void SumVolume(float dV)
{
   volume += dV / 60 * (millis() - t0) / 1000.0;
   t0 = millis();
}
 
void setup()
{
   Serial.begin(9600);
   attachInterrupt(digitalPinToInterrupt(sensorPin), ISRCountPulse, RISING);
   t0 = millis();
}
 
void loop()
{
   // Obtaining the frequency
   float frequency = GetFrequency();
 
   //Calculate the flow rate in litres per minute
   float flow_Lmin = frequency / K-factor
   SumVolume(flow_Lmin);
 
   Serial.print(" The flow rate is: ");
   Serial.print(flow_Lmin, 3);
   Serial.print(" (l/min)tConsumption:");
   Serial.print(volume, 1);
   Serial.println(" (L)");
}

You know that depending on what you need you must modify this code, also, very important to put the K factor of the model you have bought or it will not take real measurements. Don’t forget!

Leave a Comment

*

*