In this tutorial, we are going to see a Gas Leakage Detection System using 8051.
Table of Contents
Gas Leakage Detection System using 8051
Abstract
Gas leakage tragedies and accidents have led to heavy losses over the years. So it is very important to detect any gas leakage and prevent any accidents. So here we propose a system to detect LPG gas leakage scenarios and provide a security alert to intended users.
SMS-based LPG gas leakage detection system using GSM has application in various areas like home, industries, hotels, hospitals. This project has a gas leakage detector implemented by using an LPG Gas sensor. The user can get remote indication through SMS sent from the project. This SMS is sent from the GSM modem which is connected to the microcontroller. A buzzer is turned on after LPG gas leakage so it acts as a gas leakage alarm.
Components Required
We have our own EmbeTronicX store called ChipTronicX. You can purchase the hardware from there.
- 8051 Development board
- LCD Module
- GSM Module
- Gas Sensor
- Buzzer
- ADC0804
- Relay
Software Required
- Keil IDE
Prerequisites
Before seeing the code, first you can see the basic interfacing tutorials of these components.
- LCD Interfacing with 8051
- GSM Interfacing with 8051
- Relay Interfacing with 8051
- ADC0804 Interfacing with 8051
Block Diagram
Explanation
- A gas sensor is used to detect the Gas, which is connected to 8051 microcontrollers through ADC0804.
- LCD is used to Display the Gas level and Relay status.
- GSM is used to send the message when it detects the Gas in-room or home.
- The buzzer also makes a sound when the controller detects any Gas.
- Relay also connected to Micro Controller. The house’s electricity power will go through this relay. When it detects gas leakage, the relay goes off. So house electricity will be off. It will prevent the other damages by electricity.
Circuit Diagram
LCD:
- RS – P3.7
- RW – GND
- EN – P3.6
- Data lines – P1
Gas Sensor:
- Output – ADC’s Vin (6th Pin)
ADC0804:
- RD – P0.7
- WR – P0.6
- INTR – P0.5
- CS – GND
- Data Lines – P2
GSM:
- GSM RX – P3.1
- GSM TX – P3.0
Buzzer: P0.1
Relay: P0.0
Code
Here I’ve added only the main code. Header files are not here. You can download the full code Here.
#include<reg52.h>
#include"LCD.h" //rs=p3.7, en=p3.6
#include"GSM.h"
#define NUM "1234567890" //Enter Your Mobile Number
sbit rd=P0^7;
sbit wr=P0^6;
sbit intr=P0^5;
sbit RELAY=P0^0;
sbit buzz=P0^1;
unsigned char h,msgq;
unsigned int s,r;
void adc();
unsigned char adc_data=0;
void main()
{
init_serial();
LCD_initialise();
RELAY=1; //relay on
buzz=0; //buzz on
comwrt(0x80);
display("LOADING.");
for(h=0;h<8;h++) {
datawrt('.');
for(s=0;s<30000;s++);
}
P2=0xFF;
comwrt(0x80);
display("GAS:000PPM R:OFF");
buzz=0;
for(r=0;r<=10000;r++);
while(1) {
adc();
for(r=0;r<=20000;r++);
}
}
void adc()
{
wr=0;
rd=1;
wr=1;
while(intr==1);
rd=0;
adc_data = P2 ;
msgq = adc_data;
comwrt(0x84);
datawrt((msgq/100)+0x30);
datawrt(((msgq/10)%10)+0x30);
datawrt((msgq%10)+0x30);
if(msgq > 80) {
RELAY=0; //relay off
buzz=0; //buzz on
comwrt(0x8D);
display("OFF");
comwrt(0xC0);
display("G:HIGH V:CLOSE");
for(s=0;s<60000;s++);
comwrt(0xC0);
display("SENDING MSG.....");
sendSMS(NUM,"VOLVE CLOSED AND POWER DISCONNECTED DUE TO GAS LEAKAGE!");
for(s=0;s<30000;s++);
comwrt(0x80);
display("GAS:");
comwrt(0x8b);
display("R:");
} else {
comwrt(0xC0);
display("G:NORMAL V:OPEN ");
RELAY=1; //relay on
buzz=1; //buzz off
comwrt(0x8D);
display("ON ");
}
}
Explanation
- The gas sensor detects gas leakage in the home. This value is analog. So we need to connect ADC to convert Digital.
- If the Gas level is high, the microcontroller turns OFF the Relay to cut the electricity. The ON the buzzer. Finally, it sends the message to the house owner about gas leakage using GSM.
Please read the other 8051 projects.
You can also read the below tutorials.

Embedded Software | Firmware | Linux Devic Driver | RTOS
Hi, I am a tech blogger and an Embedded Engineer. I am always eager to learn and explore tech-related concepts. And also, I wanted to share my knowledge with everyone in a more straightforward way with easy practical examples. I strongly believe that learning by doing is more powerful than just learning by reading. I love to do experiments. If you want to help or support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning!
Discover more from EmbeTronicX
Subscribe to get the latest posts sent to your email.



Can’t find gas sensor, gsm in proteus…Can you please drop the exact key word ?
These are not available in the proteus. We have just given a block for connection diagram.
Can any tell abt the relay connection. pls figure it out ,one pin in connected to p0.0,
Does we need to give another pin to 5v or gnd
The relay has been connected to the Relay driver. P0.0 is connected to the relay driver. Please read the below posts to get a better understanding.
can you guys explain complete connection of the relay???
there are 5 pins to connect
please elaborate
We don’t remember the value. But you can try with any value as it is just pull up.
What is respack 7?
im unable to find one anywhere.
can anybody please tell me if i can run this circuit without respack 7?
if not please share me a link of the product to buy
Hi,
Respack is nothing but a pull up resistor. We have to connect the pull up resistor to Port 0.
what is the value of that pull up resistor??
and what should i ask the person while buying??
like ” i need a certain value 8 pin pull up resistor??”
A typical pull-up resistor value is 4.7kilo Ohms, but can change depending on the application.
Its looks like this https://www.electronicscomp.com/10kohm-9-pin-sip?gclid=Cj0KCQjw8amWBhCYARIsADqZJoVm_dhQ-C4pefTv4o6PPc6-bCg3848VABO-xiyR24EFY1kTYc_2EqEaAqZfEALw_wcB
One last question
is the resistor used in this circuit are of 4.7kohm or 10kohm?
Will this code work in hardware connection??
This must work. But you have to connect your hardware properly as per the code.
which version of proteus did you use for the simulation?
In this tutorial, we have used proteus for connection diagrams and not for simulation purposes.
can you send circuit with power supply immage
RESpack 8 or 7 what is it and it available in market ?
Yes it is available. That is pullup resistor