DEV Community

Cover image for Smoke Detector Alarm Using Arduino and MQ135 Gas Sensor
Krypton | Madhusudan Babar for Madhusudan Live

Posted on • Originally published at madhusudan.live on

Smoke Detector Alarm Using Arduino and MQ135 Gas Sensor

Hello guys, today we will build a smoke detector system, in two different ways with the most simple and easy tutorial.

In our world, safety takes prime importance, there's no room for compromise. If you're a non-smoker concerned about unexpected fires, a student looking for project ideas or simply a hobbyist who values a secure environment.

creating your own smoke detector is a smart and responsible choice, and that too, with two distinctive ways - with or without the help of a microcontroller like Arduino, isn't it amazing?

What is a Smoke Detector Alarm?

Firstly, let's understand what is a smoke detector. A smoke detector is an electronic device that senses the presence of fire and smoke and also other harmful gases in the air. It's a device designed not only to detect the presence of smoke or gas but also to quantify it in parts per million (PPM).

All this is made possible through the gas sensors such as MQ135 gas sensor or MQ2 gas sensor. Imagine having the ability to early detect the smoke, air quality and gas levels in your living space, all at your fingertips with this simple yet powerful system.

Working Video of smoke detector system

How to build your own Smoke Detector?

There are two ways in which we can build the smoke detector or the fire alarm system. one is a simplest one and does not involves any usage of the microcontroller while the other is simple yet feature equipped, where we can see the air quality and display the same on the LCD display, and alert the user with the help of a buzzer, we will implement the smoke detector system with both of these ways as follows:

  1. Using MQ135 Gas Sensor without any microcontroller
  2. Smoke detector using arduino and MQ135 Gas sensor

How to build a Simple Smoke Detector using MQ135 sensor?

Smoke detector or a fire alarm system can be built just using the gas sensors such MQ135 gas sensor or MQ2 gas sensor, without microcontroller. for this project, we will be using MQ135. MQ135 is a powerful sensor and is capable of driving your smoke detector system without any need of a microcontroller, this is a simple yet complete guide to build the minimal smoke detector system.

Required Components:

MQ135 Gas Sensor

Photo of MQ135 gas Sensor showing front Side
MQ135 Sensor Front Side

Photo of MQ135 Sensor showing Back Side
MQ135 Sensor Back Side

MQ135 is a small but powerful sensor, that can detect harmful gases at very high accuracy, also it boasts multiple features, its operation can be carried out with or without any microcontroller and this can provide the outputs in digital as well as analog forms, hence it is a popular choice for similar kind of projects.

MQ135 is an air quality sensor that detects hazardous gases like ammonium, sulfide, and benzene-based gases, hence it is a perfect choice for detecting smoke and other harmful gases. The smoke has the aforementioned elements. The component used to detect smoke is nothing but MOS (metal oxide semiconductor) It consists of a small heater built with some electrochemical that is reactive to the above-mentioned gaseous at room temperature.

Pin Configuration of MQ135

VCC : This pin is connected to the positive supply (+5V), which powers the MQ135 gas sensor.

GND : This pin is connected to the ground pin of MQ135 gas sensor.

DO : This is DOut or Digital Out pin, that gives the output of the sensor in digital form w.r.t to the threshold value set on the MQ135 module, this pin gives the consumable output values directly, thus making the sensor work without additional support for any microcontroller.

AO : This pin is used when using MQ135 as an analog sensor, for now, we are not going to use, this pin provides analog output, that can be varied within the range of 0V to 5V and which totally depends on gas sensitivity. The output signal by the analog pin is proportional to the concentration of gas vapours in the air. This measures the gas in PPM (Parts Per Million)

Buzzer for alarm

Photo of a Buzzer Module
Buzzer Module

A buzzer is a simple electromagnetic device that produces a beeping sound when connected to VCC. Here it is used to alert the user with a beeping sound after the detection of smoke or harmful contents in air.

9v DC Battery

Photo of a 9V DC Battery
9V DC Battery

The battery is an essential component, used to provide supply to our system which is 9 volts with the help of a cap that is easy to connect with our system.

Breadboard and single-strand cables

Photo of a Breadboard
Breadboard

A photo of a ribbon of single-stranded wires
Ribbon of single-stranded wires

A breadboard is a platform that we will use to build our system, the necessary connections are made with single-stranded wires by interconnection of necessary components in the system.

Connections for simple Smoke detector system

  1. Make a connection of the VCC pin of the MQ135 sensor to the Positive Terminal of the battery.
  2. Connect the GND pin of MQ135 to the Negative terminal of the battery.
  3. Connect the analog output pin from the MQ135 sensor i.e. AO to the negative pin of the buzzer.
  4. Now connect the positive pin of the buzzer with the positive terminal of the battery.

Testing the smoke detector system

