Gas bottle pressure sensor

If doesn't fit into any other category ....
BeanieBots
Posts: 351
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 187 times
Been thanked: 113 times

Re: Gas bottle pressure sensor

Post by BeanieBots »

Try using 2nd order filter to the ADC.
No harm in using electrolytic caps, so you can have MASSIVE time constants.
Suggest 10k -> 10uF -> 10k -> 10uF -> ADC
Combine that with the software averaging that cicciocb has shown and it will be rock solid.
Also add good decoupling to your power supply.
If all of the above does not fix things, then something else is fundamentally wrong.
User avatar
Electroguard
Posts: 885
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 285 times
Been thanked: 329 times

Re: Gas bottle pressure sensor

Post by Electroguard »

try this code
I replaced the sensor with a slider; you can play with the acquisition rate and the number of samples in the filter.
I've had another look at your example Francesco, and it works because the input slider is not varying, and even if the slider is moved it can take its time to reach the new value. But it doesn't work with the sensor because of its continuously changing output.

Adding the one coloured line below can simulate a changing sensor input of up to + or - 10, and shows the continuous dancing.

my_pressure = my_pressure + (rnd(20)-10)
gas = gas + (my_pressure - gas) / 50 ' filter on last 50 values

But occasionally the sensor swings can be 3 digits.
So I think I need to try to restrict the size of the swings, rather than try to keep averaging them all out.
I will try incrementing a 'magnifier' count each time the sensor indicates a move in the same direction so that it can accelerate same-direction moves, but whenever there is a change of direction it should reset the 'magnifier' count back to minimum so that it doesn't have much effect.
It either works or not, but will be interesting trying to figure out an elegant way to do it.
BeanieBots
Posts: 351
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 187 times
Been thanked: 113 times

Re: Gas bottle pressure sensor

Post by BeanieBots »

Your readings are way outside the quoted spec for the sensor.
I would suspect a faulty sensor.
Also, have a read of the reviews. Almost all are clearly fake! Very suspicious.
Confirm the readings with a DVM to at least eliminate any issues with the ESP/Code.
User avatar
Richo
Posts: 13
Joined: Mon Apr 04, 2022 3:37 pm
Location: Nakskov, Denmark
Has thanked: 31 times
Been thanked: 2 times

Re: Gas bottle pressure sensor

Post by Richo »

1.
The ESP-32 uses a SAR ADC which requires the input to be stable during the conversion
https://en.wikipedia.org/wiki/Successiv ... mation_ADC

This is done with a capacitor at the input, but REMEMBER that a resistor must also be used to act as a filter.
If the sensor has an output impedance close to zero, the capacitor is not working.
filter_adc.jpg
2.
Use multisampling to minimize noise.
The ADC is fast, so you have plenty of time to make many measurements and take the average
You do not have the required permissions to view the files attached to this post.
User avatar
Electroguard
Posts: 885
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 285 times
Been thanked: 329 times

Re: Gas bottle pressure sensor

Post by Electroguard »

Thanks for the useful info, I will add a resistor to the cap and see if that settles things down.
Also a good idea about the multi-sampling... sample many, dump the extremes, and only keep the new average to update with.
Hopefully that can provide a stable threshold signal.
The aim is to trigger an initial TTS verbal announcement and change a ceiling light from green to red whenever the gas bottle needs changing.
Might see if it's feasible to signal warning of a pending change by using a yellow ceiling light for low pressures.
User avatar
Richo
Posts: 13
Joined: Mon Apr 04, 2022 3:37 pm
Location: Nakskov, Denmark
Has thanked: 31 times
Been thanked: 2 times

Re: Gas bottle pressure sensor

Post by Richo »

An example where an active filter is chosen.
"Bessel" type gives best step response.

Selected a filter with attenuation of 40 dB at 100 Hz (40 dB=1/100)
bessel.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
Richo
Posts: 13
Joined: Mon Apr 04, 2022 3:37 pm
Location: Nakskov, Denmark
Has thanked: 31 times
Been thanked: 2 times

Re: Gas bottle pressure sensor

Post by Richo »

It would be nice to have a statistical function for calculating the Gaussian distribution.
Create an array, pour data into it from x measurements, and then have the result.

https://en.wikipedia.org/wiki/Normal_distribution

With a hardware filter, we reduce noise from the sensor and connections.
By averaging many measurements, we reduce errors in the ADC.

With an active Bessel filter we get the right result faster than a RC-filter

If we average a lot of measurements, we get close to the right result, but with a statistical function we can achieve a better result in a shorter time, IF the function is fast enough (not written in Basic)
User avatar
Richo
Posts: 13
Joined: Mon Apr 04, 2022 3:37 pm
Location: Nakskov, Denmark
Has thanked: 31 times
Been thanked: 2 times

Re: Gas bottle pressure sensor

Post by Richo »

Practical circuit.
You do not have the required permissions to view the files attached to this post.
User avatar
cicciocb
Site Admin
Posts: 2093
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 449 times
Been thanked: 1385 times
Contact:

Re: Gas bottle pressure sensor

Post by cicciocb »

I suppose that is probably too much complicated for that kind of application :roll:
Maybe a simple resistor capacitor filter should be enough. :idea:
User avatar
Electroguard
Posts: 885
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 285 times
Been thanked: 329 times

Re: Gas bottle pressure sensor

Post by Electroguard »

Software allows quick and easy changes and improvements, and especially leverages the benefits of editing Annex from a chair via wifi connection.
Was thinking of how to create a filter by using an array.
Two arrays, actually, one to hold the sampled data, and one to hold a sorted order of the sample array.
Don't want to keep shuffling the actual sampled data, just want to sort the array index of the data in a separate array.
Thinking of reading about a dozen samples, then creating a sort_order() array of the sample array in order of sample similarity.
Probably dump any ridiculous extremes, then average the remaining reasonable similarities, to add to the main gas pressure average.
Need to work out a usable sort routine to sort by similarity, and some form of yardstick for testing reasonable similarity.
Aint got a clue of how to do it yet - just have a fairly clear picture in my minds eye of where I want to get to, but not the foggiest of how to get there.
Post Reply