Situatie
Build your own Arduino-based Air Quality Monitor using sensors like the MQ-135, MQ-7, and DHT11/DHT22. This guide explains how the sensors work, how to wire them, and includes a fully commented Arduino code example.
Components Needed
| Component | Qty | Description |
|---|---|---|
| Arduino Uno / Nano / Mega | 1 | Main microcontroller |
| MQ-135 Gas Sensor | 1 | Detects VOCs, NH₃, CO₂, smoke, pollution |
| DHT11 or DHT22 | 1 | Temperature & Humidity |
| MQ-7 (optional) | 1 | Carbon Monoxide sensor |
| 0.96″ OLED (optional) | 1 | Displays readings |
| Breadboard & Jumper Wires | – | Wiring |
| USB Cable | 1 | Power + programming |
How the Sensors Work
MQ-135 (Air Quality Sensor)
Detects harmful gases such as CO₂, NH₃, NOx, benzene, and VOCs. The analog output value increases when the air becomes more polluted. Requires a short preheat time for accuracy.
MQ-7 (Carbon Monoxide)
Detects CO gas. Optional component for advanced monitoring.
DHT11 / DHT22
Reads temperature and humidity. These values help interpret gas sensor readings more accurately.
MQ-135 Wiring
MQ135 → Arduino VCC → 5V GND → GND A0 → A0
DHT11 / DHT22
DHT Sensor → Arduino VCC → 5V GND → GND DATA → D2
OLED (I2C)
OLED → Arduino VCC → 5V GND → GND SDA → A4 SCL → A5
Arduino Code (Copy & Paste)
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22 // change to DHT11 if needed
DHT dht(DHTPIN, DHTTYPE);
int mq135Pin = A0;
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
// --- Read MQ135 Sensor ---
int mqValue = analogRead(mq135Pin);
float airQuality = map(mqValue, 0, 1023, 0, 500);
// 0 = clean air, 500 = very polluted
// --- Read Temperature & Humidity ---
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// --- Output Data ---
Serial.println("----------- AIR QUALITY MONITOR -----------");
Serial.print("MQ135 Raw Value: ");
Serial.println(mqValue);
Serial.print("Air Quality Index (approx): ");
Serial.print(airQuality);
Serial.println(" / 500");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" *C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
Serial.println("-------------------------------------------\\n");
delay(1000);
}
Understanding the Readings
| MQ135 Reading | Air Quality | Description |
|---|---|---|
| 0–80 | Excellent | Very clean air |
| 80–150 | Good | Normal indoor air |
| 150–250 | Moderate | Needs ventilation |
| 250–350 | Poor | Polluted environment |
| 350–500+ | Hazardous | High VOCs or smoke detected |
Troubleshooting
- Sensor always reads high: MQ-135 needs 1–5 minutes warm-up time.
- No DHT readings: Check DATA pin and DHT type in code.
- Unstable values: Add a 100nF decoupling capacitor to MQ sensor.
- OLED not showing: Wrong I2C address — run an I2C scanner.
Leave A Comment?