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
  1. #include < LiquidCrystal.h >
  2. int mq = A0;
  3. int led = 12;
  4. int buz = 10;
  5. int m;
  6. float p;
  7. LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
  8. void setup()
  9. {
  10. pinMode(led, OUTPUT);
  11. pinMode(buz, OUTPUT);
  12. digitalWrite(led, LOW);
  13. digitalWrite(buz, LOW);
  14. lcd.begin(16, 2);
  15. }
  16. void loop()
  17. {
  18. d = analogRead(mq);
  19. lcd.setCursor(0, 0);
  20. lcd.print("LPG GAS SENSOR");
  21. if (m > 60)
  22. {
  23. p = 0;
  24. } else
  25. {
  26. p = (m - 60) / 9.64;
  27. }
  28. lcd.setCursor(0, 1);
  29. lcd.print(p);
  30. lcd.setCursor(5, 1);
  31. lcd.print("%");
  32. if (p >= 30)
  33. {
  34. digitalWrite(led, LOW);
  35. digitalWrite(buz, HIGH);
  36. lcd.setCursor(9, 1);
  37. lcd.print("Little Leakage");
  38. } else
  39. {
  40. digitalWrite(led, HIGH);
  41. digitalWrite(buz, LOW);
  42. }
  43. delay(500);
  44. lcd.clear();
  45. }
    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: