Calibración y estandarización de mediciones de calidad del aire usando sensores MQ

Calibration and standardization of air quality measurements using MQ sensors

Yersson Ramiro Carrillo-Amado1* , Miguel Angel Califa-Urquiza2 , Jacipt Alexander Ramón Valencia3

1*Especialista en Gestión Ambiental,, Universidad de Pamplona, Pamplona, Colombia.

2Ingeniero Electrónico,,, Cúcuta Norte de Santander, Cúcuta-Colombia.

3Doctor en Ingeniería Química,, Universidad de Pamplona, Pamplona, Colombia.

Cómo citar:
Y.R Carrillo-Amado, M.A Califa-Urquiza y J.A Ramón-Valencia, “Calibration and standardization of air quality measurements using MQ sensors”. Respuestas, vol. 25, no. 1, pp. 70-77, 2020.

Received on May 30, 2019; Approved on November 3, 2019


To perform the calibration and standardization of the air quality measurements through the MQ sensors, a mathematical relation was used based on the information provided by the manufacturers of the sensors through their data sheets, using the linear mathematical regression model that allowed to create the libraries for the sensors MQ-2, MQ-3, MQ-4, MQ-5, MQ-6, MQ-7, MQ-8, MQ-9, MQ-135, MQ-131, MQ-303A, MQ-309A, These libraries are characterized by being open source, and are available to the public, whose software tool allows to take values in parts per million (ppm) from the value of the resistance read in the sensor, allows to obtain data which are similar to other scientific studies given that they give in the same units, which serve to perform studies in the environment, pollution, analysis in industrial processes.

Keywords: Arduino, calibration, Air quality, fitting data, MQ sensors.


Para realizar la calibración y estandarización de las mediciones de la calidad del aire a través de los sensores MQ, se empleó una relación matemática con base en la información proporcionada por los fabricantes de los sensores a través de sus hojas de datos, utilizando el modelo de regresión matemática lineal que permitió crear las librerías para los sensores MQ-2, MQ-3, MQ-4, MQ-5, MQ-6, MQ-7, MQ-8, MQ-9, MQ-135, MQ-131, MQ-303A, MQ-309A, esas librerías se caracterizan por ser de código abierto, y están a disposición del público, cuya herramienta de software permite tomar valores en partes por millón(ppm) a partir del valor de la resistencia leída en el sensor, admite obtener datos los cuales son similares con otros estudios científicos dados que dan en las mismas unidades, las cuales sirven para realizar estudios en el medio ambiente, contaminación, análisis en procesos industriales.

Keywords: Arduino, calibración, calidad del aire, datos de ajuste, sensores MQ.


Nowadays compact and portable devices are known to measure the concentrations and quantities of pollutants present in the air [1], the air in populated urban centers shows an increase of pollutants present in it; therefore, the poor quality of the air increases [2], due to the progression of companies and vehicle fleets that generate more pollutants in these urban areas [3]. One of the biggest problems is the lack of information on air quality [4] due to two factors: the first is the lack of monitoring and the second is the lack of studies on air quality [5]. Air pollution affects respiratory diseases such as asthma and allergies [6]. The major pollutants and undesirable substances can harm the health of living beings, which are divided into two groups for monitoring and analysis, On the one hand, there are the particulate matter (sooty dust, ashes) and aerosols; on the other hand, the polluting gases (CO, CO2, NOx, SO2, volatile hydrocarbons, VOCs, and tropospheric ozone) [7]. The purpose of the research was to create a device that takes data on the concentrations of contaminating gases present in the air, measuring the values of the concentrations of each contaminant. The most common measures used to express these concentrations are mg/m3, although parts per million (ppm) are also used [9].

