Flow Sensors
Flow sensors are sensors that measure the flow rate of a fluid or gas. They are used in a wide range of applications, from measuring the flow of water in a pipe to monitoring the flow of air in an engine.
There are many different physical principles that can be used to measure flow rate. Some common types of flow sensors are:
- Hall effect based flow sensors: These sensors use an impeller with a magnet and a hall effect sensor to detect a rotation of the impeller.
- Ultrasonic flow sensors: These use ultrasonic transducers to measure the flow rate, typically by measuring the difference in transit time of ultrasonic pulses sent with and against the flow.
- Thermal mass flow sensors: They combine a heater element and a temperature sensor to measure the amount of energy absorbed by the fluid as it passes over the heater.
- Differential pressure flow sensors: These utilise the Bernoulli principle to measure the pressure drop across an obstruction as the fluid flows through it.
- Electromagnetic flow sensors: These apply Faraday’s law of induction — a magnetic field is set up across the tube, and a conductive fluid moving through it induces a voltage across a pair of electrodes in the tube wall. The fluid has to be electrically conductive, which means it works well for water but rules out gases and oils.1
Hall Effect Flow Sensors
MCU Drivers
A microcontroller driver for a hall effect flow sensor is very easy to write, given the simple digital pulse output from the sensor.
Below is some C pseudo code for a hall effect flow sensor driver:
// Access to this has to be atomic. See the notes below.volatile uint32_t pulseCount = 0;
uint64_t lastMeasurementTime_us = 0;
int main() { // Setup the interrupt handler for the hall effect sensor configure_interrupt(SENSOR_GPIO_PIN, RISING_EDGE, sensor_isr);
while(1) { uint64_t currentTime_us = get_time_us();
uint64_t timeSinceLastMeasurement_us = currentTime_us - lastMeasurementTime_us;
// Assuming there is an atomic_clear() function which // clears the atomic variable and returns the previous value uint32_t pulseCountCopy = atomic_clear(&pulseCount);
// F = 6.6 * Q where F is the frequency of the hall effect signal, Q is the flow rate in L/min // Q = F / 6.6 // Q = 1 / (6.6 * t) where t is the period, t = 1 / F // Since we have measured N pulses in t_total, t_period = t_total / N, // Thus Q = 1 / (6.6 * (t_total / N)) // Q = N / (6.6 * t_total) double flowRate_Lpmin = (double)pulseCountCopy / (6.6 * (double)timeSinceLastMeasurement_us / 1000000.0); printf("Flow rate: %.02f L/min\n", flowRate_Lpmin);
lastMeasurementTime_us = currentTime_us; sleep_ms(1000); }}
/** * This gets called on the rising edge of the hall effect signal */void sensor_isr() { atomic_inc(&pulseCount);}If you do not have any atomic variables available, you have two other options:
- Disable interrupts when reading/clearing the pulse count from
main(). - Use a mutex and lock it when reading/clearing the pulse count from
main()(this assumes you are using an RTOS).
Be aware that myVar++ is generally not atomic, even if reading and writing are atomic since ++ (incrementing) involves a read and a write.
I used doubles since I was running on a rather fast microcontroller with FPU support. If using doubles gives you performance issues, you could either use floats or fixed point arithmetic.
I also configured the ISR to be called only on the rising edge of the hall effect signal. This was because triggering on both edges doesn’t really give you any more information, and I didn’t want to make the assumption that the hall effect signal outputted a 50% duty cycle square wave at all speeds (if it strayed far from 50% and you were using data from both edges, you could get some poor flow rate measurements at slower speeds).
High Precision Calibration
Some flow sensors give you more than a basic linear equation to convert from pulses to flow rate, to achieve higher accuracy.
One more advanced technique is to provide a calibration curve which tells you what the pulses per litre () is at different flow rates ().
For example:
where:
- is the number of pulses per litre at a flow rate of (in L/min)
- , , and are the coefficients of the polynomial fit to the calibration curve
- is the flow rate in L/min
The coefficients , , , and are provided by the manufacturer. To then work out what the flow rate is, you have to perform an iterative calculation, as you need to know to work out , but you need to work out .
First, you would measure the number of pulses over a fixed time period . If were a constant, the flow rate would just be:
But depends on , so the equation to solve is:
which has on both sides. Rather than solving this analytically, it is easier to solve it by fixed-point iteration.
Step 1 — Initial estimate. Use the constant term on its own as a first guess at the pulses per litre. This requires no prior knowledge of :
Step 2 — Iterate. Re-evaluate the calibration curve at the current flow estimate, and use the resulting to refine it:
Step 3 — Stop. Repeat until the estimate settles, i.e. when for some tolerance (or simply run a fixed number of iterations). Convergence is fast — typically two or three passes — because varies only mildly across the sensor’s flow range, so each iteration lands close to the last.
Clamping the Calibration Curve
The polynomial is only fitted over the sensor’s valid flow range . Outside that range a cubic can extrapolate wildly, so the input to must be clamped to the fitted range:
Note that it is only the input to the calibration curve that is clamped, not the reported flow rate. The reported flow rate is still calculated from the true, unclamped pulse count:
So if the measurement implies a flow rate above , the pulses per litre is frozen at its boundary value , but the reported flow rate can still come out above . The clamp protects the shape of the correction curve from extrapolating; it is not a limit on the reading itself.
This does mean accuracy degrades outside the valid range, since the correction is no longer tracking the flow rate — below in particular, where the turbine is losing pulses to bearing drag and blade slip, the frozen under-corrects and the reported flow rate reads low.
Example Hall Effect Flow Sensors
YF-Bx
YF-Bx is a family of hall effect based flow sensors mounted in a small piece of brass tubing (DN15 or DN20, i.e. ½” or ¾”). Depending on the variant, they measure flow rates between 1 and 25 or 1 and 30 L/min. The YF-Bx family have a working voltage of 5V to 15V(DC) and the G1&x family have a working voltage of 5V to 24V(DC).
There are three wires:
- Red: +VCC
- Black: GND
- Yellow: Signal
The yellow signal wire outputs a digital signal which transitions between high and low a fixed number of times per revolution of the impeller (using the hall effect sensor). It has a duty cycle of 50% ±10%.
Note how the duty cycle drifts well away from 50% towards the slow (right-hand) end of the capture — the high time becomes noticeably longer than the low time. This is why the driver above triggers on one edge only.
The rate is typically expressed as a frequency. For example, the YF-B6 datasheet describes a frequency of F=6.6*Q(Q=L/MIN).2 F is the measured frequency of the hall effect signal, and Q is the flow rate in L/min. In a microcontroller, you would typically set up a GPIO interrupt on the sensor pin, and accumulate the number of pulses over a fixed period of time (e.g. check once per second). To calculate the flow rate, we would need to re-arrange the equation. Let’s also substitute for the period () since that’s what we’ll actually measure.
where:
- is the frequency of the hall effect signal in Hz
- is the flow rate in L/min
- is the time between pulses in seconds
As you normally want to accumulate a number of pulses over a fixed period of time (e.g. 1s), and then calculate the flow rate, you need to modify the equation slightly. Let’s call the number of pulses and the total time period these were measured over .
where:
- is the number of pulses measured over a fixed period of time
- is the total time period over which the pulses are measured
So therefore:
The other difference between the two families is the tube material: the YF-Bx parts have a brass tube, whilst the G1&x parts have a plastic one.
The table below shows the core specifications for the flow sensors in the YF-Bx and G1&x families. For the frequency equation, is the frequency of the hall effect signal in Hz, is the flow rate in L/min.
| Type | Dimensions (DN) | Working Voltage | Flow Rate Range | Frequency Eq. | Length | Male & Female | Length of Thread | Material |
|---|---|---|---|---|---|---|---|---|
| YF-B1 | DN15 | 5V to 15V(DC) | 1 to 25L/min | - | 44mm | Double Male | 10mm | Copper |
| YF-B2 | DN15 | 5V to 15V(DC) | 1 to 25L/min | - | 50mm | Male in Female out | 10mm | Copper |
| YF-B3 | DN15 | 5V to 15V(DC) | 1 to 25L/min | - | 66mm | Double Male | 18mm | Copper |
| YF-B4 | DN15 | 5V to 15V(DC) | 1 to 25L/min | - | 66mm | Male in Female out | 10mm | Copper |
| YF-B5 | DN20 | 5V to 15V(DC) | 1 to 30L/min | F=6.6*Q | 50mm | Double Male | 10mm | Copper |
| YF-B6 | DN20 | 5V to 15V(DC) | 1 to 30L/min | F=6.6*Q | 60mm | Double Male | 11mm | Copper |
| YF-B7 | DN15 | 5V to 15V(DC) | 1 to 25L/min | - | 66mm | Double Male | 10mm | Copper |
| G1&2 | DN15 | 5V to 24V(DC) | 1 to 30L/min | - | - | Double Male | - | Plastic |
| G3&4 | DN20 | 5V to 24V(DC) | 1 to 60L/min | - | - | Double Male | - | Plastic |
| G1&8 | - | 5V to 24V(DC) | 0.3 to 6L/min | - | - | - | - | Plastic |
| M11*1.25 | - | 5V to 24V(DC) | 0.3 to 6L/min | - | - | - | - | Plastic |
There is also the YF-S201 flow sensor which seems related.
I have found some significant accuracy issues when using this type of sensor, specifically with the YF-B5. The quoted accuracy as per its datasheet is over a flow rate range of 1 to 30L/min.4 However, I have found the error to be closer to 1L/min when reading a low flow rate of 1L/min, with the accuracy improving as the flow rate increases. The calibration curve below is fitted against measurement data from 3 YF-B5 flow sensors. The dotted black line shows where we would expect the points to be if the sensor followed the datasheet’s quoted equation and accuracy. The dots are measurements from the 3 sensors vs. the actual flow rate (as measured by an expensive and accurate flow meter). The red line is the linear least squares best fit line through the data.
As shown in the calibration curve above, the equation for the best fit line is:
where:
- is the flow rate (in L/min)
- is the frequency (in Hz) of the flow sensor output
Using this linear best fit equation in firmware to convert from the pulses per second to a flow rate should give a much more accurate flow rate than the () equation provided in the datasheet.
Tiny Flow Sensors
Tiny flow sensors exist in chip-size packages. These are in a group of products called MEMS (micro-electro-mechanical system) devices.
Sensirion makes small 10 × 10mm liquid flow sensors (the LPP10 and LPG10). They are based on thermal MEMS elements. They can measure between 0 and 1000uL/min (1mL/min), with a resolution that can be as low as 0.5nL/min. It has a response time of 40ms/sample. It is compatible with H2O, methanol, ethanol, and blood.

