Over a million developers have joined DZone.

LPG Sensor Using Arduino Uno

DZone's Guide to

LPG Sensor Using Arduino Uno

In the mood for a quick project? Learn how to create a gas sensor with Arduino Uno.

· IoT Zone
Free Resource

Cisco IoT makes digital transformation a reality in factories, transportation, and utilities. Learn how to start integrating with Cisco DevNet.

In this article, I'll show you that how can we find out the LPG gas using the MQ2 gas sensor and print the value in LCD.


  • ArduinoMega.
  • Bread Board.
  • MQ2 Gas Sensor.
  • LCD 16*2.
  • LED.
  • Buzzer.




  • Anode to digital pin 12.
  • Cathode to ground.  


  • Anode pin to digital pin 10.
  • Cathode pin to the ground.


#include < LiquidCrystal.h >  
    int mq = A0;  
int led = 12;  
int buz = 10;  
int m;  
float p;  

LiquidCrystal lcd(2, 3, 4, 5, 6, 7);  

void setup()  
    pinMode(led, OUTPUT);  
    pinMode(buz, OUTPUT);  
    digitalWrite(led, LOW);  
    digitalWrite(buz, LOW);  
    lcd.begin(16, 2);  
void loop()   
    d = analogRead(mq);  
    lcd.setCursor(0, 0);  
    lcd.print("LPG GAS SENSOR");  

    if (m > 60)   
        p = 0;  
    } else   
        p = (m - 60) / 9.64;  
    lcd.setCursor(0, 1);  
    lcd.setCursor(5, 1);  
    if (p >= 30)   
        digitalWrite(led, LOW);  
        digitalWrite(buz, HIGH);  
        lcd.setCursor(9, 1);  
        lcd.print("Little Leakage");  
    } else   
        digitalWrite(led, HIGH);  
        digitalWrite(buz, LOW);  


  • The gas sensor is connected to the analog input pin A0.
  • The digital pin 10 is used to control the buzzer.
  • The digital pin 12 is connected to the LED.
  • If the gas sensor value is less than 60.
  • The buzzer and LED are ON.
  • Displays the result in liquid crystal display. 


Cisco is a software company. Surprised? Don’t be. Join DevNet to explore APIs, tools, and techniques that developers are using to add collaboration, IoT, security, network priority, and more!

iot app development ,arduino

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}