ESP32 with MQ135: Complete Beginner-Friendly Guide for Air Quality Monitoring

On: November 29, 2025
ESP32 with MQ135

Learn ESP32 with MQ135 gas sensor troubleshooting, calibration, and MQTT integration. Beginner-friendly guide for stable readings and IoT projects.

If you’ve ever thought about measuring indoor air quality using a low-cost sensor and a powerful IoT board, using an ESP32 with MQ135 is one of the smartest ways to begin. The ESP32 gives you WiFi, Bluetooth, fast processing, and reliable ADC performance. The MQ135 gas sensor detects CO2, NH3, alcohol, benzene, smoke, and several harmful gases commonly found indoors. When you combine the two, you get a clean, accurate, IoT-ready air-quality monitoring system that anyone can build.

What the ESP32 Really Is

The ESP32 is a microcontroller designed with WiFi and Bluetooth as its core strengths. It is powerful enough to run complex IoT applications, yet simple enough for beginners. Think of it as a tiny wireless computer that can read sensors, post data online, control devices, run multiple tasks, and help you build a full IoT product.

It supports analog inputs, digital inputs, PWM, SPI, I2C, UART, Bluetooth Classic, BLE, and a solid WiFi stack. This makes it a perfect partner for the MQ135 gas sensor.

ESP32 Explained in Simple Terms

The ESP32 stands out because it is fast, affordable, and extremely flexible. The dual-core processor handles tasks smoothly, and its ADC pins make reading analog sensors effortless. You can build projects like weather stations, smart agriculture tools, IoT dashboards, and air-quality systems with very little hardware.

When people talk about esp32 instructions, they generally refer to how easy it is to write code, upload sketches, and use built-in wireless functions. The board is truly made for beginners and advanced developers alike.

ESP32 WROVER Specs in a Practical Way

The ESP32 WROVER variant includes extra RAM, which is helpful when you want smoother performance or heavy data processing. It offers PSRAM, more stable wireless performance, and enough power for complex projects. When paired with the mq135 gas sensor with esp32, the WROVER gives very stable ADC readings, making it perfect for accurate air quality tracking.

Popular ESP32 Uses in Projects

The ESP32 shines in smart home systems, robotics, IoT dashboards, Bluetooth devices, environmental monitoring, and automation. Its built-in WiFi helps you push sensor data to a cloud server or MQTT dashboard. And because Bluetooth is included, you can also create wireless control apps even without WiFi.

Beginners often learn through esp32 examples like LED blinking, sensor reading, MQTT publishing, and Bluetooth communication. These examples are the foundation for advanced systems like air-quality monitors, which is exactly what you’ll build with the MQ135.

ESP32 vs ESP32-S2 in Real Life

Both ESP32 and ESP32-S2 are solid boards, but the original ESP32 is usually the better choice when using analog sensors. The ESP32 includes both WiFi and Bluetooth, and its ADC is more mature. On the other hand, the ESP32-S2 removes Bluetooth and focuses more on USB features. For reading a sensor like MQ135, the regular ESP32 is simply the better option.

Understanding the MQ135 Gas Sensor

The MQ135 is designed for detecting harmful gases in indoor environments. It outputs an analog voltage that changes when the concentration of gases increases. You can use the MQ135 to detect CO2, NH3, alcohol vapors, benzene, and smoke.

This is why the mq135 sensor with esp32 combination is ideal for home safety, office ventilation monitoring, smart agriculture, and IoT air-monitoring systems.

Why MQ135 Works So Well with ESP32

Connecting the MQ135 to the ESP32 is incredibly easy because both operate comfortably at 3.3V. The MQ135 outputs analog data, and the ESP32 reads that data using its ADC pins. Together, they form a stable, reliable system for tracking air pollution.

This makes mq135 interfacing with esp32 perfect for beginners who want a simple, functional, and IoT-ready air-quality monitor.

MQ135 Connection with ESP32 Made Simple

