Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Complete Sensor Guide
      • Engineering Deep Dives
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Tech Terms
    • Webinars & Digital Events
  • Resources
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • White Papers
  • Guest Post Guidelines
  • Advertisers
    • Advertise
    • PR Submissions
    • Eblast Submissions
  • Subscribe

Arduino based Gas Leakage Detection Using MQ6 Gas Sensor

By Praveen Kumar, Chennai, India March 24, 2017

Gas leakage is one of the common reasons for fire breakouts. A leakage turns out to be cause of terrible accident particularly in closed buildings. Many of the hotels and restaurants do not keep any security measures to detect gas leakage due to lack of enforcement of standards and pre-assumption that installing such precautionary systems will be costly. This is a gas leakage detection project based on Arduino UNO. The low cost project uses MQ6 gas sensor which can be calibrated to detect leakage levels based on surroundings. The installation generates a sound alert using buzzer on detection of a dangerous leakage. The project utilizes the 434 MHz RF module so the alarm can be installed anywhere within the building and even multiple alarms can be installed within a building.

Prototype of Arduino and MQ6 Gas Sensor based LPG Gas Leakage Detector

Fig. 1: Prototype of Arduino and MQ6 Gas Sensor based LPG Gas Leakage Detector

The MQ6 gas sensor detects concentration of gas in ppm and outputs analog value which can be converted to digital measure using in-built Analog to Digital Convertor of Arduino. The value of the digital measure will be 10-bit long and varies from 0 to 1023. The project allows user to set the dangerous level for leakage based on the same digital measure. When the value set by the user matches with that of the value detected by the sensor, it invokes the alarm. The MQ6 sensor can be calibrated by interfacing a load resistance of fixed value with the sensor.

The entire project is built on Arduino UNO. The program code running the project is developed on Arduino IDE and burnt to the board using AVR Dude.

COMPONENTS REQUIRED

Receiver Side

1.  Arduino UNO

2.  Tx RF module(433MHz)

3.  16×2 LCD

4.  1K ohm resistor

5.  5mm LED

6.  10K ohm PRESET

7.  Two pin plug

8.  Three pin holder

9.  MQ6 gas sensor

10. Resistor- 1M ohm

11. HT12E IC

12. Push-to-on Switches

Transmitter Side

1. Tx RF module(433MHz)

2. Resistor- 1M ohm and 47K ohm

3. HT12D IC

4. Voltage regulator -7805

5. Buzzer

6. BC547 transistor

Block Diagram of Arduino and MQ6 Gas Sensor based LPG Gas Leakage Detector

Fig. 2: Block Diagram of Arduino and MQ6 Gas Sensor based LPG Gas Leakage Detector

CIRCUIT CONNECTIONS

There are two circuits in the project – transmitter circuit and the receiver circuit. The transmitter circuit is built on Arduino UNO and it has MQ6 gas sensor interfaced to it. The circuit is provided human interface using two tactile switches and an LCD display. The circuit is interfaced with the RF transmitter to send alert signals to the receiver circuit.

The receiver circuit is basically RF receiver circuit with buzzer circuit interfaced with the decoder IC. More than one receiver circuits can also be made and used with the project to add multiple alarms. All the alarm circuit added in the project will alert simultaneously when there will be a gas leakage. It should be taken care that if multiple alarm circuits are added in the project, all the RF receivers in those circuits should be configured to the same address byte as that of the RF transmitter in the transmitter circuit.

Power Supply – Both the circuits will be powered by 5V DC supply. The 7805 voltage regulator is used to supply the desired voltage. The power can be drawn from a regular battery which can be connected to the 7805 IC. The IC has three pins – pin 1 should be connected to anode of the battery, pin 2 and 3 with the cathode (common ground). The 5V DC should be drawn from the pin 3 of the IC.

The transmitter circuit has the following sections interfaced to it – :

MQ6 Gas Sensor – The MQ6 gas sensor is a gas sensor module. The module has 4 pins for interfacing of which two pins are VCC and ground, one pin is analog output and one pin is digital pin via a comparator (LM358). The analog output pin of the module is used for detecting concentration level of gas leakage and interfaced with the A0 analog input pin of the Arduino board. The sensor measures the concentration of leaked gas in ppm according to the following formulae – :

Concen = 1036.5*R^-2.392 Where

Concen is the concentration of LPG in ppm

R is the ratio of Rs the resistance of sensor to the R0 which is the resistance at 1000ppm at 20 degree Celsius and 65% humidity.

The resistance of the sensor Rs is given by the formulae – :

Rs = (1024/ADC_DATA-1)*RL where

Rs is the resistance of the sensor

ADC_DATA is digital reading ranging from 0 to 1023

RL is load resistance ranging from 10K to 40K ohms

Therefore, for a fixed load resistance, the ADC reading is proportional to the concentration of gas in ppm.

In the datasheet the ratio of concentration to the sensor resistance is given. The graph is done under the normal condition of 20 degree Celsius and 65% humidity. And that means Rs=R0 for the curve.

Graph showing sensitivity curve of MQ6 Gas Sensor

Fig. 3: Graph showing sensitivity curve of MQ6 Gas Sensor

This way the concentration of gas in ppm becomes equal to ADC reading. The ADC reading will range between 0 and 1023. In the project, the user can set the dangerous level of ADC reading for reference in steps like 200, 250, 300, 350, 400, 450 and 500.

2-switch keypad – There are two tactile switches provided at the transmitter circuit. The switches are connected to the A4 and A5 pin of Arduino UNO with 1K ohm pull-up resistors. On pressing one switch the value of sensitivity of the sensor for comparison is increased. On pressing the other switch, the increased value is selected as the reference value of sensitivity for comparison. The value incremented or selected is displayed on the LCD screen.

16X2 LCD – The 16X2 LCD display is used to display the increment or selection of sensor’s sensitivity. It is connected to the Arduino board by connecting its data pins to pins 2 to 5 of the Arduino board. The RS and E pins of the LCD are connected to pins 13 and 12 of the Arduino UNO respectively. The RW pin of the LCD is grounded.

Table listing circuit connections between Arduino Uno and Character LCD

Fig. 4: Table listing circuit connections between Arduino Uno and Character LCD

The standard open-source library for interfacing LCD with Arduino UNO is used in the project. The library works as expected and needs no changes or modifications.

RF Transmitter – The RF transmitter is used to transmit the alert signal to the receiver circuit. The RF transmitter module is a small PCB sub assembly. The pin configuration of transmitter module is as follows – :

Table listing pin configuration of RF Transmitter

Fig. 5: Table listing pin configuration of RF Transmitter

The serialized data from encoder is received at pin 2 of the module and passed on to the antenna from pin 4 of the module.

HT12E IC – The HT12E IC converts the parallel data into serial data for passing it to the RF transmitter. HT12E encoder IC belongs to the 212 series of encoders. It is paired with 212 series of decoders having the same number of addresses and data format. HT12E is capable of encoding 12 bits, out of them 8 are address bits and 4 are data bits. Thus the encoded signal is a serialized 12-bit parallel data comprising of 4-bit data to be transferred appended with the address byte.

The receiver circuit is a basic RF receiver with buzzer circuit interfaced to it. The circuit has the following sections -:

Power Supply – The receiver circuit is also powered by the similar 7805 based DC supply as the transmitter circuit.

RF Receiver – The RF receiver detects the radio signal carrying the alert information. The RF receiver module has 8 pins and has following pin configuration.

Table listing pin configuration of RF Receiver

Fig. 6: Table listing pin configuration of RF Receiver

HT12D Decoder – The signal detected from the RF receiver is passed to the HT12D decoder. It converts the serial data back to the parallel data after separating data and addresses. HT12D belongs to the 212 series of decoders and can be paired with 212 series of encoders having the same number of addresses and data format. HT12D is capable of decoding 12 bits, out of them 8 are address bits and 4 are data bits. The 4-bit data is of latch type and when passed to the output data pins it remains unchanged until the new data is received.

Buzzer – A regular piezoelectric buzzer is used in the receiver circuit. The buzzer is interfaced to D0 bit of the HT12D decoder IC. The buzzer is interfaced through a BC547 transistor connected in common emitter configuration.

HOW THE PROJECT WORKS

The project operates in the following phases -:

1) Setting the sensitivity level – When the transmitter device is switched ON, the Arduino board loads the imported libraries and initializes LCD display. Some initial messages are displayed on the LCD and after 3 seconds the user is prompted to set the sensitivity level. The user can increase the sensitivity level in increments of 200, 250, 300, 350, 400, 450 and 500 by pressing one switch. On pressing the switch the value for reference increases then decreases repeatedly. Each value corresponds to concentration level in PPM. On pressing other switch, the sensitivity value is set for the reference.

2) Monitoring Gas Concentration – Once the reference value is set, the program code on Arduino keeps track of the analog value read from the MQ6 sensor. The device is programmed to read current sensor reading as analog value and convert it to a digital form. The digital measure is compared with the user defined reference value in an infinite loop.

3) Sending Danger Alert – If the current value measured from the sensor equals or exceeds the user defined reference value, the transmitter device is programmed to set the pin 6 of Arduino board HIGH. The pin 6 of the Arduino is connected to D0 bit of the encoder IC. Therefore, the RF transmitter starts transmitting the 0x1 as the data bit. The same bit is decoded as HIGH logic at the D0 bit of the decoder IC. When a HIGH bit is received at D0 bit, the buzzer circuit get the required supply and starts blowing. It should be taken care that in every receiver alarm circuit of the project, all the address bytes should be same as the address byte of the transmitter circuit and the buzzer section in the respective receiver circuit(s) should be connected at the D0 pins of the respective decoder ICs.

