Seeking Guidance on Understanding MQ-7 Carbon Monoxide Sensor Math

I'm currently working on a project involving an MQ-7 Carbon Monoxide (CO) sensor. To integrate the sensor, I've been referring to a guide that provides code in YAML for ESPHome. However, as I'm using the Arduino framework for my project, I'm encountering mathematical expressions in the code that I'm struggling to understand.

Here are the equations I'm grappling with:

Temperature and humidity compensation: mq7_compensated_resistance = mq7_resistance/( -0.0122*T - 0.00609*H + 1.7086)

Ratio calculation: mq7_ratio = 100*mq7_compensated_resistance/mq7_clean_air_compensated_resistance

Further manipulation of the ratio: ratio_ln = mq7_ratio/100

Final CO concentration calculation: co_ppm = exp(-0.685 - 2.679*ratio_ln - 0.488*ratio_ln*ratio_ln - 0.078*ratio_ln*ratio_ln*ratio_ln)

I'm reaching out to seek guidance and clarification on these mathematical expressions. Could someone help me understand the underlying principles behind these equations? Additionally, if you could point me to any educational resources or documentation that might assist me in grasping these concepts, I'd be extremely grateful.

I've already referred to the datasheet for the MQ-7 sensor and have the graphs in hand now, but I'm still struggling to connect the dots. If you have any insights or can provide further explanation, it would greatly aid my project progress.

ESPHome Guide : MQ-7 Carbon Monoxide Sensor | devices.esphome.io

MQ7 Sensitivity Characteristic Curve : MQ7 Sensitivity Characteristic Curve - Album on Imgur

MQ7 Temperature and Humidity Curve : MQ7 Temperature and Humidity - Album on Imgur

Thank you all in advance for your assistance and insights.

TL;DR: Seeking help to understand the math involved in integrating an MQ-7 Carbon Monoxide sensor with an ESP8266 using Arduino. Specifically, I'm looking for guidance on temperature and humidity compensation, ratio calculation, and CO concentration calculation equations. Any educational resources or explanations would be greatly appreciated.

What is your problem exactly?
The formulas are not that difficult...
Do they yield outrageous results?
Do you happen to know what units T and H are supposed to have in those formulas?

There may be little underlying principles. Just some curve fits could produce formulas like that...

The equations are not correct. They are only a rough approximation, and must be individually derived for each sensor. Furthermore, the equations would be valid ONLY for a particular combination of gases.

There is not much point in trying to calibrate the MQ sensor series, since all of them respond to several different gases.

If a change in the reading is detected, without additional information, it is impossible to determine which of those gases might have caused the change. At best, those sensors can only alert you to the fact that something in the air has changed.

I was just curious about how those values and equations were figured out. Like, how they pulled those specific constants from the graphs (if that's how they did it)? I think it's more about me not knowing enough rather than getting things wrong. I was kinda hoping someone could break down the math for me or point me to some resources where I could learn more about this stuff. That way, I could try my hand at figuring out similar parameters for other sensors and projects where nobody's done the math yet.

Oh, and by the way, I think the units are in Celsius and relative humidity (Rh).

Oh okay. Thank you for your insights. If I may ask, do you happen to know how to derive those approximations?

It is a standard log-log fit of the sensor response to the data.

According to the manufacturer, the sensor response is approximately a straight line on a log-log plot of the resistance ratio versus the calibration concentration.

Adafruit has an excellent overview tutorial on sensor calibration.

And this bit fits the curved humidity and temperature curves in your 3rd link.
It is a reciprocal function...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.