I spent the last few days trying to get a sense out of the black magic behind the calculations used for this sensor.
I got the math now but still there is something I feel like it is not completely accurate with the current implementation.
First of all the resulting ppm seems like a sort of normalized value; since I know e.g. CO2 ppm in clean air is around 400, the code seems not to take this into consideration. Also, configure it with a different MQ sensor doesn't seem an easy task.
For these reasons I've tried starting from scratch, inspired by http://davidegironi.blogspot.com/2014/01/cheap-co2-meter-using-mq135-sensor-with.html#.WyLQo6qFNn5.
Starting point is the power function y = a*x^b. The way to make the code more generic is to let the user provide the coordinates of two points (like @APL2017 was suggesting a while ago) which is an easy task and let the code solve the two equations and derive the values of a and b. Then, since ppm = a(rs/ro)^b, with a known value of ppm (e.g. the concentration in clear air of the gas, for co2 is 411), the equation can be solved for Ro by measuring Rs from the adc. Once a, b and Ro are known, the ppm comes naturally by solving again ppm = a(rs/ro)^b.
I'm not sure this is better than the other methods but at least I get the same results from the blog above, both in terms of values of a, b and Ro as well as a real value of CO2 ppm measured with a MQ135.
The downside of this of course is the difficulty to provide a known value of ppm for the calibration for other gas like e.g. Ch4, but if I claim I'm showing a ppm value, I want to be sure this is a real ppm
The code is here, within the dev branch of NodeManager, any feedback would be appreciated!
https://github.com/user2684/NodeManager/blob/19e37a45792be4d698a1316bf6eb4f954a8455f5/NodeManagerLibrary.ino#L2441