MQ-135 Air Quality Detector Using Arduino | Cirkit Designer Simulation Project

MQ-135 Air Quality Detector with Arduino UNO – Cirkit Designer | MakeMindz
Air Quality Arduino UNO Gas Detection Cirkit Designer Beginner Friendly

MQ-135 Air Quality Detector using Arduino UNO

Detect harmful gases in real time with the MQ-135 sensor. Reads analog concentration, converts to voltage, triggers digital threshold alerts, and controls Red/Green LEDs — simulated in Cirkit Designer.

What You'll Build

A smart environmental monitoring system that reads gas concentration from an MQ-135 sensor, converts raw ADC values to voltage, checks a digital threshold, and instantly lights a Red (Danger) or Green (Safe) LED. All serial readings are viewable in the Arduino IDE Serial Monitor. Designed and simulated using Cirkit Designer — no physical hardware needed to get started.

🌿

Difficulty

Beginner

⏱️

Build Time

45–90 Min

📡

Sensor Output

Analog + Digital

🔍

Resolution

0–1023 (10-bit ADC)

About the MQ-135 Gas Sensor

The MQ-135 uses a heated metal oxide sensing element whose resistance changes in the presence of target gases. It detects multiple harmful gases across a wide concentration range, making it ideal for indoor air quality projects.

Detectable Gases

Ammonia (NH₃)
Nitrogen Oxides (NOₓ)
Alcohol Vapors
Benzene
Smoke
Carbon Dioxide (CO₂)

Outputs Explained

📊 Analog Output AOUT → A0

Provides a continuous voltage (0–5V) proportional to gas concentration. Arduino reads this as a 10-bit value (0–1023), then converts to voltage using raw × (5.0 / 1023.0).

⚡ Digital Output DOUT → D2

Snaps LOW when gas concentration exceeds the threshold set by the onboard potentiometer. Reads HIGH when air is safe. Used to trigger the LED alert system instantly.

Preheat requirement: In real hardware, the MQ-135 needs approximately 20–30 seconds of warm-up time after power-on before readings are accurate. The heating element must stabilise the sensing surface temperature. In simulation this is not required.

Components Required

ComponentQtyNotes
Arduino UNO (R3)×1Main controller — runs sensing and alert logic
MQ-135 Gas Sensor Module×1Includes onboard LM393 comparator and potentiometer for DOUT threshold
Red LED (5mm)×1Danger indicator — lights when DOUT is LOW
Green LED (5mm)×1Safe indicator — lights when DOUT is HIGH
220Ω Resistor×2Current-limiting for each LED
Jumper Wires (M-M, M-F)×15+All signal and power connections
Breadboard×1For prototyping LED circuits

How the Code Works

1

Analog Reading — Raw ADC Value

Every 100ms, the Arduino calls analogRead(A0) to sample the MQ-135's analog output. This returns an integer from 0 to 1023 representing the gas concentration level — higher values mean more gas.

2

Voltage Conversion

The raw value is converted to real voltage using the formula volts = raw × (5.0 / 1023.0). This maps the 10-bit ADC range to 0–5V and is printed to the Serial Monitor for human-readable output.

3

Digital Threshold Detection

digitalRead(D2) reads the DOUT pin of the MQ-135 module. The onboard LM393 comparator outputs LOW when gas exceeds the threshold (adjustable via the blue potentiometer on the module), and HIGH when air is safe.

4

LED Alert Logic

If danger == true (DOUT is LOW): Red LED turns ON, Green LED turns OFF. Otherwise: Green LED turns ON, Red LED turns OFF. This gives an instant visual status without needing to check the Serial Monitor.

5

Serial Monitor Output

Every loop prints the raw AOUT value, voltage in volts (3 decimal places), and the safety status string to Serial at 115200 baud. Use Arduino IDE → Tools → Serial Monitor to view live readings.

Example Serial Monitor Output

// Normal air — sensor reading low
AOUT=350 (1.711 V)  DOUT=HIGH (SAFE)
AOUT=362 (1.770 V)  DOUT=HIGH (SAFE)

// Gas detected — threshold exceeded
AOUT=720 (3.520 V)  DOUT=LOW (DANGER)
AOUT=748 (3.657 V)  DOUT=LOW (DANGER)

 


Wiring Diagram

