MQ135 is a Gas sensor. It works on analogue and digital pins with Arduino boards. It gives analogue value in PPM of Air Quality. But, when we use a digital pin, it gives on signal at a particular value of analogue. This can be adjusted via potentiometer. So, you can also detect a particular gas without using any microcontroller. Just seeing a green LED, you can know it.

Nowadays, we see different gasses being emitted in atmospheres from home appliances like air conditioner and industrial chimneys. Monitoring of these gasses is very important as a safety point of view.

Here, for this project I will use Wemos D1 Board which is a ESP8266 based IoT board.

Components Used:(Click to Buy)

What is MQ135 Gas Sensor?

The MQ-135 gas sensor module consists of a steel exoskeleton under which a sensing element is housed. This sensing element is subjected to the current through connecting leads. So, this current is known as the heating current through it, the gases coming close to the sensing element get ionized and are absorbed by the sensing element. This changes the resistance of the sensing element which alters the value of the current going out of it. This resistance value shows in analogue reading.
It works on the 5V pin of Arduino or ESP8266 boards. It is suitable for detecting NH3, NOx, alcohol, Benzene, smoke, CO2, etc.

Connect ESP8266 with ST7789 SPI TFT

This display works with 3.3V power and ST7789 chip works with 4 wire SPI interface. This display comes with 7 pins. But, we do not connect anything with the rightmost pin. Because this is the backlight on /off pin. To know how to connect ST7789 SPI TFT LCD, follow this post.

ST7789 SPI TFT 240×240 without CS Pin Interfacing ESP8266

MQ135 Gas Sensor with ESP8266 and ST7789 SPI Display

So, here I have connected 5V of ESP8266 with VCC of MQ135. I will not use Digital Pin.

Code Explain

Firstly, in the void setup area, I have initialized display with colour and static texts like PPM, Air quality.
Then, in the void loop area, we are displaying sensor value in every 5 seconds which is being read on line no 34.

Arduino Sketch for MQ135 Gas Sensor

/*
MQ135 with ST7789 IPS SPI 240X240 display without CS pin.
by somtips.com
*/
#include <Arduino.h>
#include <SPI.h>
#include <Adafruit_GFX.h>    // Core graphics library by Adafruit
#include <Arduino_ST7789.h> // Hardware-specific library for ST7789
#define TFT_DC    D3
#define TFT_RST   D2
#define TFT_MOSI  D7
#define TFT_SCLK  D5
Arduino_ST7789 tft = Arduino_ST7789(TFT_DC, TFT_RST);
void setup() {

  tft.init(240, 240);   // initialize a ST7789 chip, 240x240 pixels
  delay(500);
  tft.fillScreen(RED);
  tft.setCursor(10, 0);
  tft.setTextColor(YELLOW);
  tft.setTextSize(3);
  tft.println("Air Quality");
  tft.setCursor(80, 200);
  tft.setTextColor(WHITE);
  tft.setTextSize(4);
  tft.println("PPM");
  delay(300);
}
void loop() {
  tft.setCursor(60, 90);
  tft.fillRect(0,30,240,160,BLUE);
  tft.setTextColor(WHITE);
  tft.setTextSize(7);
  int sensorValue = analogRead(A0);
  tft.println(sensorValue);
  delay(5000);
}

Output

MQ135 Gas Sensor with ESP8266 and ST7789 SPI Display

Finally, here you can see Air quality is showing in PPM on the TFT display.

httpv://youtu.be/lOMsfIxmg9E

But, if you do not have TFT display, you can also do this using 1602/2004 LCD Display. Follow this post.

MQ135 Gas Sensor with ESP8266 and LCD Display with I2C

Comment Box