Introduction

The internet of things is a technology; it can connect many physical devices with other devices through the Internet. These connected physical devices are controlled and monitored anywhere & anytime throughout the world.
In this article, we are solving a home LPG Cylinder fire prevention system using IoT technology. By reading this, you will learn how to develop an LPG gas detection system using Arduino UNO R3

Prerequisites

Hardware requirements:
Hardware Nos
Arduino UNO R3 1
Data cable for (Arduino) 1
MQ-2 Gas Sensor 1
LCD crystal [16x2] Display 1
Breadboard 1
220-ohm Resistor 1
10-ohm Potentiometer
1
Jumper wires -
Gas Lighter [For checking Gas Leakage] 1
Software requirements:
Arduino IDE (Click the link to Download Arduino IDE)
In this experiment, we can do three stages of work to develop a gas detection system
  1. Connect all the hardware
  2. Write & upload code to Arduino board
  3. Test our developed system
Stage 1 (Connect all hardware)
First, we can connect an LCD crystal display with an Arduino UNO board using jumper wires. I am using a breadboard to extend power terminals for making this system.
Refer to the below LCD crystal Pin diagram for making an easy connection with Arduino
Place a 10K ohm potentiometer near the LCD crystal display. It can adjust the contrast of the LCD screen and create a power connection from Arduino +5V and GND right and left end of the potentiometer. Make a connection from the center terminal of the potentiometer to VEE (contrast control) LCD crystal display. (Refer to the connection diagram)
Pin Configuration
Arduino Breadboard LCD Crystal Display
Pin 2 ---------------------------------------------------------------------------------------------------> Data pin 4
Pin 3 ---------------------------------------------------------------------------------------------------> Data pin 5
Pin 4 ---------------------------------------------------------------------------------------------------->Data pin 6
Pin 5 -----------------------------------------------------------------------------------------------------> Data pin 7
Pin 7 ----------------------------------------------------------------------------------------------------> Register select
Pin 6 ---------------------------------------------------------------------------------------------------> Enable
+ 5V ----------> Potentiometer Right Terminal------>Potentiometer Centre terminal ----> VEE (Contrast Control) LCD crystal
+5V ---------------------------> 220-ohm Resistor ----------------------------------------------> LED +5V pin [LCD Crystal]
GND ---------------------------------------------------------------------------------------------------->Potentiometer Left terminal, Ground pin & LED - Ground pin [Connect to both pin]
Step 2
Next, we can connect an MQ-2 Gas sensor to Arduino, it’s very simple to connect this with the Arduino board.
Arduino MQ-2 Gas sensor
A3 ------------------------------------------> A0 [Analog output pin]
+ 3.3 v or 5 V ---------------------------------> Vcc
GND --------------------------------------------> GND
All hardware connections are perfectly done :)
Stage 2 [Write & upload code to the Arduino board]
In this step, write code for Arduino using the Arduino IDE.
  1. Download Arduino software using this link here.
  2. Install and open an Arduino IDE on your PC/Laptop
  3. Connect your Arduino board to your computer using a USB data cable
  4. Copy and paste below the code into the Arduino IDE
  1. #include<LiquidCrystal.h>
  2. #define LCD_PIN_RS 7
  3. #define LCD_PIN_E 6
  4. #define LCD_PIN_DB4 2
  5. #define LCD_PIN_DB5 3
  6. #define LCD_PIN_DB6 4
  7. #define LCD_PIN_DB7 5
  8. #define gassensor A3
  9. LiquidCrystal lcd(LCD_PIN_RS,LCD_PIN_E,LCD_PIN_DB4,LCD_PIN_DB5,LCD_PIN_DB6,LCD_PIN_DB7);
  10. void setup() {
  11. Serial.begin(9600);
  12. lcd.begin(16, 2);
  13. }
  14. void loop() {
  15. lcd.setCursor(0, 0);
  16. lcd.print("C-ShCor Gas detection System");
  17. delay(500);
  18. gasread();
  19. }
  20. void gasread()
  21. {
  22. int d =analogRead(gassensor);
  23. if(d<80)
  24. {
  25. lcd.setCursor(0,1);
  26. lcd.print("No Gas Flow ");
  27. Serial.println("No Gas flow ");
  28. }
  29. else if (d>90&&d<110)
  30. {
  31. lcd.setCursor(0,1);
  32. lcd.print("Mild Gas Leak ");
  33. Serial.println("Mild Gas Leak ");
  34. }
  35. else if(d>110 && d< 150)
  36. {
  37. lcd.setCursor(0,1);
  38. lcd.print("Gas Leak detect ");
  39. Serial.println("Gas Leak Detect ");
  40. }
  41. else if (d>150&&d<300)
  42. {
  43. lcd.setCursor(0,1);
  44. lcd.print("Danger in home ");
  45. Serial.println("Danger in home ");
  46. }}
Save and upload this code to the Arduino UNO board, After Code upload is completed that device can start to detect Gas Leakage.
Stage 3 [Test our developed System]
Our device is ready… Let's create a manual gas leak using a gaslighter.
The gas detection system can detect a gas leakage successfully. It's working perfectly!