Electromagnetic Flow Sensors
Electromagnetic flow sensors (aka magnetic-inductive (MID), magneto-inductive, mag meter) measure liquid speed by using Faraday’s Law of electromagnetic induction. The law states that when a conductor moves through a magnetic field, a voltage is induced in the conductor. In an electromagnetic flow sensor, the moving liquid is the conductor, and the sensor generates a magnetic field around it.1
The main advantages of electromagnetic flow sensors are that they are unaffected by changes in pressure, temperature or viscosity, and have no moving parts. This also means little to no pressure drop across the meter, and they cope well with dirty or corrosive media.5
The catch is the conductivity requirement. The liquid typically has to exceed something like 5 to 20 µS/cm (Siemens being a measure of conductivity), which is fine for acids, caustics and salt solutions, but rules out deionised water, oils and alcohols.5 A few other things to be aware of when installing one:
- The pipe must be running full — a partially filled pipe reads low.
- Allow straight pipe runs either side of the meter, on the order of 5 pipe diameters upstream and 2 to 3 downstream.
- The induced signal is only millivolts, so it is easily swamped by noise, and nearby magnetic fields will interfere with it.
Accuracy is typically around 0.5%, with a turndown ratio (the ratio of the highest to lowest flow rate it can measure) of roughly 40:1. This is noticeably worse than the 250:1 an ultrasonic meter can manage.5
Further Reading
See Hall effect sensors for more information on the hall effect principle and how Hall effect sensors are built.
See Encoders for more information on how encoders work and how they can be connected to a microcontroller.
Footnotes
-
Endress+Hauser (2024, Dec 3). Understanding electromagnetic flowmeters: Features and benefits. Retrieved 2026-08-04, from https://www.endress.com/en/support-overview/learning-center/flow-measuring-principle-emf. ↩ ↩2
-
Seeed Studio. Water Flow Sensor YF-B6 [datasheet]. Retrieved 2025-02-25, from https://media.digikey.com/pdf/data%20sheets/seeed%20technology/114991176_web.pdf. ↩
-
Seeed Studio. Home / The Devices / Data Collection Systems / Energy Management Units / Water Flow Sensor YF-B6 [product page]. Retrieved 2025-02-24, from https://www.seeedstudio.com/Water-Flow-Sensor-YF-B6-p-2883.html. ↩
-
Seeed Studio. Water Flow Sensor YF-B5 [datasheet]. Retrieved 2025-04-08, from https://mm.digikey.com/Volume0/opasdata/d220001/medias/docus/5670/1597_Seeed%20114991175.pdf. ↩
-
Heather Collins. Understanding Magnetic Flow Meters & How They Work. KOBOLD Instruments. Retrieved 2026-08-05, from https://koboldusa.com/articles/type-of-flow-meters/understanding-magnetic-flow-meters/. ↩ ↩2 ↩3




