2026-03-05 10:57 AM
Hi, I am trying to develop a capacitive liquid level detector with the STM8L152 adapting an example of the STMTouch Library.
It is fine to detect if there is water or not inside a container. But when I try it in my final solution, that is to detect the presence of battery liquid inside a battery container, it does not able to differenciate the presence of the liquid. The reason is that there are metalic plates inside the battery container and I believe that the plates are blinding the capacity of the sensor to detect the liquid.
Do you know if there is any fine-tuning that I can use to help the application differentiate the the liquid from the metalic plates?
Thank you,
Rodrigo
2026-03-05 11:11 AM
Welcome @bernardo, to the community!
this is mainly a sensing‑geometry problem rather than a simple fine‑tuning issue.
Metal plates inside the battery act as strong electrodes and shield the electric field of your capacitive sensor, so the STM8L152 only sees the metal, not the change in dielectric from the liquid.
A few practical options:
Library parameters (gain, threshold, acquisition frequency) can help with noise and resolution, but they cannot fully compensate if the internal metal geometry shields the field. A mechanical/electrode redesign is usually required in this kind of battery application.
Hope that helps?
Regards
/Peter
2026-03-05 12:03 PM
Hi Peter, I really appreciate your insigths.
Before put it in practical, I would like to share some images.
The first one shows the sensor shape. I've tried to connect the peripheral area of the sensor to the ground and to an active shield. The final result was the same.
The second image shows the sample (in yellow) and the channel (in blue) waveforms. I am using a 15nF capacitor connected to the sample.
The last image shows the sample (in yellow) and the active shield (in blue) waveforms.
I am observing such behavior. When I bring my finger close to the sensor, the charging and discharging time of the channel input decreases, and I expected the opposite, since I am increasing the capacitance by bringing my finger closer.
For information, I am based on the STM8L152C6_Ex02 from the STM8L STMTouch Examples V1.1.0 library.
Please, I appreciate it if you could comment about the described bahavior and if the waveforms makes sense for you.
Thank you so much,
2026-03-09 10:34 AM
Hi, please, any suggestion regarding the charge and discharging of the channel (and sample) behavoiur?
Thank you,
2026-03-13 12:29 PM
I was at Embedded World in Nuremberg, so I wasn't able to help more deeply in the community for several days.
Thanks for the additional scope shots. The waveforms all look perfectly normal for the STMTouch charge‑transfer front‑end: clean, regular ramps and discharges, no obvious instability. That means the electronics and timing are essentially fine.
The fact that the curves hardly change between “liquid” and “no liquid” confirms my suspicion: the internal metal plates are capturing most of the field, so the sensor mainly sees metal, not the electrolyte. Library tuning won’t fix that.
As I mentioned before: to get a usable signal you will need to change the electrode geometry (long vertical strip on the outside, minimal guard towards the liquid, ideally a second reference electrode) and increase the distance or dielectric between your electrode and the internal plates. After that, fine‑tuning thresholds and gain in STMTouch should be sufficient.
Regards
/Peter
2026-03-15 10:41 AM
Hi Peter, I hope you had a great experiance at EW2026 and thanks for the waveforms analyses.
Having a second reference seems good, but do you suggest that one of the electrodes be outside the metallized area? If yes, unfortunately the metal plates occupy the entire internal area of the battery.
About the electrode geometry, regardless of the method used for measurement, with one or two electrodes, which would be more efficient for my scenario?
a) with a GND shield;
b) with an active shield;
c) with no shield.
Best regards,
Rodrigo
2026-03-18 2:40 AM
In your specific battery application the priority is to maximize the field lines that reach the electrolyte behind the internal metal plates. Any shield ring around the electrode - whether grounded (a) or active (b) - will intercept part of these field lines and therefore reduce your sensitivity to the liquid.
For that reason, option (c) no shield is the most efficient starting point: a single vertical strip electrode on the outside of the battery case, with no surrounding shield, placed where the liquid level changes.
Ground or active shields are useful to reduce environmental noise and hand effects, but only after you have confirmed that the bare electrode provides a detectable signal in the presence of the internal metal plates.
Regards
/Peter
2026-03-19 9:28 AM
Hi Peter, I have tested it with a couple of electrode geometry, including your welcome latest suggestion, but with no improvements in the electrolyte detection.
I have the same Delta value with or without electrolyte inside the battery, like the image below.
And just for your information, this is the battery type that I am talking about.
Also, I had the opportunity to test/explore a commercial fill level capacitive sensor. It uses the STM8L151G unit. I thought it was using the same STM8L touch-sensing library, but based on the waveform below I believe it uses a proprietary solution. The waveform was collected at the electrode point. It worked perfectly in all tested battery.
Regards,
Rodrigo
2026-03-20 5:28 AM
Now the picture becomes clearer, I should have asked earlier which liquid is present in your case.
It is apparently a battery with NiCd chemistry, probably with aqueous potassium hydroxide (KOH) as electrolyte, where a sensor principle designed for finger touches has reached its limits. The measurement result with the alternative product also shows that you should take a different approach - a true capacitive level sensor geometry instead of the touch library.
However, for your specific use case, I do not have a suitable, freely available library or a software recommendation. But perhaps one of the very friendly community members has already done something similar and is willing to share their knowledge.
Regards
/Peter