An AI-Based Approach to Gas and Liquid Flow Verification

By Jon Gabay

Contributed By Electronic Products

Measuring or verifying that there is gas or liquid movement typically uses electromechanical techniques. Paddlewheels in the path of flow drive optical or Hall sensors, as well as a measurement of RPM, provides a good indication of flow rate. Another approach is to use a strain gauge to measure stress, like a sail connected to a spring gauge. While effective, these mechanically based approaches can suffer from frictional wear and breakdown and can fail when dirt, corrosives, or shock damage the mechanisms.

A high degree of consistency and purity of the gas or liquid offers the option of using optical and sonic measuring techniques. Refined fluids like fuel, which have tightly constrained characteristics, take advantage of optical properties or sonic properties to measure flow. It is analogous to looking for the resonant sound pitch as air blows across the top of a bottle. Predictable and easy-to-build circuits can detect the variable you are seeking.

This article looks at the technique of using a temperature-sensing thermistor to detect flow. This approach uses a self-heated mode coupled with a slope-analysis, AI-based algorithm to reliably measure and verify that there is fluid or gas flow through a pathway. All parts, datasheets, tutorials, and development kits mentioned are available online at Digi-Key’s website.

Thermistor characteristics

A thermistor is a two-terminal, thermally-sensitive resistor. It exhibits a change of resistance with a change in temperature.

Two types of thermistors exist. NTCs are negative coefficient changing where the resistance decreases with temperature. PTCs are positive coefficient changing with resistance increasing with increasing temperature. Both types are available, but NTCs are more common.

A particular thermistor will be specified to have a nominal resistance and tolerance, usually at 25°C. The change in resistance is proportional to the temperature change with a coefficient, which is typically not a linear relationship. As such, manufacturers will typically provide tables of temperature vs. resistance variations for a particular family. For example, the Panasonic ERT-JZEG103JA is part of the ERTJ series, and the particulars of the non-linear coefficient are provided in the data sheet, in a table based on resistance ratios.¹

Thermistors are advantageous because they are rugged, have a good usable range (typically –100° to +325°C), have good accuracy (typically 0.05° to 1.5°C), are low cost, and are rarely susceptible to outside noise.

Thermistors also have disadvantages. They must be hermetically sealed, as moisture infiltration can cause failures. The nonlinearity can be looked at as a disadvantage as well, since to perform accurate reading, curve-fitting algorithms or processor-based lookup tables may be needed. The other disadvantage is self-heating.

Self-heating occurs because thermistors behave like resistors and will dissipate power. At high resistances, self-heating is usually negligible. However, when biased with higher voltages and lower resistances, self-heating can cause false readings and even self-destructive thermal runaway conditions with NTC-style parts.

This self-heating can be used to measure the ability of its surroundings to extract heat. Here is how this technique works.

Establishing a baseline

The first step is to place a hermetically sealed thermistor in the flow path of the gas or liquid to be monitored (Figure 1). Always make sure that the composition of the thermistor body and leads are insensitive to corrosion from the exposed flow. The mechanical structure must also be robust enough so as not to stress and deform the thermistor mount at maximum flow rates.

Thermistor in line with the flow

Figure 1: With the thermistor in line with the flow, we can measure the rate at which heat is removed.

Before any active changes can be detected, a baseline must first be established. In this case, a baseline will indicate the ambient temperature before any flow begins to take place. You will need to set a threshold or limit point to indicate that no further self-heating will take place, especially with NTC types of thermistors, which draw more current the hotter they get.

With the characteristics of the chamber and ambient temperature known, three conditions can be deduced. The first is if the thermistor is gas locked.

When the thermistor is gas locked and the fluid chamber is empty, self-heating pulses will heat up the thermistor very quickly. In this case, heat is dissipated mostly through radiation and takes place slowly in a static gas- or air-filled chamber. In a similar vein, with slow dissipation of heat, the thermistor will take more time to cool back down to ambient temperatures (Figure 2).

A gas-locked thermistor

Figure 2: A gas-locked thermistor will heat up very quickly and cool very slowly. A measurement of resistance change will indicate this.

With a static, non-flowing fluid state, the denser fluid acts as a heatsink and draws heat away from the thermistor. As a result, the thermistor heats up more slowly and it takes more time to reach the threshold resistance (Figure 3).

A static liquid state will act as a heatsink

Figure 3: A static liquid state will act as a heatsink, slowing down the rate of heating. Cooling will take place more quickly compared to a gas-locked state.

With flow, comes the fastest removal of heat. As a result, the heating will take a very long time to reach the threshold. When it does, it will cool down very quickly (Figure 4).

Flow removes heat the most quickly

