Introduction: Indoor Air Quality and Safety: Arduino, MQ-2 and DHT11 Project

Hello guys,

this project is a small and simple application of small sensors that can in a simple way, combined with the use of Arduino , control indoor environments containing gases some of which flammable.Using a display we can quickly access the value of the concentrations, with the help of a button we can change between the information.The use of an audible alarm enables users to be alerted quickly and effectively.

This project was developed in college during the course of biomedical technology, in no case should it be used as measuring equipment, just for educational purposes!!!


The following list of components were used to built this monitor :

  • Arduino UNO
  • DHT11
  • MQ-2
  • Display LCD 16x2
  • Potentiometer (this is to control display)
  • Buzzer (Piezo speaker)

Step 1: What Are We Measuring and the Use of MQ-2

The MQ-2 sensor is a Chemistor used to detect H2, LPG, CH4, CO, Alcohol, Smoke or Propane. Industrial or laboratory environments have many of these elements which when released can have a negative potential for human health.This sensor provides a fast response and high sensitivity.

"The sensor value only reflects the approximated trend of gas concentration in a permissible error range, it DOES NOT represent the exact gas concentration."

This small device has a wide spectrum of use:

  • 200ppm-5000ppm for LPG and propane;
  • 300ppm-5000ppm for butane;
  • 5000ppm-20000ppm for methane;
  • 300ppm-5000ppm for H2;
  • 100ppm-2000ppm for Alcohol.

In order to obtain correct readings, resistance must be preheated for a period of 24 hours.Calibration is also necessary since it has such a large working spectrum,by approaching the gas sensor near smoke/gas you want to detect and turning the potentiometer in the module you can easily adjust the sensivity, a red LED will light up when it detects.

The information of the initial resistance (R0) and the resistance (analogic signal read by Arduino) of MQ2 (Rs), allows to calculate the ratio between them. With this information we can use the theoretical curves to determine the quantity of each gas (Fig.2).In order to obtain more reliable results by correcting the Rs / R0 value, the humidity and temperature level are read (DHT11). By using figure 4 we can adjust the ratio correctly.

Step 2: DHT11, Temperature and Humidity.

The humidity and temperature information can be obtained using a small precision sensor like DHT11. The information obtained from these readings can be converted into Celsius, Fahrenheit, Kelvin and Rankine.

The relative humidity data together with the temperature data allow to adjust in the case of MQ-2 the values obtained from the readings in order to obtain greater precision and reliability.We can always choose a model with greater accuracy like DHT22.

In this project the information obtained by DHT11 had a double function, on the one hand to correct the values of MQ-2 and on the other hand to serve as information of conditions , since for example some means require controlled temperature.

Step 3: Diagram, Assembly and Alarms.

The assembly of the circuit is simple , unfortunately for an Arduino board like the UNO this type of display uses many ports reducing the possibility of adding more sensors or elements like LED.This is the part where we can become more creative, we can create an alarm if any of the sensors are not placed in the correct position.

  if (isnan(H) || isnan(T)){
    Serial.println("Error DHT");

If all the values are within the parameters, the lcd must display the following information (Fig 2).

if ( T<=25 && COppm <= 1000 && LPGppm <= 300){ 
    lcd.print(" Int Air Quality");
    lcd.print("T&H: OK ");
    lcd.print("GAS: OK");

We can add one or more buttons in order to present other results such as

if (buttonState == HIGH){
    lcd.print("Temp & Humidity");

The piezo speaker is ideal for effectively alerting, with a characteristic sound and easily distinguishable. Using a simple line of tone() code we can choose the frequency and duration.

if ( T >= 25){ 
 tone(Buzzer, 2000, 500);
    lcd.print("Int air Quality");
    lcd.print(" GAS: OK");
else {

We can create multiple personalised alarms, to be more effective it is possible to connect leds in order to also visually alert the user.

This project can be optimised and changed in many ways, and integrated into other systems, keep active and use this work to inspire you since its simplicity represents a starting point.