Build an Air Quality Sensor with a MQ135 Sensor to detect smoke and other harmful gas for Alexa

In this section, we will walk you through creating an air quality sensor using ESP32 or ESP8266. You will then be able to view the air quality via Amazon Alexa and receive a push notification via the Sinric Pro app when the air quality drops below a certain threshold level.

Prerequisites :

  1. ESP32, ESP8266 x 1.
  2. MQ135 x 1.
  3. Jumper Wires.

Sinric Pro MQ135 air quality

Quick introduction to MQ135

The MQ135 is a semiconductor gas sensor that is commonly used in air quality control equipment. It is sensitive to a wide range of gases, including ammonia, sulfide, benzene, and smoke. The sensor has two outputs: a digital output that goes high when the gas concentration exceeds a certain threshold, and an analog output that provides a voltage proportional to the gas concentration.

The MQ135 sensor requires a power supply of 5V and consumes about 150mA of current. The digital output can be connected to a ESP32, ESP8266 or Pico W to measure the gas concentration.

How to calibrate the sensor ? Put your sensor outside where there is enough fresh air (ideally at 20°C & 33% humidity according to the datasheet) and leave it powered on for 12-24 hours to burn it in and stabilize.

Specification sheet: SNS-MQ135

Wiring

Sinric Pro esp8266 PIR wiring

MCU A0 Pin VCC Pin
ESP32 34 (Analog ADC1_CH6) 5V
ESP8266 A0 5V/VIN
Pico W GP26 (ADC0) 5V

Note: on ESP32, ADC2 (GPIO04, GPIO02, GPIO15) is unstable when Wi-Fi is being used.

Let’s verify that motion sensor is wired correctly and working.

Arduino IDE Serial Monitor will show the motion detections like this:

Sinric Pro mq135 test reading

Detecting poor Air Quality

Step 1 : Connect to Sinric Pro

Step 1.1 : Creating a custom device type for Air Quality Sensor.

Sinric Pro does not have a built-in device type for Air Quality Sensor with PPM so we are going to create a custom device type for Water Sensor using Device Template feature to achieve.

  1. PPM Value

  2. Air Quality Is Severe, Very Poor, Poor, Moderate or Good.

Note: You can use the device template import feature mentioned below to skip creating the full template.

Sinric Pro air quality ensor device template

Here we must select the features of our Air Quality Sensor. We want to know whether Air Quality is Severe, Very Poor, Poor, Moderate or Good. So let’s drag a Range, a Mode and Push Notification capability.

Sinric Pro custom device type for capacitive soil moisture sensor

Click on Configure button and setup the two capabilities like below.

Sinric Pro moisture sensor template mode and range settings

Click on Save to save.

Sinric Pro moisture sensor template mode and range settings

Click on Save to save the template.

Now you can see the template we just created.

Import an existing template?

If you are feeling lazy setup all the Modes and Range values, you can use the import feature.

Sinric Pro capacitive soil moisture sensor import template

Paste this Template:

Sinric Pro create device alexa

Sinric Pro create device alexa

Sinric Pro copy device id

Sinric Pro copy device id

Step 2 : Connect to Sinric Pro

Step 2.1 Install Sinric Pro Library

Sinric Pro install SinricPro library

Step 2.2 Install TroykaMQ

TroykaMQ is not available in Arduino Library Manager. So you must download it from https://github.com/amperka/TroykaMQ and copy it over to C:\Users\<your username>\Documents\Arduino\libraries

2.2 Complete Code

Now you should be able to see the flooding status and water level via Alexa, Sinric Pro App

Alexa, What’s the air quality (mode name) in air quality sensor(device name)

Alexa, What’s the ppm (range name) in air quality sensor(device name)

Sinric Pro Alexa capacitive soil moisture sensor

Sinric Pro Alexa capacitive soil moisture sensor portal

Troubleshooting

  1. Google Home or SmartThings are not supproted.

  2. Please refer to our Troubleshooting page for more details.

This document is open source. See a typo? Please create an issue