Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Voltaat Arduino Ultimate Kit
120 min
Share

Arduino Smoke Level Detector using MQ-135 Sensor with Alarm

Smoke may often indicate that there is a fire in your home, so smoke detectors are very important in determining the occurrence of fires. Thanks to Arduino, you can build an accurate system to detect smoke levels.

Project Video

Overview

In this tutorial, We will teach you how to build an accurate system to detect smoke levels using Arduino and the MQ135 gas sensor, so that it displays the smoke level on a crystal display, and when the gas percentage exceeds a certain value, an alarm sounds via a buzzer.

Getting the Items

Arduino Uno R3 (Voltaat Version)
Get Item
Air Quality Sensor (MQ-135)
Get Item
2×16 LCD with I2C Module
Get Item
Passive Buzzer – 5V
Get Item
Half-size Breadboard
Get Item
Jumper Wires - Male to Male (40 Pack)
Get Item

Steps

Wiring it Up

Connect the wires between the MQ-135 and the Arduino and the LCD and the buzzer as shown in the image below.


Connections from the Arduino to the breadboard:

  • Arduino GND pin → Breadboard ground line

  • Arduino 5V pin → Breadboard 5V line


Connection from the LCD with I2C Module:

  • VCC pin → breadboard 5v line

  • GND pin → breadboard GND line

  • SDA pin → Arduino analog pin A4

  • SCL pin → Arduino analog pin A5


Connections from the MQ-135 sensor:

  • MQ-135 sensor VCC pin → Breadboard 5V line

  • MQ-135 sensor GND pin → Breadboard ground line

  • MQ-135 sensor A0 pin → Arduino pin A0



Connections from the Arduino to the passive buzzer:

  • Arduino GND pin → buzzer GND pin (- pin)

  • Arduino pin 3 → buzzer VCC pin (+ pin)

Coding

/*
Voltaat learn (http://learn.voltaat.com)
Link for full tutorial:

Tutorial: Arduino Smoke Level Detector using MQ-135 Sensor with Alarm!

 LiquidCrystal I2C Library: https://learn.voltaat.com/wp-content/uploads/2023/08/LiquidCrystal_I2C-1.1.2.zip

The purpose of this sketch is to detect smoke, display the smoke level on the LCD, and emit an alarm sound when the smoke levels reaches a certain value.


Connections from the Arduino to the breadboard:

• Arduino GND pin → Breadboard ground line

• Arduino 5V pin → Breadboard 5V line


Connection from the LCD with I2C Module:

• VCC pin → breadboard 5v line

• GND pin → breadboard GND line

• SDA pin → Arduino analog pin A4

• SCL pin → Arduino analog pin A5


Connections from the MQ-135 sensor:

• MQ-135 sensor VCC pin → Breadboard 5V line

• MQ-135 sensor GND pin → Breadboard ground line

• MQ-135 sensor A0 pin → Arduino pin A0



Connections from the Arduino to the passive buzzer:

• Arduino GND pin → buzzer GND pin (- pin)

• Arduino pin 3 → buzzer VCC pin (+ pin)


*/

#include "Wire.h"
#include "LiquidCrystal_I2C.h"

// Initialize the LCD with the I2C address
LiquidCrystal_I2C lcd(0x27, 16, 2);  // Change the I2C address if necessary

int buzzer = 3;
int smokeA0 = A0;
// Your threshold value
int sensorThres = 200;

void setup() {
 pinMode(buzzer, OUTPUT);
 pinMode(smokeA0, INPUT);
 Serial.begin(9600);
 lcd.init(); // Initialize the LCD
 lcd.backlight(); // Turn on the LCD backlight
}

void loop() {
 int analogSensor = analogRead(smokeA0);

 Serial.print("Pin A0: ");
 Serial.println(analogSensor);
 lcd.setCursor(0, 0);  // Set the cursor to the first position of the first line
 lcd.print("Smoke Level:");
 lcd.setCursor(12, 0);  // Set the cursor to the first position of the second line
 lcd.print(analogSensor-50);
 
 // Checks if it has reached the threshold value
 if (analogSensor-50 > sensorThres) {
   lcd.setCursor(0, 1);  // Set the cursor to the first position of the third line
   lcd.print("Alert....!!!    ");
   tone(buzzer, 1000, 200);
   
 } else {
   lcd.setCursor(0, 1);  // Set the cursor to the first position of the third line
   lcd.print(".....Normal.....");

   noTone(buzzer);
 }
 
 delay(500);
 lcd.clear();
}

Testing it Out

Once you've uploaded the code to the Arduino board, you will find that the LCD displays the smoke level and the buzzer emits an alarm sound when the smoke levels reach a certain value, as shown in the video below.

Resources

No items found.