Detect smoke and air quality using MQ-135 Sensor šŸ­

There are many reasons that may cause air pollution and affect the quality of the air. In many places, it is necessary to monitor air quality, such as in hospitals, and the rate of harmful gas emissions, such as in factories.


In this tutorial we make a high-efficiency alarm system that will notify you when harmful gases are released into the air using the MQ-135 sensor.


Overview


The output of the MQ-135 sensor increases proportionally with the gas concentration. So, we can use this sensor to send an alert to your computer when harmful gases are detected.


The MQ135 gas sensor can detect ammonia, Sulphur dioxide, and gasoline vapor, as well as smoke and other potentially dangerous gases.


Let's find out more together!


Getting the items


For this project you will need the following components you can buy them from our store.

Sale Off
Voltaat Arduino Uno R3 (Voltaat Version)
45 QAR
Sale Off
Voltaat Combustible Gas Sensor (MQ-2)
19 QAR
Sale Off
Voltaat Jumper Wires - Male to Female (40 Pack)
10 QAR

Wiring it up


To set up the MQ-135 sensor in the correct way, follow the instructions below. The image demonstrates how to connect the wires between the MQ-135 sensor and the Arduino. Once the MQ-135 sensor and the Arduino are connected to each other, connect the Arduino to your computer using the USB cable.


Connections from the MQ135 sensor:

ā€¢ VCC pinā†’ Arduino 5V pin

ā€¢ GND pinā†’ Arduino GND pin

ā€¢ A0 pinā†’ Arduino pin A0


Coding


The function of this sketch is to obtain the reading from the MQ135 sensor using the Arduino. The sensor reading value expresses the purity of the air and the concentration of various harmful gases in it. Then the Arduino compares that value with the clean air value specified in the code, which is 200. If the sensor reading exceeds 200, an alert will be printed on your computer.


You can change this value slightly based on the quality of the air around you so that the code works well for you. If the gas detected message is printed when the circuit is initially connected, you have to increase the value.


This code is basic and straightforward, relying just on reading the value from the sensor, thus no libraries are required.


/*
Voltaat learn (https://www.voltaat.com/pages/voltaat-learn)
Link for full tutorial: https://bit.ly/3st6zyD

Tutorial: Detect smoke and air quality using MQ-135 Sensor

The function of this sketch is to Detect smoke and air quality using MQ-135 Sensor and Arduino

Connections from the MQ135 sensor:
ā€¢ VCC pinā†’ Arduino 5V pin
ā€¢ GND pinā†’ Arduino GND pin
ā€¢ A0 pinā†’ Arduino pin A0
*/



// define MQ135 variable with A0 value that represent the input analog pin in the arduino
int MQ135 = A0;

// define standardAir variable with 200 value
int standardAir =200;


// Commands inside void setup run once
void setup()
{
// MQ135 is defined as an input
pinMode(MQ135,INPUT);

// Start the serial monitor at 9600 baud rate (9600 bits per second)
Serial.begin(9600);

}

// Commands inside void loop run forever
void loop()
{
// Read the value of analog input from MQ135 and assign it in the variable sensorRead
int sensorRead =analogRead(MQ135);

// print "Sensor Reading: " to the serial monitor at the same line
Serial.print("Sensor Reading: ");

// print The sensorRead value to the serial monitor at the same line
Serial.print(sensorRead);

// compare the sensor reading value with the standard fresh air value that we set in the code
if(sensorRead > standardAir)
{
// print " ,Gas is detected" to the serial monitor at new line
Serial.println(" ,Gas is detected");
}
else
{

// print " ,No gas detected" to the serial monitor at new line
Serial.println(" ,No gas detected");
}


}

Testing it out




Now you must have correctly wired the MQ-135 sensor to the Arduino as we explained in the wiring section, as well as uploaded the code to your Arduino board.


You may now access the serial monitor on your Arduino IDE by clicking on the magnifying glass icon at the top right corner.



The serial monitor is great tool that can facilitate the communication between the computer and the Arduino. It can allow us to sending and receive different commands, as well as view information directly from the Arduino.


When you test the sensor with a lighter, your computer will print an alert message indicating that harmful gases have been released. The sensor reacts to both the gases released during the ignition process and also the gas created by the lighter without ignition.


As shown in the image below, the serial monitor now displays the sensor reading value and gas detection status. The value is updated and printed every second due to the delay we added in our code.


You should also ensure that you have selected the correct baud rate (9600) as specified in the code.


Resources 


Arduino Code

Fritzing Wiring file

Related Tutorials


In your daily life, you deal with many devices that have an LCD display. These LCDs help the user to interact with different devices and use them more easily.


A "buzzer" is an electrical device that makes an alarm sound. It is usually used to indicate when someone has pressed a button or to give a warning sound. Buzzers come in different shapes and sizes.


A soil moisture sensor is a device that measures the amount of water in the soil. The sensor consists of two metal probes that can be inserted into the soil to measure the moisture levels.