PROGRAMMING GUIDE

The receiver circuits will not have any programmable controller or IC. The receiver circuits should have the same address byte of the RF receiver configured, as of the transmitter RF module and buzzer sections should be connected to the D0 bits of decoder ICs. The transmitter circuit will have the program code for reading and comparing sensor value and sending RF data to the receiver sections.

First the LCD.h library needs to be imported and an object of LCD class needs to be initialized. An array to contain the predefined reference values also needs to be declared.

#include <LiquidCrystal.h>//import the LCD library
LiquidCrystal lcd(13, 12, 5, 4, 3, 2); // Sensor sensitivity value set
int Ref[8] = { 0,200,250,300,350,400,450,500};

There needs to define two variables and assign them to the pins where tactile switches are connected. A variable is defined and assigned to the pin connected to D0 bit of encoder IC. Variables to store the reference sensor value and current sensor value are declared. A counter is also initialized.

// the setup routine runs once when you press reset:
int KEY1=A5;              // RIGHT KEY
int KEY2=A4;              //LEFT KEY
int buzzer=6;             // For buzzer 
int Setref=0;             // user set sensor value
int count=0;             //to count the number of times key pressed
int sensorValue=0;       //for current sensor value

A setup() function is declared in which the baud rate for serial transmission of data to the  LCD is set to 9600 bits per second using Serial.begin() function. The pins where tactile switches are connected are set to digital input and pin that has to relay logic to D0 pin of the encoder IC is set to the digital output using PinMode() function. The LCD is initialized using lcd.begin() function and initial messages are printed on it.

void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  pinMode(KEY1, INPUT);
  pinMode(KEY2, INPUT);
  pinMode(buzzer, OUTPUT);
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print(“Engineers Garage”);
  lcd.setCursor(0,1);
  lcd.print(” MQ6 Gas Sensor “);  
  delay(3000);
  lcd.setCursor(0,1);
  lcd.print(”                “);   
}

A loop() function is called in which first the messages are displayed on LCD to prompt the user to set a reference value of sensitivity. The status of both the switches is tracked by checking LOW logic at the respective pins and accordingly a value is stored in the variable holding reference value and the user actions are visually guided on the LCD display.

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  lcd.setCursor(0,0);
  lcd.print(“Press Left Bttn “);
  lcd.setCursor(0,1);
  lcd.print(“Set Sensitive”);
  digitalWrite(buzzer,LOW);
 if(digitalRead(KEY2) == 0)
 {
    count++;
    Setref=Ref[count];
    lcd.setCursor(13,1);
    lcd.print(Setref);
    if(count==8)
    {count=0;}
    delay(200);
 }
  if((digitalRead(KEY1) == 0) && count > 0)
   {
    lcd.setCursor(0,0);
    lcd.print(“Sensitivity =”);
    lcd.setCursor(13,0);
    lcd.print(Setref);
    lcd.setCursor(0,1);
    lcd.print(“MQ6 sensor        “);

An infinite while loop is called in which the current sensor value is read using the analogread() function at the A0 pin of the Arduino. The current sensor value is displayed on the LCD. The current value is compared with the reference value set by the user and if it equals to the reference value, the message “Alert !” is displayed on the LCD and the data bit D0 is set HIGH and LOW for five times repeatedly to blow the buzzer at the receiver circuit(s). The counter controlling HIGH and LOW logic transfer to D0 bit of RF data is initialized to zero in the end of the loop.

while(1)
   {
  sensorValue = analogRead(A0);
  lcd.setCursor(11,1);
  lcd.print(sensorValue  );
  delay(1);        // delay in between reads for stability
  if(Setref==sensorValue)
  {
    lcd.setCursor(0,0);
    lcd.print(“Alert!!         “);
    lcd.setCursor(0,1);
    lcd.print(“Alert!!         “);
    for(int i=0;i<=5;i++)
    {
    digitalWrite(buzzer,HIGH);
    delay(500);
    digitalWrite(buzzer,LOW);
    delay(500);
    }
    delay(3000);
    count=0;
    break;
  }
  }
   }
 }

This completes the program code for Arduino Based Gas Leakage Detection Project using MQ6 Gas Sensor.

Project Source Code

###


#include <LiquidCrystal.h>//import the LCD library

LiquidCrystal lcd(13, 12, 5, 4, 3, 2); // Sensor sensitivity value set

int Ref[8] = { 0,200,250,300,350,400,450,500};