mq135_air_quality.json — Circuit Overview
MQ-135 Air Quality Detector — Wiring Overview ARDUINO UNO 5V → MQ-135 VCC GND → MQ-135 GND A0 ← AOUT (Analog) D2 ← DOUT (Digital) D9 → Red LED D10 → Green LED MQ-135 SENSOR Gas Sensor Module SENSING VCC → Arduino 5V GND → Arduino GND AOUT → Arduino A0 DOUT → Arduino D2 🔴 RED LED DANGER Indicator Anode → 220Ω → D9 Cathode → GND ON when DOUT = LOW OFF when DOUT = HIGH 🟢 GREEN LED SAFE Indicator Anode → 220Ω → D10 Cathode → GND ON when DOUT = HIGH OFF when DOUT = LOW USB / 5V POWER Powers Arduino + MQ-135 heater (~150mA) Allow 30s warm-up for accurate readings LEGEND 5V Power (red) GND (black) AOUT Analog Signal DOUT Digital Signal LED Control Lines

Pin Connection Map

MQ-135 Sensor

VCC→ Arduino 5V
GND→ Arduino GND
AOUT→ Arduino A0
DOUT→ Arduino D2

Red LED (Danger)

Anode (+)→ 220Ω → D9
Cathode (−)→ GND

Green LED (Safe)

Anode (+)→ 220Ω → D10
Cathode (−)→ GND

Step-by-Step Instructions

1

Gather All Components

Collect your Arduino UNO, MQ-135 gas sensor module, red and green LEDs, two 220Ω resistors, a breadboard, and jumper wires. Verify your MQ-135 module has 4 pins (VCC, GND, AOUT, DOUT) and an onboard blue potentiometer.

2

Wire the MQ-135 Sensor to Arduino

  • VCC → Arduino 5V pin
  • GND → Arduino GND pin
  • AOUT → Arduino A0 (analog in)
  • DOUT → Arduino D2 (digital in)
Use male-to-female jumper wires to connect directly from the sensor header to Arduino pins. No level shifting needed — the module operates on 5V logic.
3

Connect the Red LED (Danger)

  • Red LED anode (+, longer leg) → 220Ω resistor → Arduino D9
  • Red LED cathode (−, shorter leg) → Arduino GND

The resistor limits current to ~14mA at 5V, protecting both the LED and the Arduino output pin.

4

Connect the Green LED (Safe)

  • Green LED anode (+) → 220Ω resistor → Arduino D10
  • Green LED cathode (−) → Arduino GND
5

Install Arduino IDE

Download the Arduino IDE from arduino.cc. No additional libraries are required for this project — it uses only built-in Arduino functions (analogRead, digitalRead, Serial).

6

Upload the Code

Copy the sketch from the Code section below. Connect Arduino via USB, select Board → Arduino UNO and your correct Port, then click the Upload arrow.

7

Adjust the DOUT Threshold

Once powered, wait 30 seconds for the sensor to warm up. Open Serial Monitor at 115200 baud. Use a small screwdriver to turn the blue potentiometer on the MQ-135 module until the DOUT switches from SAFE to DANGER at your desired gas level.

🔧
Turn the potentiometer clockwise to raise the threshold (less sensitive), counter-clockwise to lower it (more sensitive). The onboard LED will flicker as you approach the threshold point.
8

Test with a Gas Source

Briefly bring a lighter (unlit) near the sensor to expose it to butane, or breathe directly onto it to see CO₂ detection. Observe the Serial Monitor readings increase and the Red LED activate when the threshold is exceeded.

⚠️
Calibration note: Raw AOUT values and voltage readings are relative. For accurate ppm measurements, the sensor requires calibration against a known reference gas concentration. For educational projects, the threshold-based DOUT alert is sufficient.

Full Source Code

mq135_air_quality.ino
// ─────────────────────────────────────────────────────
// MQ-135 Air Quality Detector — Arduino UNO
// MakeMindz.com | Cirkit Designer Simulation Project
// Detects: NH₃, NOx, Alcohol, Benzene, Smoke, CO₂
// ─────────────────────────────────────────────────────

// ── Pin Definitions ──────────────────────────────────
const int PIN_AOUT  = A0;  // Analog gas concentration output
const int PIN_DOUT  = 2;   // Digital threshold output (active-LOW via LM393)
const int LED_RED   = 9;   // Red LED  → DANGER indicator
const int LED_GREEN = 10;  // Green LED → SAFE indicator

