Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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

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.

Requirements

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

Connection

 

LED

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

Buzzer

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

Programming


#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.print(p);  
    lcd.setCursor(5, 1);  
    lcd.print("%");  
    if (p >= 30)   
    {  
        digitalWrite(led, LOW);  
        digitalWrite(buz, HIGH);  
        lcd.setCursor(9, 1);  
        lcd.print("Little Leakage");  
    } else   
    {  
        digitalWrite(led, HIGH);  
        digitalWrite(buz, LOW);  
    }  
    delay(500);  
    lcd.clear();  
} 


Explanation

  • 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. 

Output

Topics:
iot app development ,arduino

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}