The wiring between the two devices is straightforward and beginner-friendly. MQ135 typically has three pins that matter: VCC, GND, and AOUT.

For the wiring:

  • MQ135 VCC connects to ESP32 3.3V
  • MQ135 GND connects to ESP32 GND
  • MQ135 AOUT connects to any ADC pin on ESP32, often GPIO 34

This is the standard mq135 connection with esp32 used in most IoT projects.

How to Connect MQ135 to ESP32 in the Easiest Way

The actual wiring is simple. Use only 3.3V to power the sensor. Many MQ135 breakout boards allow both 3.3V and 5V, but powering with 3.3V avoids voltage mismatch.

After powering the sensor, connect the analog output to one of the ESP32’s ADC pins. Once this is done, your mq esp32 setup is ready to start reading air-quality data.

How ESP32 and MQ135 Work Together

When you connect the esp32 and mq135, the sensor continuously measures gas concentration levels. The ESP32 reads those values as analog signals and converts them to meaningful readings. These readings can be displayed on the serial monitor, a mobile app, a web dashboard, or even pushed through MQTT.

When harmful gases increase, the voltage output goes up. The ESP32 then picks this up and helps you track the pollution level.

Calibration Basics for ESP32 MQ135 Sensor

The MQ135 needs a short warm-up period during which its internal heater stabilizes. After a minute or two, you can take the first reading and use it as the baseline. This value represents clean air. Future readings can then be compared to this baseline to determine if air quality has worsened.

Good calibration helps your esp32 mq135 sensor give more meaningful results for home or office environments.

ESP32 MQ135 Code for Beginners

Below is clean, beginner-friendly esp32 mq135 code you can use right away.
This covers every phrase like mq135 esp32 code, mq135 with esp32 code, and mq-135 esp32 naturally.

#define MQ135_PIN 34

int baselineValue = 0;
bool baselineSet = false;

void setup() {
  Serial.begin(115200);
}

void loop() {
  int value = analogRead(MQ135_PIN);

  if (!baselineSet) {
    baselineValue = value;
    baselineSet = true;
    Serial.println("Baseline set for MQ135");
  }

  int quality = value - baselineValue;

  Serial.print("Raw Value: ");
  Serial.print(value);
  Serial.print(" | Air Quality: ");
 .println(quality);

  delay(1000);
}

This sketch gives clear, readable air-quality values that update every second.

Understanding the ESP32 MQ135 Code in Plain Language

The code simply reads the analog value from the MQ135, stores the first reading as the baseline in clean air, and then subtracts the baseline from future readings. Higher values mean more pollution.

This is the basic logic behind any esp32 to mq135 project, and it is more than enough for a beginner to create an indoor air-quality dashboard.

Using an MQTT Broker with ESP32

If you want to make your project cloud-ready, the ESP32 easily connects to any MQTT broker. You can publish the air-quality reading to topics like:

  • home/livingroom/air
  • home/office/airquality

This kind of wireless integration turns your setup into a full IoT device. Many beginners build their first MQTT project using an esp32 broker mqtt setup.

Using ESP32 Bluetooth for Wireless Monitoring

Bluetooth support on ESP32 is excellent. You can send your air-quality data to a smartphone app using BLE characteristics. This is a great way to go wireless when you do not want WiFi. The standard esp32 bluetooth example for sending sensor values is perfect for building a local air monitor.

LED Indicator System Using FastLED

If you want a visual alert system, you can connect an LED strip and use an esp32 FastLED example to display air-quality levels as colors.

For example:

  • Green for good air
  • Yellow for moderate air
  • Red for harmful gas levels

This makes your esp32 con mq135 project more interactive and user-friendly.

Building a Complete ESP32 with MQ135 Air Quality System

You can enhance the setup with:

  • WiFi dashboards
  • OLED displays
  • Mobile app integration
  • MQTT cloud dashboards
  • Bluetooth real-time notifications
  • LED color alerts
  • Data logging