// ── setup() ──────────────────────────────────────────
// Runs once on power-up or reset
void setup() {
  pinMode(PIN_DOUT,  INPUT);   // DOUT uses internal LM393 pull-up
  pinMode(LED_RED,   OUTPUT);
  pinMode(LED_GREEN, OUTPUT);

  // Ensure both LEDs are off at startup
  digitalWrite(LED_RED,   LOW);
  digitalWrite(LED_GREEN, LOW);

  Serial.begin(115200);
  Serial.println("MQ-135 Air Quality Detector — MakeMindz.com");
  Serial.println("Warming up sensor... please wait 30 seconds.");
  Serial.println("─────────────────────────────────────────────");
}

// ── loop() ───────────────────────────────────────────
// Repeats every 100ms — reads sensor, updates LEDs and Serial
void loop() {

  // Step 1: Read raw analog value (0–1023)
  int raw = analogRead(PIN_AOUT);

  // Step 2: Convert to voltage (0.0–5.0V)
  float volts = raw * (5.0f / 1023.0f);

  // Step 3: Read digital threshold output
  //   LOW  = gas concentration ABOVE threshold → DANGER
  //   HIGH = gas concentration BELOW threshold → SAFE
  int  doLevel = digitalRead(PIN_DOUT);
  bool danger  = (doLevel == LOW);

  // Step 4: Update LED indicators
  digitalWrite(LED_RED,   danger ? HIGH : LOW);
  digitalWrite(LED_GREEN, danger ? LOW  : HIGH);

  // Step 5: Print to Serial Monitor
  Serial.print("AOUT=");
  Serial.print(raw);
  Serial.print(" (");
  Serial.print(volts, 3);
  Serial.print(" V)  DOUT=");
  Serial.println(danger ? "LOW (DANGER ⚠️)" : "HIGH (SAFE ✅)");

  delay(100);   // 10 readings per second
}
💡
Serial Monitor: Open via Arduino IDE → Tools → Serial Monitor. Set baud rate to 115200. You'll see live AOUT values, voltage, and SAFE/DANGER status updating 10 times per second.

Simulate Without Hardware

🧪

Test the full project in your browser — no sensor required

Use Cirkit Designer or Wokwi to virtually build and run the circuit. Import the diagram.json above, paste the Arduino code, and run the simulation to observe LED switching and Serial Monitor output in real time.

🔵
Cirkit Designer tip: Search for "MQ-135" in the component library. Drag it onto the canvas, connect the pins as shown in the wiring diagram, paste the code into the code editor, and press Simulate. Adjust the sensor slider to simulate varying gas levels.

Key Features

📊

Real-Time Monitoring

Reads and displays gas concentration 10 times per second via Serial Monitor.

🔢

Analog Detection

Reads full 0–1023 ADC range with voltage conversion for precise concentration tracking.

Digital Threshold Alert

Instant DOUT-based alerting — no floating thresholds or software debounce needed.

💡

LED Safety Indicator

Red/Green visual status — immediately obvious even without a Serial Monitor open.

🖥️

Simulation Friendly

Designed for Cirkit Designer — test all logic before buying a single component.

📖

Beginner Code

Zero external libraries — only built-in Arduino functions used throughout.

Possible Enhancements

🔔
Add a buzzer for sound alerts on DANGER
📺
16×2 LCD to display AQI and voltage value
📶
ESP8266 WiFi for IoT cloud monitoring
📱
Mobile push notifications via Blynk or MQTT
📈
Air Quality Index (AQI) ppm calculation
💾
SD card data logging with timestamps

Things to Know

Preheat time: MQ-135 requires 20–30 seconds warm-up in real hardware for accurate readings. Never read values immediately after power-on.
🎯
Calibration required: Raw analog values are relative. For precise ppm measurements you need to calibrate against a known reference gas concentration using the sensor's datasheet curves.
🖥️
Simulation simplification: In Cirkit Designer and Wokwi, sensor readings are simplified for learning purposes. Real hardware behaviour depends on ambient temperature, humidity, and gas concentration.

Related Projects

© 2026 MakeMindz — Arduino, IoT & Robotics Tutorials

Built with ❤️ for makers, students, and engineers.

Comments

try for free