Proposing a device based on a network of low-cost monitoring systems using Arduino [10], with a series of gas sensors from the MQ line [11], for which sensors MQ-2, MQ-3, MQ-4, MQ-5, MQ-6 were used, MQ-7, MQ-8, MQ-9, MQ-135, MQ-131, MQ-303A, MQ-309A, which are based on the intake of specific contaminating gases [12], and their mathematical calibration is accurate for the precision of commercial monitoring equipment. To perform the calibration of the sensors [13] a known reference value/standard was used, extracted from their data sheet [14] and the known reference value changes according to the sensor model being used, taking data which is estimated by tests and adjustments in order to be able to precise real data and thus encourage the construction of devices under free licenses. The calibration parameters of the MQ sensors are a great contribution, since these sensors are taken analogically through the pins of the Arduino, which become digital by the converter of the same; This device will help to mitigate air pollution, due to the monitoring that can be done in places where there are high sources of pollution, the relevance of the project is of great importance in the inspection and verification of air quality.

Materials and Methods

For the development of this research, bibliographical references to the problem of air pollution were taken into account, which allowed us to know how to follow up on this enigmatic problem, providing a clear proposal that leads to the abatement of air pollution.

At the international level, the work carried out by [15] is highlighted, where it is stated that one of the great health problems today is air pollution, due to the increasing levels of contaminants in the air. Currently, in large cities, it is attributed to the occurrence of health problems in human beings due to contaminating agents caused by the growth of the oil industry, services, agro-industry and the increase in automotive units. Therefore, it calls on Latin American countries to exercise control over air quality through a monitoring system that will allow them to reduce various health problems.

In Colombia [16], specifically in Medellín in 2017, through monitoring to determine air quality, an orange alert was declared in the city to avoid more alarming cases and thus reduce the risk of disease caused by poor air quality.

The Institute of Hydrology, Meteorology and Environmental Affairs (IDEAM) [17], through the Regional Autonomous Corporations, is responsible for monitoring air quality. For this reason, it has stations located only in the country's large cities, which has made it possible to establish that there is greater environmental pollution, determining that air quality in Colombia has decreased as in the rest of the world, which is worrisome for the health conditions of the inhabitants.

Because only in the big cities and in strategic points, the stations are located to monitor the air quality, leaving the small cities without monitoring, as there is no monitoring, there is no control and therefore the pollution grows due to the overflow of pollutant sources, anywhere and leaving out the health of the people.

To this problem of lack of monitoring in small places, authors like [18], after years of research, managed to develop a network of wireless sensors, obtaining a viable solution through the integration of hardware and software, being the open source platforms, like Arduino and raspberry PI, the most used, obtaining a high impact due to its low cost and great variety of sensors, which made possible the environmental monitoring and data collection at small scale.

19] They conclude that, with the development of industrial technology, China's smog climate is frequent and affects air quality and human health. They noted the importance of monitoring indoor air quality in real time and making timely processing, for which they designed an air quality monitoring system based on the ZigBee wireless sensor network. The system consists of several terminal modules, a coordination module, a control module and a monitoring center. The terminal module collects data using a variety of sensors and sends it to the monitoring center via GPRS. Once the air quality index exceeds the set threshold, the user is immediately alerted and the corresponding air purification process is carried out. The system is simple and convenient, the monitoring result is accurate, the real-time performance is high and the application is extensive.

In Colombia, the work of [20] showing the current technological and scientific progress has also been highlighted. It has promoted the development of systems that improve the quality of life of people, contributing to the well-being of the community by providing relevant and pertinent information for decision making. In the technological context of the Internet of Things (IoT), these systems involve the measurement and monitoring of various environmental variables.

Such issues have generated interest in the development of methods and tools to support the heterogeneity of sensor data, measurements and measurement devices. There are private tools that have solved some of these interoperability problems, but they restrict IoT project developers to use sensors of specific brands, limiting the widespread use in the community. Additionally, the challenge of integrating diverse protocols into a single one needs to be solved.

In order to solve these difficulties, an architecture based on sensor and software networks inspired by free culture is proposed, which allows communication through diverse protocols in an application scenario where air quality is monitored to inform users, and which through the generation of alerts favours decision making in their daily lives, taking into account data from sensors.

