Oxygen Library code help

I’ve found a library for an Oxygen sensor, but I don’t understand how it works. I would really appreciate it if someone could explain how it works.

Oxygen.cpp (885 Bytes)

Oxygen.h (146 Bytes)

Read_O2_value.ino (429 Bytes)

Have a look at how to use this forum and post code so people can see it.

What do you mean by "how it works"? You call the O2_value() function and get back an O2 percent in a float value.

In the library, the first call to O2_value() calculates a calibration value by averaging 64 analog readings (Pin A1) at roughly 100 millisecond intervals (6.4 seconds) and dividing the average by 20.80 (the percentage of oxygen in the atmosphere).

Subsequent calls to O2_value() will average 32 analog readings (Pin A1) at roughly 50 millisecond intervals (1.6 seconds) and divide that value by the calibration value. Getting the same average as the calibration value will get you a result of 1.0% (shouldn't that be 20.80%?!?). Higher voltage means higher percent. Lower voltage means lower percent.

The example sketch implies that the calibration will take a minute but it only takes 6.4 seconds. The example sketch implies that the result is an oxygen percentage but it is clearly not. The product documentation says:

The sensor value only reflects the approximated trend of gas concentration in a permissible error range, it DOES NOT represent the exact gas concentration. The detection of certain components in the air usually requires a more precise and costly instrument, which can not be done with a single gas sensor. If your projects aim to obtain the gas concentration at a very precise level, then we do not recommend this gas sensor.

I hope your expectations are low.