📚 Course contents

Projects Hub, build 9 of 81

Air Quality Monitor with Arduino, MQ-135 and LCD

intermediate2 min read

Introduction

Air quality is a critical aspect of our environment that significantly impacts our health and well-being. Monitoring air quality can help us stay informed about the levels of pollutants and make informed decisions to protect ourselves and the environment. In this article, we'll explore how to create a simple yet effective air quality monitoring system using an Arduino and an LCD screen to display real-time air quality data.

Working Principle

The MQ-135 sensor has a tiny heated layer of tin oxide inside. Clean air makes it a poor conductor. Gases such as ammonia, smoke, alcohol vapour, benzene and carbon dioxide let more current through, so the voltage on its output pin goes up. The Arduino reads that voltage as a number from 0 to 1023: the higher the number, the dirtier the air.

The MQ-135 tells you that the air is getting better or worse; it does not give exact ppm values unless it is calibrated, and it cannot measure dust (PM2.5 and PM10). For dust you need a separate dust sensor.

Things We Need

To build this project, you'll need the following components:

  1. Arduino Uno or compatible board.
  2. Air quality sensor module (e.g., the MQ-135 for gas detection).
  3. 16x2 LCD display with an I2C module.
  4. Breadboard and jumper wires.
  5. Power source (USB cable or an external power supply).
  6. Enclosure (optional).

Circuit Diagram

Now, let's set up the circuit as follows:

  • Connect the VCC and GND pins of the air quality sensor to the 5V and GND pins of the Arduino.
  • Connect the analog output pin of the air quality sensor to any analog pin on the Arduino (e.g., A0).
  • Connect the LCD's I2C module: VCC to 5V, GND to GND, SDA to A4 and SCL to A5.

The MQ-135 has a small heater, so let it warm up for a few minutes (the first time, up to a day) before trusting the numbers.

Working of the System with Arduino

  1. The MQ-135 changes its output voltage with the amount of gas in the air.
  2. The Arduino reads it on A0 as a number from 0 to 1023.
  3. It compares the number with two limits and decides: Good, Moderate or Poor.
  4. It shows the number and the word on the LCD, and sends them to the Serial Monitor.
Loading the circuit…Arduino Uno
Press Run to upload the code to the Arduino.

Arduino Code

Install the LiquidCrystal I2C library (by Frank de Brabander) from the Library Manager first. If the LCD stays blank, try the address 0x3F instead of 0x27.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
 
LiquidCrystal_I2C lcd(0x27, 16, 2);
 
const int airQualityPin = A0;
// Limits for the reading (0 to 1023). Note your sensor's number in clean air, then adjust these.
const int MODERATE = 300;
const int POOR = 500;
 
void setup() {
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();
  lcd.print("Warming up...");
  delay(2000);
}
 
void loop() {
  int airQualityValue = analogRead(airQualityPin);
 
  String level = "Good";
  if (airQualityValue >= POOR) {
    level = "Poor";
  } else if (airQualityValue >= MODERATE) {
    level = "Moderate";
  }
 
  Serial.print("Air: ");
  Serial.print(airQualityValue);
  Serial.println(" " + level);
 
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Air value: ");
  lcd.print(airQualityValue);
  lcd.setCursor(0, 1);
  lcd.print("Air is " + level);
 
  delay(1000); // Update every second
}

Conclusion

Creating an air quality monitoring system with an LCD output using Arduino is an accessible and informative DIY project. It allows you to gain insights into the air quality of your surroundings, which is essential for health and environmental awareness. With this project, you can expand your knowledge of electronics, programming, and environmental science while contributing to the well-being of your community.