Smoke Detector Using MQ-2 Gas Sensor and Bharat Pi

This project uses a smoke detection motion sensor and Bharat Pi to detect the presence of smoke or combustible gases in the environment.

·      The primary purpose of the smoke detector is to provide an early warning system to alert occupants of a building or home about a potential fire or gas leak.


Hardware components

Below is the given list of all the hardware components that are required for this project:

·      Bharat Pi Board (You can buy Bharat Pi board from on Amazon)

·      MQ-2 Sensor

·      Jumper Wire

·      LED  

Software apps and online services

We are going to use Arduino IDE for programming the Bharat Pi. The Bharat Pi can be connected using a USB Type-C connector. Serial drivers are required to be installed for the detection of Bharat Pi. You can download the serial drivers from this depending on the operating system.

·      Arduino IDE

·      CH341 serial drivers for Bharat Pi


What is a SMOKE Detection Sensor (MQ-2 sensor)?

 A smoke detector is a device that senses smoke, typically as an indicator of fire. 

 MQ-2 sensor is a smoke and flammable gas sensor which can detect LPG, methane, propane, butane, alcohol, and hydrogen.

The sensor has a built-in sensing material that changes its resistance depending on the type of gas it detects. This type of sensor is also called chemiresistors.

The relationship between the output voltage and the intensity of smoke is as    follows :

As the intensity of the smoke increases, the output voltage also increases.

 As the intensity of the smoke decreases, the output voltage also decreases.

What is Bharat Pi:

In this project, we are using Bharat Pi which has both ESP32 microcontroller and a SimCom A7672S 4G/LTE module.

Bharat Pi is an IoT prototyping board for students, innovators, startups, and developers. A simplified board with an all-in-one compute, network and storage on a single board to build rapid prototypes.

Bharat Pi bundles the power of ESP32, 4G/LTE module in a Arduino form factor. This makes Bharat Pi compatible with all Arduino and ESP32 programs and shields.

Wireless monitoring can be done using WiFi or with a Sim based 4G/LTE connectivity.

Bharat Pi is a rugged board with good quality and could be used even for production and live customer deployments

Code Snippet

int led = 32;                // the pin that the LED is atteched to

int sensor = 23;              // the pin that the sensor is atteched to

int state = HIGH;             // by default, no motion detected

int val = 0;                 // variable to store the sensor status (value)

void setup() {

  pinMode(led, OUTPUT);      // initalize LED as an output

  pinMode(sensor, INPUT);    // initialize sensor as an input

  Serial.begin(115200);        // initialize serial


void loop(){

  val = digitalRead(sensor);   // read sensor value

  if (val == HIGH) {           // check if the sensor is HIGH

    digitalWrite(led, HIGH);   // turn LED ON

    delay(100);                // delay 100 milliseconds

    if (state == LOW) {

      Serial.println(“Motion detected!”);

      state = HIGH;       // update variable state to HIGH



  else {

      digitalWrite(led, LOW); // turn LED OFF

      delay(200);             // delay 200 milliseconds

      if (state == HIGH){

        Serial.println(“Motion stopped!”);

        state = LOW;       // update variable state to LOW




Smoke Detection Sensor-Based Projects and Applications

 The most common and widely used application of smoke detection sensors is in smoke alarms or detectors.

·      Smoke detection sensors can be integrated into smart home systems to enhance safety and automation.

·      In industrial settings, smoke detection sensors play a crucial role in fire prevention and early warning systems.

·      Smoke detection sensors are used in firefighting robots to locate the source of fires and navigate through smoke-filled environments.

·      Smoke detection sensors are integrated into heating, ventilation, and air conditioning (HVAC) systems to prevent smoke or fire spread through ducts.

·      Smoke detection sensors are integrated into heating, ventilation, and air conditioning (HVAC) systems to prevent smoke or fire spread through ducts.

Leave a Reply

Your email address will not be published. Required fields are marked *