Introduction
In this article, I'll show you how can we find out the LPG gas using the MQ2 Gas sensor and print the value in LCD (Liquid Crystal Display).
Requirements:
- Arduino Mega
- Bread Board
- MQ2 Gas Sensor
- LCD 16*2
- Led
- Buzzer
Connection:
LED:
- Anode to Digital Pin 12
- Cathode to Gnd
Buzzer:
- Anode pin to Digital Pin10
- Cathode pin to the gnd
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.
- Digital pin 10 is used to control the buzzer.
- Digital Pin 12 is connected to the led.
- If the Gas sensor value is less than 60.
- The Buzzer and led is ON.
- Displays the result in liquid crystal display.
Output:
Read more articles on Arduino: