Ugenz Academy/IoT Tutorial

Gas And Air Quality Sensors

14 min read2,770 words

Reading progress

Keep learning

Gas and Air Quality Sensors

Gas and air-quality sensors are used to detect or measure gases and other pollutants present in the surrounding environment.

They are important in:

  • Gas leakage detection
  • Smoke detection
  • Indoor air-quality monitoring
  • Industrial safety
  • Smart homes
  • Agriculture
  • Environmental monitoring
  • IoT systems
  • Fire and safety systems

A basic system works like this:

Gas / Pollutant ↓ Sensor ↓ Electrical Signal ↓ Arduino / ESP32 ↓ Processing ↓ Display / Alarm / Notification

1. What is a Gas Sensor?

A gas sensor is a device that detects the presence or concentration of a particular gas or group of gases.

For example:

  • LPG
  • Methane
  • Carbon monoxide (CO)
  • Carbon dioxide (CO₂)
  • Alcohol vapors
  • Smoke
  • Volatile organic compounds (VOCs)

A gas sensor can be used simply for detection, or for estimating concentration.


2. What is Air Quality?

Air quality describes how clean or polluted the air is.

Poor air quality can result from pollutants such as:

  • Smoke
  • Carbon monoxide
  • Nitrogen oxides
  • Sulfur dioxide
  • VOCs
  • Fine particulate matter

Different pollutants require different sensing technologies.

Therefore:

There is no single sensor that perfectly measures every aspect of air quality.


3. Gas Detection vs Gas Measurement

These are two different concepts.

Gas detection

Answers:

"Is gas present?"

Example:

Gas detected → YES Gas detected → NO

Gas measurement

Attempts to determine:

"How much gas is present?"

Example:

CO concentration = 25 ppm

Accurate concentration measurement generally requires a properly calibrated sensor and controlled measurement conditions.


4. MQ-Series Gas Sensors

The MQ series is very popular in Arduino and ESP32 projects.

Common examples include:

  • MQ-2
  • MQ-3
  • MQ-4
  • MQ-5
  • MQ-6
  • MQ-7
  • MQ-9
  • MQ-135

These sensors generally use a heated sensing element whose electrical resistance changes when exposed to certain gases.


5. How MQ Sensors Work

A typical MQ sensor contains:

Gas-sensitive material + Heater

Conceptually:

Gas enters ↓ Sensing material reacts ↓ Resistance changes ↓ Electrical output changes ↓ Microcontroller reads signal

The sensor's resistance changes according to the surrounding gas environment.


6. MQ-2

MQ-2 is one of the most common gas sensor modules used in beginner projects.

It is sensitive to gases/vapors such as:

  • LPG
  • Smoke
  • Methane
  • Propane
  • Hydrogen
  • Some other combustible gases

A typical project:

MQ-2 ↓ ESP32 ↓ Gas threshold check ↓ Buzzer ↓ Alarm

7. MQ-3

The MQ-3 is commonly associated with detecting alcohol vapors.

It can be used in educational projects involving:

  • Alcohol vapor detection
  • Breath-related demonstrations
  • Safety experiments

However, an MQ-3 module should not be treated as a certified breathalyzer without proper calibration and controlled measurement.


8. MQ-4

The MQ-4 is commonly used for detecting methane/natural gas-related environments.

Applications can include:

  • Gas leakage demonstrations
  • Industrial monitoring prototypes
  • Gas detection systems

9. MQ-5

MQ-5 is commonly used for detecting combustible gases such as:

  • LPG
  • Natural gas
  • Hydrogen

It is often used in gas leakage detection projects.


10. MQ-6

MQ-6 is particularly associated with LPG and butane/propane-related gas detection.

A typical application:

Gas Leakage ↓ MQ-6 ↓ ESP32 ↓ Alarm

11. MQ-7

The MQ-7 is designed for carbon monoxide (CO) sensing.

CO is a dangerous gas because it is:

  • Colorless
  • Odorless
  • Potentially toxic

A CO detection system can therefore be used for safety monitoring.

However, hobby MQ modules should not replace certified life-safety CO alarms.


12. MQ-9

MQ-9 is commonly used for detecting gases including:

  • Carbon monoxide
  • Methane
  • LPG
  • Other combustible gases

The exact sensitivity depends on operating conditions and sensor characteristics.


13. MQ-135

The MQ-135 is frequently used in hobby projects for general air-quality-related sensing.

It is sensitive to various gases, including certain:

  • Ammonia-related vapors
  • Smoke
  • CO₂-related environments
  • Alcohol vapors
  • Other gases