The combination of esp32 and mq135 is flexible, scalable, and perfect for personal IoT learning or home use.

ESP32 is becoming one of the most popular microcontrollers for IoT because it offers Wi-Fi, Bluetooth, and great performance at a low cost. When creating environment-monitoring or smart-home projects, many beginners and hobbyists pair the ESP32 with a DHT22 sensor for accurate temperature and humidity readings. If you want a clear, step-by-step explanation of the wiring and code, this beginner-friendly guide on ESP32 with DHT22 is very helpful . It walks you through setup, troubleshooting, and real project examples in a simple way.

ESP32 with MQ135 Troubleshooting Guide

This troubleshooting guide is designed for beginners and intermediate developers working with ESP32 with MQ135. Every question covers real-world issues like wiring problems, unstable readings, ADC noise, code errors, and calibration mistakes.

Why is my MQ135 not giving stable readings on ESP32?

Unstable readings usually happen because the MQ135 needs a warm-up period. The internal heater takes time to stabilize before it can give meaningful data. Give the sensor at least one to two minutes before taking baseline readings. If the values still jump around, smooth them using an averaging method in the esp32 mq135 code to reduce noise from the analog pin.

Why does my ESP32 reboot when I connect the MQ135?

Reboots often occur due to incorrect wiring. Many MQ135 breakout boards allow 5V input, but the ESP32 cannot tolerate 5V on its ADC pins. Always power the sensor using 3.3V. If you connect 5V accidentally, the analog output can exceed ESP32 limits, causing reboots or brownouts. A clean mq135 connection with esp32 must always use 3.3V.

Why am I getting very high values from MQ135 on ESP32?

When the values are too high, the baseline may not be set properly. The MQ135 compares gas concentration with its clean-air baseline. Let the sensor run in clean air for two to three minutes and record the first stable analog reading. Use this value as your reference in your mq135 esp32 code.

Why is MQ135 giving zero or very low values on ESP32?

Low readings indicate either a wiring issue or a sensor that has not warmed up. Check the analog output wire. Ensure it is connected to an actual ADC pin like GPIO 34 or 35. A zero reading usually means the signal is not reaching the microcontroller, so recheck your mq135 interfacing with esp32.

Why does my ESP32 ADC show noise when reading MQ135?

The ESP32 ADC can show slight jitter because of internal noise. You can reduce this by averaging multiple samples and filtering the data in code. Adding a 10k resistor between AOUT and GND helps stabilize the analog output. Many beginners face this issue in mq135 sensor with esp32 setups.

Why is my MQ135 heating up? Is it normal?

Yes, it is normal. MQ series gas sensors have built-in heaters that warm up during operation. This helps detect gases with higher accuracy. The sensor will feel hot, but it should never smoke or emit burning smell. Heating is part of how the mq135 gas sensor with esp32 works.

Why is MQ135 always showing “bad air quality” even inside my room?

If the sensor always shows high pollution even indoors, it means the baseline is wrong. The MQ135 must be calibrated in clean air, preferably outside or near a window. Warm it up, note the reference value, and adjust your esp32 mq135 sensor reading logic accordingly.

Why is WiFi disconnecting when I read MQ135 on ESP32?

WiFi sometimes drops when ADC tasks consume too much time. To fix this, add small delays in code or read the analog value less frequently. This issue appears in some esp32 examples where ADC sampling is too aggressive.

Why is my Bluetooth app not receiving MQ135 data from ESP32?

Bluetooth requires correct service and characteristic setup. If the app is not receiving data, check that the UUIDs match the mobile app. Many beginners use the default esp32 bluetooth example but forget to update UUIDs for their custom sensor project.

Why can’t I publish MQ135 readings to MQTT broker using ESP32?

The most common issue is incorrect MQTT credentials or WiFi failure. Check your broker username, password, and topic name. Test publishing a simple message first, then integrate the sensor reading. A stable esp32 broker mqtt setup ensures smooth data upload.

Why does ESP32 ADC saturate when measuring MQ135 output?

