This article is a continuation of the series of tutorials on the LPC2148 Microcontroller (ARM7). The aim of this series is to provide easy and practical examples that anyone can understand. In the previous tutorial, we have interfaced the Rain detection sensor with LPC2148 (ARM7). In this tutorial, we are going to see LPG Gas Sensor Interfacing with LPC2148.
Prerequisites
Before starting this tutorial we should know the below topics. If you know already, please go further.
Components Required
- LPC2148 Development Board
- GAS Sensor Module
- LCD Module (To print the Sensor output)
Introduction
There are many gases available in the environment. Like that there are many sensors available to detect particular gas. In this tutorial, we are going to detect LPG gas. So we need to use the MQ-2 sensor. Before that, we will see the sensors available to detect gas.
Features
- The operating Voltage is +5V
- Can be used to Measure or detect LPG, Alcohol, Propane, Hydrogen, CO, and even methane
- Analog output voltage: 0V to 5V
- Digital Output Voltage: 0V or 5V (TTL Logic)
- Preheat duration 20 seconds
- Can be used as a digital or analog sensor
- The PCB of this electronic circuit has a potentiometer. The Sensitivity of the Digital pin can be varied using the potentiometer
Sensors available to detect different Gases
Sensor Name | Gas to measure |
MQ-2 | Methane, Butane, LPG, Smoke |
MQ-3 | Alcohol, Ethanol, Smoke |
MQ-4 | Methane, CNG Gas |
MQ-5 | Natural gas, LPG |
MQ-6 | LPG, butane |
MQ-7 | Carbon Monoxide |
MQ-8 | Hydrogen Gas |
MQ-9 | Carbon Monoxide, flammable gasses |
MQ131 | Ozone |
MQ135 | Air Quality |
MQ136 | Hydrogen Sulphide gas |
MQ137 | Ammonia |
MQ138 | Benzene, Toluene, Alcohol, Propane, Formaldehyde gas, Hydrogen |
MQ214 | Methane, Natural Gas |
MQ216 | Natural gas, Coal Gas |
MQ303A | Alcohol, Ethanol, smoke |
MQ306A | LPG, butane |
MQ307A | Carbon Monoxide |
MQ309A | Carbon Monoxide, flammable gas |
Selecting between Sensor type and a module type
When it comes to measuring or detecting a particular Gas the MQ series Gas sensors are the most commonly used ones. These sensors can either be purchased as a module or as just the sensor alone. If you are trying to only detect (not measuring ppm) the presence of gas then you can buy it as a module since it comes with an op-amp comparator and a digital out pin. But if you planning to measure the ppm of a gas it is recommended to buy the sensor alone (without a module).
Working with Gas Sensor
Using an MQ sensor it detects a gas is very easy. You can either use the digital pin or the analog pin to accomplish this. Simply power the module with 5V and you should notice the power LED on the module to glow and when no gas is detected the output LED will remain turned off meaning the digital output pin will be 0V (LOW). Remember that these sensors have to be kept on for pre-heating time (mentioned in the features above) before you can actually work with them. Now, introduce the sensor to the gas you want to detect and you should see the output LED to go HIGH along with the digital pin, if not use the potentiometer until the output gets high. Now every time your sensor gets introduced to this gas at this particular concentration the digital pin will go high (5V) or else will remain low (0V).
You can also use the analog pin to achieve the same thing (We have not covered this part in this tutorial). Read the analog values (0-5V) using a microcontroller, this value will be directly proportional to the concentration of the gas to which the sensor detects. You can experiment with these values and check how the sensor reacts to different concentrations of gas and develop your program accordingly.
LPG Gas Sensor Interfacing with LPC2148
Connection
IR Sensor
- Vcc – 5v
- GND – Ground
- DO – P1.24
LCD
- RS – P0.8
- RW – P0.9
- EN – P0.10
- Data Lines – P0.0 – P0.7
Source Code
If it is detecting LPG gas in front of this sensor, LCD will display “Gas Detected”.
[You can download the source code from GitHub]
/* Gas Sensor Interfacing with LPC2148 * Done by EmbeTronicX */ #include<lpc214x.h> #define bit(x) (1<<x) #define delay for(i=0;i<7000;i++); #define GAS (IO1PIN & (1<<24)) unsigned int i; void lcd_int(void); void dat(unsigned char); void cmd(unsigned char); void string(unsigned char *); void main() { IO0DIR =0XFFF; IO1DIR = 0x0; lcd_int(); cmd(0x80); string("EMBETRONICX.COM "); while(1) { if(GAS) { string("Gas Detected"); } delay;delay; cmd(0x01); } } void lcd_int() { cmd(0x38); cmd(0x0c); cmd(0x06); cmd(0x01); cmd(0x80); } void cmd(unsigned char a) { IO0PIN&=0x00; IO0PIN|=(a<<0); IO0CLR|=bit(8); //rs=0 IO0CLR|=bit(9); //rw=0 IO0SET|=bit(10); //en=1 delay; IO0CLR|=bit(10); //en=0 } void dat(unsigned char b) { IO0PIN&=0x00; IO0PIN|=(b<<0); IO0SET|=bit(8); //rs=1 IO0CLR|=bit(9); //rw=0 IO0SET|=bit(10); //en=1 delay; IO0CLR|=bit(10); //en=0 } void string(unsigned char *p) { while(*p!='\0') { dat(*p++); } }
Applications
- Detects or measures Gases like LPG, Alcohol, Propane, Hydrogen, CO, and even methane
- Air quality monitor
- Gas leak alarm
- Safety standard maintenance
- Maintaining environmental standards in hospitals
NOTE: if you are planning to measure the ppm of gas then you should take the analog output from the A0 pin and need to convert that analog value to a digital value and display that using ADC.
If you want to use FreeRTOS on LPC2148, then please refer FreeRTOS series.
You can also read the below tutorials.

Embedded Software | Firmware | Linux Devic Deriver | RTOS
Hi, I’m SLR. 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!