However, an important point is:

MQ-135 is not a direct, calibrated CO₂ meter.

Its output is affected by multiple gases, temperature, humidity, sensor aging, and other environmental factors.


14. MQ Sensor Comparison

SensorCommon Target/Use
MQ-2Smoke, LPG, methane, combustible gases
MQ-3Alcohol vapors
MQ-4Methane / natural gas
MQ-5LPG / natural gas / hydrogen
MQ-6LPG / butane / propane
MQ-7Carbon monoxide
MQ-9CO and combustible gases
MQ-135General air-quality-related sensing

These are typical applications, not exclusive gas identification capabilities.


15. Analog Output

Many MQ modules provide an analog output.

Conceptually:

Gas concentration/exposure ↓ Sensor resistance changes ↓ Voltage changes ↓ Analog output ↓ ADC ↓ Microcontroller

An ESP32 can read the analog voltage using an ADC-capable GPIO.


16. Digital Output

Many MQ modules also include a comparator circuit that provides a digital output.

For example:

Gas level below threshold → LOW Gas level above threshold → HIGH

The threshold can often be adjusted using a potentiometer on the module.

Therefore, the module may have:

VCC GND AO → Analog Output DO → Digital Output

17. Analog vs Digital MQ Output

Analog

Provides a continuously varying voltage.

Gas exposure ↓ Analog voltage ↓ ADC

Useful when you want to observe changes in sensor response.

Digital

Provides a simple threshold result.

Sensor ↓ Comparator ↓ LOW / HIGH

Useful for simple alarm projects.


18. Important: ESP32 Voltage Safety

This is especially important when using MQ modules with an ESP32.

Many MQ modules are designed around 5 V operation, and their analog/digital outputs may reach voltages that are not suitable for direct connection to an ESP32 GPIO.

ESP32 GPIOs are generally 3.3 V logic.

Therefore:

MQ Module ↓ Check output voltage ↓ If output can exceed ESP32 limit ↓ Use appropriate voltage divider / level shifting ↓ ESP32 GPIO

Never assume that an MQ module's output is automatically safe for an ESP32 just because the sensor is being used in an IoT project.


19. MQ Sensor Heater

MQ sensors contain an internal heater.

The heater is important because it helps the sensing material operate correctly.

Therefore:

MQ Sensor ├── Heater └── Gas-sensitive element

The heater consumes power.

This means MQ sensors can consume significantly more power than many modern low-power digital environmental sensors.


20. Warm-Up Time

MQ sensors generally need a warm-up period.

Immediately after powering the sensor:

Power ON ↓ Heater warms up ↓ Sensor stabilizes ↓ Measurement becomes more useful

A short-term reading immediately after power-on may not be reliable.

For serious measurement applications, the sensor should be conditioned according to its datasheet and calibration procedure.


21. Calibration

Calibration is one of the most important concepts in gas sensing.

Suppose:

Actual condition → Known reference Sensor output → Measured response

We can determine how the sensor behaves under known conditions.

For MQ sensors, the relationship between sensor resistance and gas concentration is not simply:

Voltage = Gas concentration

Instead, the response is influenced by several factors.


22. Factors Affecting MQ Sensors

MQ readings can be affected by:

  • Temperature
  • Humidity
  • Sensor aging
  • Heater voltage
  • Supply voltage
  • Different gases
  • Sensor-to-sensor variation
  • Warm-up state
  • Airflow
  • Contamination

Therefore:

An MQ sensor's raw ADC value should not automatically be interpreted as an accurate ppm value.


23. What is PPM?

PPM = Parts Per Million

It is commonly used to express very small gas concentrations.

For example:

100 ppm

means approximately:

100 parts of gas per 1,000,000 parts of the mixture

But obtaining a reliable ppm measurement requires appropriate calibration and sensor modeling.


24. Gas Sensor System

A simple gas detection system can be designed as:

GAS SENSOR ↓ Analog Signal ↓ ESP32 ↓ Threshold Check ↓ ┌─────┴─────┐ ↓ ↓ Safe Level Gas Alert ↓ Buzzer / LED ↓ Mobile Alert

25. Example: LPG Leakage Detection

Imagine a kitchen gas leakage detector.

LPG Leakage ↓ MQ-6 ↓ ESP32 ↓ Gas level exceeds threshold ↓ Buzzer ON ↓ LED ON ↓ Send notification

The system could display:

------------------------ GAS MONITOR ------------------------ Status: GAS DETECTED! Alarm: ON ------------------------

