MQ-135 Sensor (Carbon Dioxide and other gases) usage with Arduino R4 Wi-Fi

AndroidCrypto
4 min readJul 29, 2024

--

The Arduino Rev 4 Wi-Fi microcontroller is the perfect choice when collecting and analyzing sensor data from the MQ-135 sensor module. This article is part of several tutorials about connecting MQ-x sensors to the Arduino device. You find an overview about the series and available articles here.

MQ-135 Sensor (front and back)

Please find the technical data and wiring of the sensor and the OLED display in the overview article.

Arduino Uno R4 Wi-Fi and MQ-135 Sensor setup

Detectable gases with this Sensor

The sensor is designed to detect these gases and their concentration in the air: Carbon Monoxide (CO), Carbon Dioxide (CO2), Alcohol, Toluen (Methylbenzol, C6H5CH₃), Ammonium (NH4) and Acetone (CH₃COCH₃). It is the perfect choice for measuring the indoor air quality using a cheap sensor.

Reading the gas concentration

The MQ-Sensor series offers to read several gases with one sensor, but how does this work ? I write an article about this topic: MQ Sensors Series Read the Gas Concentration with Arduino R4 Wi-Fi. I know it sounds strange, but it is really important to read the datasheet for your specific sensor to understand what gases it can detect.

Type of Sensor

This sensor is using a heater to bring the sensor plate in a defined temperature mode for measuring. As it takes some time to heat the sensor, this sensor is not suitable for a “sleeping mode” of the microcontroller device. Secondly, the heater’s power consumption less than 950 mW, so it seems not a good choice for battery or solar-powered devices. Due to these facts, the sensor should be driven by a regular power supply.

Important Burn-In Period of new MQ-135 Sensors

You may think that it is not important to run a “Burn-In-Period” but this is essential to get good results. A MQ-135 Sensor is a sensor with a heater element with a resistor that resistance depends on the gas concentration in the air. When these sensors are “off” electricity for some days or months (e.g. produced in China, stored for some months, send by ship to Europe) the surface of the resistor isn’t calibrated anymore. You need to run the sensor for about 48 hours (2 days !) with 5 Volt to “burn-in” the resistor (again). Don’t trust the measures of the sensor without the burn-in period.

Usage of the MQ-135 Sensor together with other sensors like a DHT11 Temperature Sensor

As the MQ-135 Sensor is using a heater (the sensor itself can heat up to 55–60 degrees Celsius), you should NOT place a temperature sensor beneath the MQ-135 Sensor to avoid any wrong measurements.

General note on different gases measurement with one Sensor

Although the MQ-135 gas sensor detects 6 different gases, the base for all values is one value (the resistance of the sensor that results in different voltage levels). The concentration of a specific gas is calculated by the sensor profile, but if e.g. the Carbon Monoxide gas concentration goes up for 10 percent, the value for Acetone will rise for 10 percent as well.

Display a Timeline of Sensor data on ThingSpeak.com

The sketch includes code for periodically uploading the measured gas values to a ThingSpeak channel. This gives an easy way to monitor your sensor from anywhere. If you don’t want to use the service, or you cannot connect your Arduino with a local Wi-Fi network, simply comment out the WI-FI-connection and “updateThingSpeakChannel” calls. For details, see the overview article.

Output on the Serial Monitor

|    CO    |  Alcohol  |    CO2    |  Toluen  |   NH4    |  Acetone |
| 1.98 | 0.76 | 401.72 | 0.30 | 2.81 | 0.26 |
| 1.97 | 0.76 | 401.72 | 0.30 | 2.80 | 0.26 |

How can I test the sensor ?

The easiest way to test the sensor is by using a gas driven cigarette lighter. Just press for a short time the gas output button and see that the gas readings will rise.

Where can I buy the sensor ?

My favorite seller for these sensors is AliExpress — here is a link to a search page for an MQ-135 sensor module (please don’t buy the bare sensor to avoid additional wiring).

Get the complete source code of this tutorial

The code is available in my GitHub repository https://github.com/AndroidCrypto/Arduino_Uno_R4_WiFi_MQ_Sensors_Series/tree/main/ArdUno4_MqUnifiedSensors_MQ_135_ALL_OLED_ThingSpeak

Thank you for reading and “Happy coding”.

--

--