MQ Sensors Series Read the Gas Concentration with Arduino R4 Wi-Fi

AndroidCrypto
4 min readAug 1, 2024

--

Reading the data sheet of an MQ-Sensor tells you what gases this sensor can detect, e.g. the MQ-2 sensor can detect Hydrogen (H2), Liquefied Petroleum Gas (LPG), Butane (CH4), Carbon Monoxide (CO), Alcohol, Smoke and Propane (C3H8). This tutorial tells you all about the reading of the concentration of a specific gas.

I’m starting with a link to the datasheet of one sensor, in my case the MQ-2 sensor (Link to Mouser Electronics). On page 2 you find a colored diagram:

Copyright is Mouser Electronics / HANWEI ELETRONICS CO.,LTD, http://www.hwsensor.com

I’m far away to been able to explain all characteristics of this diagram, but some facts are clearly visible:

  • both axes don’t follow a linear but a logarithmic scale
  • all gases nearly follow the same curve (but not exactly)
  • the value of the y-axe decreases with a higher concentration (y-axe maximum is 10000 ppm = particles per million)
  • the value of the x-axe is a ratio “Rs / R0”
  • most important: the “LPG” and “Propane” line (and, with some limitations, the “H2” line) are the ones that indicate the highest decrease (don’t forget, it’s a logarithmic scale). This is the indicator on what gases the sensor is most sensitive, in this case “flammable gases”

The diagram is followed by a second one, showing the dependence of temperature and humidity on the “Rs / R0” value:

We can read the following information out of the diagram:

  • both x- and y-axes are linear
  • the “Rs / R0” value decreases when the temperature is higher
  • the “Rs / R0” value decreases when the humidity is higher
  • if you need correct absolute values from this sensor, you need to measure the current temperature with another sensor and adjust the data accordingly

As a summary, there seems to be a connection between the concentration of a specific gas and the value “Rs / R0”, and the value “Rs / R0” is reversed linear proportional to the voltage on the Analog Output Pin of the sensor module. So far so good, but…

How can I measure the concentration of a specific gas in the air ?

The answer is simple but frustrating: you can’t ! The MQ Sensor Series are “stupid ones”, meaning that the resistance of the sensor plate depends on a gas mixture. All of these sensors are based on a typical “clear air” mixture of gases, and if the air contains any of the specific gases the resistance will change, that our Arduino device can measure as a change in voltage on the Analog Input Pin.

Of course, there are libraries like the “MQSensorsLib” one that give out a calculated value in parts per million for a specific gas, but this is done by running a mathematic calculation (mainly based on logarithmic methods on a typical air mixture) on the measured voltage. You cannot tell the sensor by a command to measure e.g. the Carbon Monoxide gas concentration now; the sensor is just changing its resistance depending on one or more of the named gases.

This is the “gas concentration” of the 6 detectable gases of an MQ-135 sensor and, as you can see clearly, all values are changing synchronically but with different values, due to different parameters on the calculation:

MQ-135 Sensor readings

To make it short: you are not able to say “only the Carbon Dioxide” (CO2) value raised above a thread hold value, but the others are in “normal” range. The good news is: if you are using this sensor to get warned about a too high concentration of Carbon Dioxide gas, this will work but with too high concentration of Alcohol in the air as well. In the end, you don’t want to stay in the room either with too much Carbon Monoxide, Carbon Dioxide or Alcohol in the air.

This tutorial is part of a series of articles; an overview about all articles is available using this link.

--

--