ADC saturation happens when the output voltage approaches the upper limit. If the MQ135 is powered at 5V, the analog output may exceed 3.3V. Always use 3.3V power for safe mq esp32 interfacing.

Why does my MQ135 show different values every time I restart ESP32?

The baseline resets when you restart the board. If you want consistent calibration, save the baseline value in EEPROM or SPIFFS. This is a common problem in mq135 with esp32 code projects.

Why is my MQ135 responding very slowly on ESP32?

The MQ135 responds slowly when humidity is high. For faster response, keep the sensor dry and stable. Use smoothing in your code to speed up response without losing accuracy.

Why is my ESP32 reading negative air-quality values?

Negative values mean your baseline is too high. Lower the baseline by recalibrating in clean air. This directly affects your esp32 to mq135 calculation.

Why does MQ135 smell burnt during first use?

A light warm smell is normal during the first minute because of the heater element. A burning smell or smoke indicates incorrect voltage. If powering with 5V, switch to 3.3V for safe mq-135 esp32 operation.

Why is the serial monitor printing garbage characters?

Garbage output usually means incorrect baud rate. Set both serial monitor and your esp32 mq135 code to 115200 baud to fix it immediately.

Why does ESP32 show brownout detector triggered when MQ135 is connected?

This means your power supply cannot handle the sensor heater current. Use a stable 5V to 3.3V regulator or a high-quality USB power source. Brownouts are very common in mq135 and esp32 setups that use cheap cables.

Why is my OLED display freezing when MQ135 is connected?

The MQ135 heater consumes power, and low-quality power sources drop voltage. When voltage drops, the OLED resets or freezes. Use a stronger power supply and keep I2C wiring short. This issue often appears in esp32 examples using displays.

Why is FastLED not working correctly with MQ135 on ESP32?

FastLED uses strict timing. If you read the sensor too frequently or block the loop, LED updates lag. Use non-blocking code. Many beginners face this when mixing esp32 fastled example with analog sensor code.

Why is my MQ135 behaving differently in winter and summer?

Temperature and humidity affect gas sensors. Higher humidity increases output. Lower temperature slows response. Adjust your reference values seasonally for more stable mq-135 with esp32 performance.

Why does MQ135 give different readings at different USB ports?

USB ports supply different currents. If the sensor heater receives less current, readings change. Using a dedicated 5V adapter with a proper 3.3V regulator stabilizes your mq135 con esp32 setup.

Why is ESP32 not detecting my MQ135 at all?

If the reading is constant, the analog pin may not support ADC. ESP32 has specific ADC pins. Use GPIO 34, 35, 36, or 39. This solves most detection issues in mq-135 esp32 setups.

Why is the MQ135 sensor noisy after long use?

As the sensor ages, the heater gets weaker and readings fluctuate. Clean the sensor head using dry air and recalibrate. Gas sensors naturally drift over time.

Why is ESP32 not booting when MQ135 is connected to 3.3V and GND?

A short circuit or reversed polarity can cause this. Always check the orientation of the connector. Miswiring is the biggest cause of failed mq135 interfacing with esp32.

Why does MQ135 respond differently from one board to another?

Every MQ135 module has slight hardware variation. The sensitivity pot on the board must be adjusted. Tune it using fresh air and check the mq135 esp32 code output while turning the potentiometer slowly.

Why is my MQ135 showing full values when no gas is present?

This means the sensor is saturated due to high humidity or alcohol vapors in the room. Recalibrate in a dry room. This affects many mq-136 esp32 and MQ series sensors.

Why can’t I log MQ135 data on the internet using ESP32?

If your dashboard is not receiving data, check WiFi strength, broker settings, and JSON formatting. Try sending sample data first. Once the connection works, add your esp32 mq135 sensor readings.

Final Thoughts

Using an ESP32 with MQ135 is one of the most beginner-friendly ways to get started with IoT and air-quality monitoring. You learned how the ESP32 works, how the MQ135 detects gases, how to wire them, how to write the code, how to use MQTT or Bluetooth, and how to troubleshoot common issues.