Therefore, this work is focused on developing a unified open source library for MQ sensors in Arduino, embarked on three stages. The first stage is a mathematical analysis of the factory specifications of each sensor to carry them out to a regression model with improved computable characteristics; the second stage consists of building an Objects Oriented Programming Library (OOPL) under license from MIT and released online through the GitHub web platform [21], for this purpose an object capable of measuring certain gases described for the data sheets released by the factory is defined for each type of sensor; The third stage is simpler than the second one, this only tests the behavior of the sensors when the preheating process has several considerations on the literature like preheating time (PWT), but these considerations lack theoretical pillars, even when the factory defines PWT.

Mathematical Modeling

The MQ sensor data sheet describes the PPM ratio using the terms Rs/Ro, where Rs is the internal resistance of the MQ sensor in time, and Ro is the value of Rs in clean air. The specifications have graphs of MQ sensor behavior for some gases using the Rs/Ro ratio, allowing information to be obtained on how to measure each type of gas, so Fig. 1 shows the graph of gases readable for MQ-6 from the technical specifications on the Rs/Ro ratio and using a logarithmic scale.

Figure 1. Sampling spaces of the technical specifications by Factory

In fact, Fig. 1 not only gives the specifications of the data sheet, but the blue lines of the axis indicate a way to indicate the value of the variables PPM and Rs/Ro for LPG, in this case the value of the reading axis for the selected point is sufficient, CH4 and Air is not readable directly from the scale, but it is possible to complete the axis values to know how the value is. For each gas 3 points were obtained in the spaces avoiding average values where an external approximation is required using equation (1).

pm is the required midpoint
pinf is the lowest point using the logarithmic scale (to the left of the point)
psup is the upper point using the logarithmic scale (to the right of the point)

This procedure is applied to all the gas from each sensor and transferred to an Excel book to obtain linear equations using the simple linear regression calculation procedure in equation (2), where the data needed for the calculation is presented and the Excel equation is automatically applied when the user requests a trend line.

m are the slopes of the trend line
n is the number of samples used for the calculation
yi is an i-th term for data representing a value for the Rs/
Ro relationship
xi is an i-th term for data representing the PPM value
b is the intercept y when x=0

An example of the trend line calculation for HANWEI's MQ-309A can be illustrated in Figure 2. This trend line was plotted with some samples and the R2 score is added to the legend in order to quantify the error present for this data.

Figure 2. Trend lines for MQ-309

MQ-309A only measures PPM for 4 gases, but another sensor like the MQ-2 can measure almost 6 gases. Tables I and II describe the trend lines obtained for all the MQ sensors taken in this work, where there are 6 from the Sparkun factory, except for the MQ 5 which is from the shape parallax factory, but using the maximum space comfortably are presented in Table I. On the other hand, Table II includes sensors with factories from Pololulu, Haoyuelectronics, Sensorsportal and HANWEI Electronics.

Table I. Sparkun factory MQ sensors used for calibration and testing

Table II. Sensores de. Pololulu, Haoyuelectronics, Sensorsportal y HANWEI Fábricas de electrónica

Assembly of the Library

With all the models obtained from the previous section, the next step was to build the library for an embedded hardware in order to code equations in a programmable device for data acquisition and monitoring. The library contains only one class described in Figure 3, where the methods and global variables for each MQ sensor are specified. This class diagram was made using the Arduino programming language, which seems to structure C++ respecting the manipulation of variables and main statements.

Table III. Class diagram for control actuators

The first version of the code had a massive storage consumption on the atmega328 microcontroller, due to the global variables and their data type, testing arrays, lists, and others, finally it was selected as compiler variables using the #define instruction, this spends 25% for the Arduino Mega 2560 development boards and 45% for Arduino UNO. On the other hand, the coding takes into account the OOP paradigm, this is a standard structure from the basic programming paradigms such as structures or processes and concurrent paradigms. Finally, to make this library scalable and repeatable, the authors have released code in the GitHub platform under the integration of MIT licenses, allowing the general public to modify, download, use and distribute the library recognizing the authors' work on it [21].

Results and Analysis

The obtained values are measured in ppm or mg/l, it must be taken into account that the supply voltage must be an ideal standard voltage 5 volts, if you have a MCU board that has a voltage of 3.5 volts or other similar ones will handle similar TTL voltages, which can be 3.3 or 5 volts depending on the manufacturer, you must consider the analog input, so that you can read the sensor voltage at the exact point you want to measure. The library is published in GitHub,,la. The first folder contains the datasheets of each manufacturer from MQ 2 to MQ 309A.