To test the smoke detector or fire alarm system, follow these steps:

  1. Place the smoke detector in the desired location, where you can see it clearly.
  2. generate a small amount of smoke, such as a matchstick or an incense stick, and hold it close to the smoke detector.
  3. Now look at the smoke detector. The buzzer should start producing a continuous beep sound, indicating the presence of smoke.

Smoke Detector using Arduino and MQ135 Gas Sensor

Now we will jump to the advanced module, in this section we will create another version of our system but with some extra features, such as displaying the concentration of gases in PPM along with safety messages, also lighting up different LEDs based on safety level: red for Hazardous environment and Green for Safe Environment.

Components:

Arduino UNO

Arduino UNO Development board
Arduino UNO Development board

Arduino is a development board and framework for the IC ATmega328P Microcontroller. It is an open-source electronic platform that we are going to use for building this smoke detector system.

Pins of Arduino are as follows:

  • There are a total of 32 pins available for Arduino
  • Out of 32 pins, there are 22 pins that work as I/O pins.
  • Of those pins, 14 pins from D0 to D13 (where D stands for digital )are truly digital IO (input and output) pins. that can be configured according to our application
  • There are 6 Pins from A0 to A5 which are known as analog input pins ( where A stands for analog ). these pins can also be configured as digital IO pins if required
  • The remaining pins supply power to the board i.e. VCC and GND.

Read more on Arduino

16x2 LCD Display

A photo of 16x2 LCD Display placed on white paper
16x2 LCD Display

16x2 LCD (liquid crystal display) display that is used to show messages/data. and is called 16x2 because it has 16 columns and 2 rows. This LCD display can show 32 characters at once.

Pins of LCD are as follows

GND1 This pin refers to the ground pin of the display, which is used to connect with the ground terminal of the power supply or microcontroller

VCC2 This pin refers to the voltage supply pin of the LCD display which is used to connect with the supply pin of the power supply

VEE3 This pin refers to the change in display view, which can be adjusted by using the potentiometer

RS4 This pin refers to toggling among the data register

RW5 This pin toggles our LCD display among read and write modes of operation

EN6 This pin refers to enabling the pin for display, and it must be kept high during all operation

Data7-14 Data pins D0 to D7: These pins used to send data to display for displaying messages and can be used in 4-wire or 8-wire mode

Anode15 +ve for backlight

Cathode16 for backlight

PS: read more about displays

LEDs

Photo of a Red LED and white LED
Multicolour LEDs

LEDs are simple light-emitting diodes with two pins: Anode (+) and Cathode (-). They are used to indicate safe and danger zones based on smoke or gas leakage in the air.

Data cable or Power cable

Type A Data Cable for programming the arduino
Type A Data Cable

A data cable is primarily used to transfer code to our Arduino board. It can also be used to provide power to our system.

Potentiometer

Photo of a Potentiometer
Potentiometer

The potentiometer is mostly used to change the display views by connecting it to pin no. 3 of the LCD display. It is simply a variable resistor that can be adjusted by changing the position of the resistive wire. The potentiometer has a sliding rotating shaft that controls the position of the resistive wire inside, allowing us to adjust the intensity of characters displayed on the screen by rotating the shaft on the potentiometer.

MQ135 Gas/Air Quality Sensor

Photo of MQ135 gas Sensor showing front Side
MQ135 Sensor Front Side

Photo of MQ135 Sensor showing Back Side
MQ135 Sensor Back Side

MQ135 is nothing but a smoke sensor that is used to detect smoke which is nothing but MOS (metal oxide semiconductor) It consists of a small heater built with some electrochemical that is reactive to some gaseous at room temperature

Pins of MQ135

VCC This pin is connected to the positive supply (+5V), which powers our MQ135.

GND This pin refers to the Negative supply or Ground, which connects the MQ135 sensor to the ground

DO This is the output pin of the sensor which gives digital output with respect to the threshold value that can be adjusted on the MQ135 module with the help of a preset, this pin is responsible for measuring and detecting any specific gas thus making the sensor work without additional support for any microcontroller.

AO When using MQ135 as an analog sensor, this pin provides analog output, that can be varied within the range of 0V to 5V and which totally depends on gas sensitivity. The output signal by the analog pin is proportional to the concentration of gas vapours in the air. This measures the gas in PPM (Parts Per Million)

Buzzer alarm

Photo of a Buzzer Module
Buzzer Module

A buzzer is nothing but a simple electromagnetic device that produces a beeping sound when connected to VCC. Here it is used to alert the user with a beeping sound after the detection of smoke 💨 or gas ⛽️

9V Battery

Photo of a 9V DC Battery
9V DC Battery

The battery is an essential component for this smoke detector system, and used to provide supply to our system which is 9 volts with the help of a cap that is easy to connect with our system.

Breadboard and single-strand cables

Photo of a Breadboard
Breadboard