FAQ : ESP32 with MQ135 air-quality monitoring

What is the best way to wire the MQ135 to an ESP32 for reliable readings?

Always use the ESP32 3.3V pin to power the MQ135. Connect MQ135 VCC → 3.3V, GND → GND, and AOUT → ADC pin such as GPIO34, GPIO35, GPIO36, or GPIO39. Keep wires short and avoid 5V accidentally touching ADC pins. This ensures stable MQ135 with ESP32 readings.

Why are my MQ135 readings unstable after connecting to the ESP32?

The MQ135 requires a few minutes of warm-up because its heater needs stabilization. Readings will jump if you check immediately. Use averaging, smoothing filters, or a 10k resistor + capacitor to reduce noise in your ESP32 MQ135 setup.

How do I calibrate MQ135 when using it with ESP32?

Place the MQ135 outdoors in clean air for 5–10 minutes. Record the stable analog output and store it as baseline. Subtract this baseline from new readings. Save this value in EEPROM or SPIFFS so your MQ135 ESP32 readings remain consistent after reboot.

Which ADC pins on ESP32 are safe to use for MQ135 analog output?

Use only true ADC pins: GPIO32, GPIO33, GPIO34, GPIO35, GPIO36, or GPIO39. The best are GPIO34–39 because they are input-only and clean for reading analog sensors like MQ135 sensor.

Why does my ESP32 reboot when MQ135 is connected?

This happens due to power brownouts. MQ135 heater consumes current; if your USB power is weak, ESP32 resets. Use a good 5V adapter, stable USB cable, and ensure you never feed 5V into ESP32 ADC pins.

How do I reduce noise and spikes in the MQ135 readings on ESP32?

Use a moving average filter, sample multiple readings, and add a small capacitor (100nF) between the analog pin and GND. These improvements dramatically reduce noise in ESP32 MQ135 readings.

Can I use MQ135 with ESP32 and publish data to an MQTT broker?

Yes. Connect ESP32 to WiFi → use MQTT client libraries → publish readings to topics. Start with plain text payloads before integrating advanced ESP32 MQTT logic.

Why does the MQ135 show consistently high values even in clean rooms?

A wrong baseline, chemical cleaners, perfumes, humidity, or nearby kitchen airflow can cause high readings. Recalibrate outdoors and check for environmental factors affecting your MQ135 ESP32 measurement.

How do I keep calibration persistent across ESP32 restarts?

Store the baseline in EEPROM, Preferences, or SPIFFS. On boot, read this stored value and use it directly so the MQ135 remains calibrated even after power loss.

Is it normal for MQ135 readings to change with humidity and temperature?

Yes. The MQ135’s internal material is sensitive to both humidity and temperature. Use DHT11/DHT22/AM2302 or similar to apply correction formulas for more accurate ESP32 air-quality monitoring.

How do I create LED or FastLED alerts based on MQ135 readings?

Convert readings into levels (good → green, moderate → yellow, bad → red). Use RGB LED or WS2812 strips with FastLED. Keep LED code non-blocking so it never interrupts WiFi or ADC sampling.

When should I replace the MQ135 sensor?

If readings are extremely noisy, slow, or the baseline keeps drifting despite recalibration and stable power, the sensor is aging. Replace it if your project needs accurate long-term ESP32 gas monitoring.

What to check if MQ135 readings remain the same and never change?

Check AOUT wiring → ensure ADC pin is correct → verify connections → test with another board → replace jumper wires. Most issues occur due to wrong ADC pin mapping in MQ135 ESP32 projects.

How can I publish MQ135 readings to a cloud dashboard securely?

Use HTTPS, TLS MQTT, or a secure IoT cloud platform that generates device tokens. Never leave MQTT open to the public because it exposes your ESP32 IoT data to attackers.

Leave a Comment

Exit mobile version