The Excel graphs were initially made to extract the equation y = mx +b, because it was believed to be the most accurate, it was noticed that, if the graph of the sensors was linearized, it was not going to obtain an appreciation that was sought, so the graph was adjusted to the one that had more accuracy according to the datasheets provided by the manufacturers.

For this process of approaching the data provided by the manufacturer, an online tool called webplotdigitizer was used, for which all the points of gas types that can be measured by the MQ sensors were extracted, exported to Excel files, which can be consulted in the GitHub folder, called webplotdigitizer MQ, within Excel you will find the extracted points, the graphs made and compared with each MQ datasheet.

Figure 3. Sensitivity characteristics of the WQ-4

It should be noted that the sensors must be preheated for a certain time, the recommendation is 48 hours to be stable and constant, after they perform this process must observe the serial port, no matter what resets the Arduino, what is doing is a heating of the internal resistance of the sensor.

When you open the serial port you are already collecting data, you must take into account programs to collect data, node, Python, in our case of the realization in principle in an online program, which read the serial port and taking it to Excel in .csv, leaving a prologue time, throwing more than 2000 data.

After this time, you can already calculate the average R0 in clean air, the recommendation to take these data that lead us to the R0 of clean air, is that there should be, no humidity, the place to be airtight, clean, without the presence of dust or smoke particles and gases.

With the Ro value obtained, depending on the sensor being used, open the example folder of the sensor you want to use, enter the function of the sensor already determined is passed to the library, leaving the library calibrated to the sensor determined, leaving a standard sensor.

In one of the folders there's a contribution code where you can correct the errors in the libraries, which are open source, you should also take into account that the corrections should be made in English, because it's for the global community, where these libraries are in English, all the concerns will have a review by the team to solve the problems raised by the community, all this library is in the GitHub repository should only be downloaded and used.

For MQ2 R0 means resistance to 1000ppm hydrogen.
For MQ3 R0 means resistance to 0.4mg/L of alcohol in clean air.
For MQ4 R0 means resistance to 1000 ppm CH4 in clean air.
For MQ5 R0 means resistance to 1000 ppm of H2 in clean air.
For MQ6 R0 means resistance to 1000 ppm of LPG in the clean air.
For MQ7 R0 means resistance to 100 ppm of CO in the clean air.
For MQ8 R0 means resistance to 1000 ppm of H2 in the clean air.
For MQ9 R0 means resistance to 1000 ppm of LPG in the clean air.
For MQ131 R0 means resistance to 50 ppm of LC2 in the clean air.
For MQ135 R0 means resistance to 100 ppm of NH3 in the clean air.
For MQ303A R0 means resistance to air.
For MQ309A R0 means resistance to 1000 ppm of CH4.

MQ Sensor Calibration

For more advanced studies which already know the environment, the sensors and the libraries, you must access a calibration program which is in the libraries placed in GitHub, this calibration is due to the reading of the MQ sensor, it is reading the ratio Rs/R0 in the air, having emphasis in the greater enhancement of the purity of the air, because there it starts for the reference for the value of 0, as a review.


This software tool allows to take the values in parts per million (ppm) from the value of the resistance read in the sensor, allows to obtain data which are comparable with other scientific studies given that they give in the same units, which serve to carry out studies in the environment, contamination, analysis in industrial processes.

This tool allows to obtain internal parameters such as voltage, calculated Rs, configured Ro, RL and the value in ppm, therefore, if a researcher collects all this information it makes the experiment recreable as many times as possible.

The library is designed in such a way that it supports a variety of MQ sensors so it can be concluded that an Arduino can be used to read as many sensors as there are analog inputs available.


[1] J. Rubio, A. Hernandez and F. Avila, “Sistema sensor para el monitoreo ambiental basado en redes Neuronales”, Ingeniería Investigación y Tecnología, vol. 18, no. 21, 2016.