For real household safety, use a certified gas detector appropriate for the specific gas and installation environment rather than relying solely on a hobby module.


26. Smoke Detection

An MQ-2 can be used in educational smoke-detection projects.

Smoke ↓ MQ-2 ↓ ESP32 ↓ Threshold ↓ Alarm

For actual fire safety, use certified smoke alarms designed and tested for life-safety applications.


27. CO Detection

A CO sensor can be used to monitor carbon monoxide.

CO ↓ CO Sensor ↓ Microcontroller ↓ Alarm

Because CO is dangerous, certified CO alarms should be used for real residential protection.


28. CO₂ Sensors

CO₂ is different from CO.

CO → Carbon Monoxide CO₂ → Carbon Dioxide

They are completely different gases.

A commonly used technology for CO₂ measurement is NDIR.

NDIR = Non-Dispersive Infrared

Examples of NDIR CO₂ sensors include families such as:

  • Sensirion SCD30/SCD4x
  • Senseair sensors
  • Other dedicated CO₂ modules

29. How NDIR CO₂ Sensors Work

CO₂ absorbs infrared radiation at characteristic wavelengths.

An NDIR sensor uses this principle:

Infrared Source ↓ Gas Cell ↓ CO₂ absorbs specific IR wavelengths ↓ Optical Detector ↓ Processing ↓ CO₂ concentration

This is fundamentally different from the heated metal-oxide sensing used in many MQ sensors.


30. VOC Sensors

VOC = Volatile Organic Compounds

VOCs can come from:

  • Paint
  • Solvents
  • Cleaning products
  • Fuels
  • Adhesives
  • Building materials
  • Human activities

Some modern environmental sensors can estimate VOC-related air-quality information.

Examples include:

  • BME680
  • BME688
  • SGP30
  • SGP40

These sensors generally provide a sensor response or estimated air-quality/VOC-related metric rather than identifying every individual VOC molecule.


31. Particulate Matter Sensors

Gas sensors and particulate sensors are different.

Particulate matter (PM) refers to tiny particles suspended in air.

Examples:

  • PM1.0
  • PM2.5
  • PM10

Sensors such as the PMS5003 or similar optical particle sensors can estimate particulate concentration.

Basic operation:

Air ↓ Particles enter sensor ↓ Laser / optical scattering ↓ Photodetector ↓ Particle estimation ↓ PM reading

32. Gas vs Particulate Sensor

Sensor TypeMeasures
MQ sensorGas-related response
NDIR sensorSpecific gas such as CO₂
VOC sensorVOC-related response
PM sensorAirborne particles
BME280Temperature, humidity, pressure
BME680/BME688Environmental parameters + gas resistance

Therefore:

Air Quality │ ├── Gases ├── VOCs ├── CO₂ └── Particulate Matter

Different sensors are needed for different measurements.


33. Air Quality Monitoring System

A more advanced system can combine multiple sensors:

AIR QUALITY SYSTEM │ ┌──────────────┼──────────────┐ ↓ ↓ ↓ CO₂ VOC PM2.5 Sensor Sensor Sensor │ │ │ └──────────────┼──────────────┘ ↓ ESP32 ↓ Wi-Fi / Cloud ↓ Dashboard

The dashboard could display:

----------------------------- AIR QUALITY ----------------------------- CO₂ : 720 ppm VOC : Normal PM2.5 : 18 µg/m³ Status : Good -----------------------------

The exact "good/bad" classification should be based on the appropriate standard and measurement method rather than arbitrary thresholds.


34. Gas Sensors in Smart Homes

A smart home can monitor:

  • LPG leakage
  • Smoke
  • CO
  • CO₂
  • VOCs
  • Particulate matter

Example:

Gas Sensor ↓ ESP32 ↓ Wi-Fi ↓ Mobile App

If a dangerous condition is detected:

Sensor ↓ ESP32 ↓ Alarm ↓ Notification

35. Industrial Applications

Gas sensors are important in industrial environments.

They can be used for:

  • Gas leakage monitoring
  • Worker safety
  • Combustible gas detection
  • Process monitoring
  • Environmental monitoring

Industrial systems may use specialized sensors such as:

  • Electrochemical sensors
  • Catalytic bead sensors
  • Infrared sensors
  • Photoionization detectors
  • Metal-oxide semiconductor sensors

The choice depends on the gas and required accuracy.


36. Electrochemical Gas Sensors

Electrochemical sensors are commonly used for gases such as:

  • CO
  • O₂
  • H₂S
  • SO₂
  • NO₂