A photo of a ribbon of single-stranded wires
Ribbon of single-stranded wires

A breadboard is a platform on which we will build our system, whereas single-strand wires are used for the interconnection of necessary components in the system

connections for smoke detector system with arduino

circuit diagram of Smoke detector using arduino and mq135 gas sensor
circuit diagram of Smoke detector system

  1. Connect pin 1 (GND) of the display to the GND terminal of the supply
  2. Connect pin 2 (VCC) of the display to the +ve terminal of the supply
  3. Connect pin 3 (VEE) of the display to a variable terminal of the potentiometer (pin 2) which is the middle pin of the potentiometer while the other ( pin 1 and pin 3) of the potentiometer are connected to the +ve and -ve terminals of the supply respectively
  4. Connect pin 4 (RS) of the display to the D7 pin of the Arduino
  5. Connect pin 5 (RW) pin of the display to the GND terminal
  6. Connect pin 6 (EN) of the display to the D6 pin of the Arduino
  7. Connect the data pins of the display (pins 11-14) as follows: connect D4 to pin D5 of the Arduino, D5 to pin D4 of the Arduino, D6 to pin D3 of the Arduino, and D7 to pin D2 of the Arduino.
  8. connect pin 15 of the LCD backlight of the display to the positive terminal of the power supply then connect pin 16 to the negative ( Ground ) terminal of the battery
  9. Connect the positive terminals (Anode) of the red LED to pin 10 of Arduino and the positive terminal of the green LED to pin 12 of Arduino then connect their negative terminals (Cathode) to ground via a 1K resistor
  10. Connect the positive terminal of the buzzer to PIN number D8 of the Arduino, and connect the negative terminal to the ground terminal of the power supply.
  11. Connect the VCC of Arduino to the positive terminal of the power supply, and connect GND to the ground terminal of the supply.
  12. To connect the MQ135 sensor to an Arduino, follow these steps:
  13. Connect the AO (analog output) pin of the MQ135 to pin A0 of the Arduino.
  14. Connect the VCC terminal of the MQ135 to the VCC (power supply) of the Arduino.
  15. Connect the GND terminal of the MQ135 to the GND (ground) of the Arduino.

LCD of smoke detector system showing gas level and alert message
Implementation of system

Arduino code for smoke detector system

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

int red = 10;
int green = 12;
int buzzer = 8;
int MQOut = A0;
// Your threshold value
int sensorThres = 170;

void setup() {
  pinMode(red, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(MQOut, INPUT);
  Serial.begin(9600);
  lcd.begin(16,2);
}

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

  Serial.print("Pin A0: ");
  Serial.println(analogSensor);
  lcd.print("Smoke Level:");
  lcd.print(analogSensor-50);
  // Checks if it has reached the threshold value
  if (analogSensor-50 < sensorThres)
  {
    digitalWrite(red, LOW);
    digitalWrite(green, HIGH);
    lcd.setCursor(0, 2);
    lcd.print("Safe Zone");
    noTone(buzzer);
  }
  else if (analogSensor-50 >= 170 && analogSensor-50 <= 200)
  {
    digitalWrite(red, HIGH);
    lcd.setCursor(0, 2);
    lcd.print("Warning...");
    digitalWrite(green, LOW);
    tone(buzzer, 5000 , 200);
  }

  else
  {
    digitalWrite(red, HIGH);
    lcd.setCursor(0, 2);
    lcd.print("Evacuate...");
    digitalWrite(green, LOW);
    tone(buzzer, 2000 , 550);
  }
  delay(600);
  lcd.clear();
}
Enter fullscreen mode Exit fullscreen mode

Testing the smoke detection alarm system

To test this advanced smoke detector system, follow these steps:

  1. Place the smoke detector in the desired location, where you can see it clearly.
  2. generate some kind of smoke, using a matchstick or an incense stick, and place it close to the smoke detector system.
  3. The buzzer should start producing a continuous beep sound, indicating the presence of smoke.
  4. Now look at the smoke detector. The LCD display will show the Alert Message and the Red LED will glow
  5. Now go to a normal safe environment, the LCD will display the Safe Zone message and the Green LED Light will glow.

Conclusion: Your Safety, Your Creativity

Well, my dear techies, we are heading towards an end of this journey, building a smoke detector system, we hope you were able to learn something new from this article, and we are glad if you were able to follow along and build the smoke detector or fire alarm system to safeguard your loved ones, we're proud of you, if you make it to the end and complete the project successfully, however, if you stuck somewhere and need some help, please use the contact form below to reach out to us.

Happy crafting!

EDI Electronic Data Interchange Basics, Examples, Benefits PDF

Arduino UNO Explained: Features, Shields, IDE: Nano, ESP32
Keywords:
embedded, arduino, electronics, programming, microcontroller

Top comments (0)