[2] L. Granada, I. Perez, M. Valencia, R. Rojas and I. Herrera, “Sistema para el manejo de la calidad del aire en la ciudad de Cali - Colombia”, Ingeniería Industrial, vol. 35, no. 1, 2014.

[3] M. Romero, F. Diego and M. Alvarez, “La contaminación del aire: su repercusión como problema de salud”, Revista Cubana Higiene, Epidemiología y Microbiología, vol. 116, no. 2, 2006.

[4] M. Estebana, M. Bote, C. Alejandre, M. Balaguer and I. Jordan, “Influencia de los factores meteorológicos y contaminantes del aire en casos de bronquiolitis grave en el área metropolitana de Barcelona: estudio piloto”, Analesdepediatria, 2019.

[5] C. Marodones, “Impacto de la percepcion de la calidad del aire sobre el precio de las viviendas en concepción-talcahuano, Chile”, Cuadernos de Economía, vol. 43, 2006.

[6] F. Vargas, “La contaminación ambiental como factor determinante de la salud”, Revista Española de Salud Pública, vol. 79, no. 2, 2005.

[7] J. Jiménez and D. Pulgarin, “Sistema de indicadores de la calidad del aire para puertos maritimos colombianos”, Revista Gestión y Ambiente, vol. 13, no. 3, 2010.

[8] F. Ballester, “Contaminación atmosférica, cambio climático y salud”, Revista Española de Salud Pública, vol. 79, no. 2, 2005.

[9] E. Aránguez, J. Ordóñez, J. Serrano, N. Aragonés, R. Fernandez, A. Gandarillas and I. Galán, “Contaminantes atmosféricos y su vigilancia”, Revista Española de Salud Pública, no. 2, 1999.

[10] S. Abraham and X. Li, “A Cost-Effective Wireless Sensor Network System for Indoor Air Quality Monitoring Applications”, Procedia Computer Science, no. 34, 2014.

[11] A. Husain, T. Hassan, M. Ikramul and R. Alam, “Air Quality Monitoring: The Use of Arduino and Android”, Journal of Modern Science and Technology, vol. 4, no. 1, 2016.

[12] C. Discoli and D. Barbero, “Insustentabilidad urbano-energética-ambiental. determinación y cuantificación de contaminantes aéreos y sumideros”, Avances en Energías Renovables y Medio Ambiente, vol. 15, 2001.

[13] G. Gasparece, “Driver Alcohol Detection System Based on Virtual Instrumentation”, IFAC PapersOnLine vol. 51, no. 6, 2018.

[14] K. Devadoss, “Seguridad humana contra la muerte que desafía a los gases utilizando un sistema de sensor inteligente”, Investigación de detección y bio-detección, vol. 7, 2016.

[15] M. Romero, F. Diego and M. Alvarez, “La contaminación del aire: su repercusión como problema de salud”, Revista Cubana de Higiene y Epidemiologia, vol. 2, no. 44, 2006.

[16] J. Pérez, “La calidad del aire en colombia: un problema de salud pública, un problema de todos”, Biosalud, vol. 45, no. 5, 2017.

[17] J. A. Huerta, “Propuesta para establecer un sistema de vigilancia de contaminantes ambientales en Colombia”, Biomédica, vol. 35, no. 2, 2015.

[18] S. Ferdoush and X. Li, “Wireless Sensor Network System Design using Raspberry Pi and Arduino for Environmental Monitoring Applications”, Procedia Computer Sciencie, vol.34, pp. 10-110, 2014.

[19] H. Luo, L. Wang and X. Wu, “Design of indoor air quality monitoring system based on wireless sensor network”, IOP Conf. Series: Earth and Environmental Science, vol. 208, 2018.

[20] A. Ochoa, L. Cangrejo and T. Delgado, “Alternativa Open Source en la implementación de un sistema IoT para la medición de la calidad del aire”, Revista Cubana de Ciencias Informáticas, vol. 12, no. 1, 2018.

[21] M. Califa, G. Contreras and Y. Carrillo, “ 28 Septiembre”, En línea:, 2019

Licencia de Creative Commons
licencia de Creative Commons Reconocimiento-NoComercial 4.0 Internacional