ostaquet / Arduino-MQ131-driver

Arduino driver for gas sensor MQ131 (Ozone / O3)
MIT License
64 stars 19 forks source link

Concentration in ppb and ppm and functions to calculate the values #25

Closed ferreiradiego closed 3 years ago

ferreiradiego commented 4 years ago

In the last version, some changes was did. I didn't get it why the code return convert(9.4783 * pow(ratio, 2.3348), PPB, unit); was modified to return convert((10.66435681 * pow(ratio, 2.25889394) - 10.66435681), PPB, unit);. If you compare the table below, you can see that the values in ppb below 200 differs a lot and above 200 the second function it's better.

ppb Rs/R0 O3 y = 9,4783x2,3348 y = 10,66435681x2,25889394 - 10,66435681
10 1,12 12,34936679 3,111320483
50 1,9 42,41938405 34,79355558
100 2,5 80,50832346 73,83218626
200 3,8 213,9977425 206,9083026
500 5,6 529,175655 511,746348
1000 7,5 1046,703047 999,9960501

The function in return convert((10.66435681 * pow(ratio, 2.25889394) - 10.66435681), PPB, unit); is really better than the other?

PS.: I get it that the a and b coeficients changed, but the dubt is in the function with the subtraction of coeficient a.

If also @nitram147 may help me in my doubt I appreciate it

nitram147 commented 4 years ago

There is a need to use function like:

Instead of previous designed function:

With the latter one (fucntion without "+c") it's not possible to get zero ppb when the ratio is equal to one. So you will always get some concentration (at least 9.4783) in case that you use the latter function (function without "+c"). In extras/datasheet/ you can find files mq131_high_fit.py and mq131_low_fit.py which I designed for calculation of required a,b,c coeficients. If you want to make the function fit the lower concentration more precisely (trade-off would be that it will have bigger error on higher concentrations) you can play with sigma parameter in mentioned python scripts. Right now the higher fitting priority is set-uped for the first and last point of the curve (0 concentration, max concentration). You can add higher priority also to 10, 50 ppm/ppb points - by changing sigma line to sigma[[0, 1, 2, -1]] = 0.01