// the setup routine runs once when you press reset:

int KEY1=A5;              // RIGHT KEY

int KEY2=A4;              //LEFT KEY

int buzzer=6;             // For buzzer 

int Setref=0;             // user set sensor value

int count=0;             //to count the number of times key pressed

int sensorValue=0;       //for current sensor value

void setup() {

  // initialize serial communication at 9600 bits per second:

  Serial.begin(9600);

  pinMode(KEY1, INPUT);

  pinMode(KEY2, INPUT);

  pinMode(buzzer, OUTPUT);

  lcd.begin(16,2);

  lcd.setCursor(0,0);

  lcd.print("Engineers Garage");

  lcd.setCursor(0,1);

  lcd.print(" MQ6 Gas Sensor ");  

  delay(3000);

  lcd.setCursor(0,1);

  lcd.print("                ");   


}


// the loop routine runs over and over again forever:

void loop() {

  // read the input on analog pin 0:

  lcd.setCursor(0,0);

  lcd.print("Press Left Bttn ");

  lcd.setCursor(0,1);

  lcd.print("Set Sensitive");

  digitalWrite(buzzer,LOW);

 if(digitalRead(KEY2) == 0)

 {

    count++;

    Setref=Ref[count];

    lcd.setCursor(13,1);

    lcd.print(Setref);

    if(count==8)

    {count=0;}

    delay(200);

 }

  if((digitalRead(KEY1) == 0) && count > 0)

   {

    lcd.setCursor(0,0);

    lcd.print("Sensitivity =");

    lcd.setCursor(13,0);

    lcd.print(Setref);

    lcd.setCursor(0,1);

    lcd.print("MQ6 sensor        ");

    

   while(1)

   {

  sensorValue = analogRead(A0);

  lcd.setCursor(11,1);

  lcd.print(sensorValue  );

  delay(1);        // delay in between reads for stability

  if(Setref==sensorValue)

  {

    lcd.setCursor(0,0);

    lcd.print("Alert!!         ");

    lcd.setCursor(0,1);

    lcd.print("Alert!!         ");

    for(int i=0;i<=5;i++)

    {

    digitalWrite(buzzer,HIGH);

    delay(500);

    digitalWrite(buzzer,LOW);

    delay(500);

    }

    delay(3000);

    count=0;

    break;

  }

  }

   }

 }
 

###

 


Circuit Diagrams

Circuit-Diagram-Arduino-MQ6-Gas-Sensor-Based-LPG-Gas-Leakage-Detector

Project Video


Filed Under: Electronic Projects

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

Log in to leave a comment:

Lost your password?

Don't have an account? Register here

Submit a Guest Post

submit a guest post

EE TECH TOOLBOX

“ee
Tech Toolbox: Wide Bandgap Semiconductors
Moving from silicon to GaN or SiC feels like a whole new ballgame, doesn’t it? It isn’t just about faster switching; it’s about managing the layout parasitics and thermal realities that come with that speed. This month’s Tech Toolbox features a curated eBook that tackles these design hurdles head-on.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS feed: EDABOARD.com Discussions. EDABOARD.com Discussions.

  • Inductor is not shielded.
  • Boost converter blows LED up?
  • Setting polar coords origin in KICAD?
  • FFT simulation time reduction
  • Capacitive touch sensor not working

RSS feed: Electro-Tech-Online.com Discussions Electro-Tech-Online.com Discussions

  • Mikroe EasyPIC 4 Power Supply
  • How to size the capacitor for ripple
  • Plate capacitor series inductance & resistance.
  • Voltage Reference Generation for Opamp
  • PLC PCB Design: How Do You Handle Isolation, Noise and Protection in 24V I/O Circuits?

Featured Tutorials

LoRa and LoRaWAN: A Complete Guide to Wireless Communication

  • Best practices for securing LoRa networks
    Best practices for securing LoRa networks
  • Understanding LoRa architecture: nodes, gateways, and servers
    Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
    Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
    How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
    How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices
    How communication works between two LoRa end-node devices
More Tutorials >

Recent Articles

  • Melexis adds 1 A automotive LIN motor drivers
  • SECO adds x86, graphics and AI in compact module
  • How to upgrade an ESP32 audio recorder with MP3 output and noise cancellation
  • UNI-T scopes combine compliance and protocol tools
  • Infineon adds 1,200 A modules for commercial EVs

EE ENGINEERING TRAINING DAYS

engineering
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2026 Arrowfly LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of Arrowfly
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Complete Sensor Guide
      • Engineering Deep Dives
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Tech Terms
    • Webinars & Digital Events
  • Resources
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • White Papers
  • Guest Post Guidelines
  • Advertisers
    • Advertise
    • PR Submissions
    • Eblast Submissions
  • Subscribe