Basic concept:

Gas ↓ Electrochemical Cell ↓ Chemical Reaction ↓ Electrical Current ↓ Measurement Circuit

They are often more suitable than hobby MQ sensors when selective gas measurement is required.


37. Infrared Gas Sensors

Infrared techniques can be used to detect gases based on their absorption of specific wavelengths.

For example:

Gas ↓ IR Absorption ↓ Optical Detector ↓ Concentration Estimation

NDIR CO₂ sensors are a common example.


38. Metal-Oxide Semiconductor Sensors

Many MQ sensors use a metal-oxide semiconductor sensing material.

Its electrical resistance changes when exposed to certain gases.

Gas ↓ Metal-Oxide Surface ↓ Resistance Change ↓ Electrical Signal

This technology is relatively inexpensive but can have:

  • Cross-sensitivity
  • Temperature dependence
  • Humidity dependence
  • Long-term drift

39. Important Difference: Detection vs Certified Safety

This is extremely important.

A hobby project:

MQ-2 + ESP32 + Buzzer

is excellent for:

  • Learning
  • Demonstration
  • Prototyping
  • Understanding gas sensing

But it should not automatically be considered a certified safety system.

For real-life protection from:

  • CO
  • LPG
  • Fire
  • Toxic gases

use appropriate certified detectors and safety equipment.


40. Example ESP32 Gas Detection

For an analog gas module, conceptually:

#define GAS_SENSOR 34 #define BUZZER 23 void setup() { Serial.begin(115200); pinMode(BUZZER, OUTPUT); } void loop() { int value = analogRead(GAS_SENSOR); Serial.print("Gas Sensor: "); Serial.println(value); if (value > 2000) { digitalWrite(BUZZER, HIGH); Serial.println("WARNING: Gas level increased!"); } else { digitalWrite(BUZZER, LOW); } delay(500); }

The value 2000 here is only an example threshold for programming practice. It is not a universal gas-safety threshold.


41. Better Gas Monitoring Logic

Instead of immediately triggering an alarm from one reading, a more robust system can use multiple readings:

Read sensor ↓ Filter noise ↓ Compare with calibrated threshold ↓ Confirm condition ↓ Trigger alarm

For example:

Gas level high ↓ Wait / verify ↓ Still high? ↓ YES ↓ Alarm

This can reduce false alarms caused by temporary fluctuations.


42. Common Problems

1. No Warm-Up

MQ sensors require proper warm-up.

2. Treating Raw ADC as PPM

This is one of the most common mistakes.

ADC = 2500

does not automatically mean:

2500 ppm

3. Ignoring Humidity and Temperature

Environmental conditions can significantly affect sensor response.

4. Wrong Power Supply

MQ heaters can consume substantial current.

5. Connecting 5 V Output Directly to ESP32

Check the output voltage before connecting it to a 3.3 V GPIO/ADC.

6. Using Hobby Sensors as Safety Devices

A prototype is not necessarily a certified safety instrument.


43. Complete Gas and Air Quality System

A more advanced IoT system can look like:

AIR ENVIRONMENT │ ┌─────────────┼─────────────┐ ↓ ↓ ↓ MQ Sensor CO₂ Sensor PM Sensor │ │ │ └─────────────┼─────────────┘ ↓ ESP32 ↓ Data Processing ↓ ┌───────┴───────┐ ↓ ↓ Display Wi-Fi ↓ Cloud / App

This is a practical architecture for an IoT air-quality monitoring system.


Key Points to Remember

Gas Sensors

Detect or estimate the presence/concentration of gases.

Important technologies

MQ Series ↓ Metal-Oxide Semiconductor Electrochemical ↓ Chemical reaction → Electrical signal NDIR ↓ Infrared absorption Optical PM ↓ Light scattering → Particle estimation

Common sensors

MQ-2 → Smoke / combustible gases MQ-3 → Alcohol vapors MQ-4 → Methane MQ-5 → LPG / natural gas MQ-6 → LPG-related sensing MQ-7 → CO MQ-135 → General air-quality-related sensing

Modern environmental sensors

BME680 / BME688 → Temperature + Humidity + Pressure + Gas resistance SCD30 / SCD4x → CO₂ SGP30 / SGP40 → VOC-related sensing PMS5003 → Particulate matter

Most important concept

Gas ↓ Sensor ↓ Electrical / Optical Response ↓ Microcontroller ↓ Processing + Calibration ↓ Measurement / Alarm / IoT

Keep learning. Keep building. Keep growing.

© 2026 Ugenz Academy