MQ-2 Sensor (Flammable and other gases) usage with Arduino R4 Wi-Fi
The Arduino Rev 4 Wi-Fi microcontroller is the perfect choice when collecting and analyzing sensor data from the MQ-2 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.
Please find the technical data and wiring of the sensor and the OLED display in the overview article.
Detectable gases with this Sensor
The sensor is designed to detect these gases and their concentration in the air: Hydrogen (H2), Liquid Petroleum Gas (LPG), Carbon Monoxide (CO), Alcohol and Propane (C3H8).
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 800 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-2 Sensors
You may think that it is not important to run a “Burn-In-Period” but this is essential to get good results. An MQ-2 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-2 Sensor together with other sensors like a DHT11 Temperature Sensor
As the MQ-2 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-2 Sensor to avoid any wrong measurements.
General note on different gases measurement with one Sensor
Although the MQ-2 gas sensor detects 5 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 Propane will rise for 10 percent as well. This sensor can be used as a breath alcohol concentration sensor. Please keep in mind that the alcohol concentration in the breath air will be different to the one in the blood, so don’t rely on the measured values.
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.
The peak was controlled by me — I hold a cigarette lighter near the sensor and pushed the gas button.
Output on the Serial Monitor
| H2 | LPG | CO | Alcohol | Propane |
| 5.50 | 2.77 | 21.16 | 5.87 | 41.59 |
| 5.48 | 2.76 | 21.06 | 5.84 | 41.44 |
How can I test the sensor ?
The easiest way to test the sensor is by using an opened bottle with high concentrated alcohol near to the sensor. Just hold the sensor to the bottle opening and see that the gas readings will rise. Another way is by using a cigarette lighter and push the gas button near the sensor.
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-2 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_2_ALL_OLED_ThingSpeak
Thank you for reading and “Happy coding”.