Figure 4: Flow removes heat the most quickly. The slope indicates that flow is present and can even indicate flow rate.

A key point is that you do not have to reach the threshold to know the slope or rate of change of heating. Alternatively, you can make it reach threshold and use time as the determining factor.

Another point is that if you want to compensate for any variation in the incoming temperature of the flowing gas or fluid, a second thermistor can be used before the flow sensing circuit. This lets you adjust your expectations if a temperature change is coming from the flow.

Dual-mode circuits

A dual-bias circuit is used to switch between measurement mode and self-heat mode. Solid-state elements or an electromechanical relay can be used to isolate self-heat voltages from system voltages (Figure 5).

A dual-mode circuit

Figure 5: A dual-mode circuit allows the micro to switch in the self-heat bias stage. Typically, a normally closed contact is used for measurement mode as a secondary fail-safe so that if the micro locks up, the thermistor is not heated to self-destruct.

A few safety points must be made. An NTC thermistor that is overdriven too much can burst into flames. Most likely, an embedded micro will control the mode and read the thermistor, and micros can fail and go into lockup states. As a result, a fail-safe measure makes it unlikely that the circuit can be locked in self-heat mode.

One way to guarantee this is to have the micro trigger a non-retriggerable, monostable multivibrator (a one-shot pulse generator), so that if it gets into that state, it is not frying the thermistor.

This is also useful since a one-shot has a fixed pulse width. A micro can have jitter in the pulse associated with interrupts delaying its turn off. With a known fixed pulse-width, you know how much energy you are pumping into the thermistor each pulse.

Another safety trick is to make the one-shot pulse width relatively narrow, and have the micro trigger it with a pulse train of “N” pulses. This allows more control over how much energy is pumped into the thermistor for each excite/measurement cycle and assures that the maximum energy delivered to the thermistor is small in case of a circuit glitch.

The AI shell

As you may have deduced, a real-time heartbeat is a crucial part of a control algorithm. A time measurement of successive cycles is what determines the slope, so the accuracy of the time trigger is key.

As a result, the timer counter interrupt service routine is fast and simple. In each real-time clock interrupt, a statistical block of samples (8 in this case) is taken and stored in a location of a three-dimensional memory array (Figure 6). Also accumulated and calculated for each sample block are an average value, peak, and low value for that sample block. This process is analogous to an autonomic function.

Background and foreground processing

Figure 6: Background and foreground processing can let thermistor data be used to make high-level assessments of the system state using inference and deduction engine rule-based processing.

A circular buffer pointer is shared with the foreground. The foreground routines execute in two parts. A non-critical, timer-based “subconscious” processor looks at the data blocks when no other real-time critical functions are taking place. The first thing is to check for error situations. If the difference between the peak and low value is more than a pre-determined amount, you may flag an error situation. This could indicate the temperature in the system is changing faster than it should when the system is operating normally. In a noisy environment, it could indicate a corrupted sample block. In either case, it can trip an interrupt that examines the data more closely, or discards a sample block as corrupt.

If no threshold violations occur, the subconscious foreground routine calculates average slopes from the peak, low, and average data blocks in the circular buffer. The three are averaged again to create a trending average. This verifies that indeed a heating cycle or cooling cycle is taking place.

The magnitude of the slope and the actual state determination is made in the foreground process as needed. A tabular list of rules is executed acting as a deduction engine, which can look at slope magnitudes, peak variations, and any data in the sample array to create a weighted value that updates one of the state accumulators. For example, an average slope greater than 4 will indicate cooling is taking place very quickly, so the flow accumulator would get a large number added to it. At the end of the processing of the tabular rule set, the accumulators will hold the data needed to make a state determination.

Note, with the known diameters, pressure, input temperature, specific gravity of fluids, thermal coefficients, etc., the sample array can be further processed to make a determination of flow rate. This is done in the conscious foreground processing routine, as well.


Processing algorithms can extract a lot of usable information from sensors that can be used to make high-level deductions. You can adjust what processing is done in the background and foreground and even compress the process into one contiguous processing block if there are no other real-time processing constraints. You can also adjust the depth of the sample blocks and rule sets. This is just one of many examples of using AI-based algorithms and processing to make high-level assumptions.

  1. Panasonic ERTJ Multilayer thermistors

Disclaimer: The opinions, beliefs, and viewpoints expressed by the various authors and/or forum participants on this website do not necessarily reflect the opinions, beliefs, and viewpoints of Digi-Key Electronics or official policies of Digi-Key Electronics.

About this author

Jon Gabay

About this publisher

Electronic Products

Electronic Products magazine and serves engineers and engineering managers responsible for designing electronic equipment and systems.