Develop a program to detect Gas Leakage in the Surrounding Environment.
To interface an MQ-2 Gas Sensor with an Arduino Uno board to detect the presence of harmful gases in the surrounding environment. The gas concentration is monitored continuously, and the gas level is displayed on the Serial Monitor. The system also generates warning messages when the gas concentration exceeds the predefined threshold.
Arduino Uno Board – 1
MQ-2 Gas Sensor Module – 1
Breadboard – 1
Jumper Wires – As Required
USB Cable – 1
10kΩ Resistor (if required)
Arduino IDE Software
Step 1:
Take an Arduino Uno board, MQ-2 Gas Sensor Module, breadboard, jumper wires, USB cable, and Arduino IDE.
Step 2:
Connect the Arduino 5V pin to the breadboard positive rail.
Step 3:
Connect the Arduino GND pin to the breadboard negative rail.
Step 4:
Connect the VCC pin of the MQ-2 Gas Sensor to Arduino 5V.
Step 5:
Connect the GND pin of the MQ-2 Gas Sensor to Arduino GND.
Step 6:
Connect the Analog Output (A0) of the MQ-2 Gas Sensor to Arduino Analog Pin A1.
Step 7:
Connect the Arduino Uno to the computer using a USB cable.
Step 8:
Open the Arduino IDE.
Step 9:
Select Tools → Board → Arduino Uno.
Step 10:
Select the correct COM Port.
Step 11:
Copy and paste the Arduino program.
Step 12:
Compile and upload the program.
Step 13:
Open the Serial Monitor.
Step 14:
Set the baud rate to 9600.
Step 15:
Wait for approximately 20 seconds to allow the MQ-2 Gas Sensor to warm up.
Step 16:
Expose the gas sensor to LPG, smoke, or other combustible gases.
Step 17:
Observe the gas level and warning messages displayed on the Serial Monitor.
MQ-2 Gas Sensor VCC → Arduino 5V
MQ-2 Gas Sensor GND → Arduino GND
MQ-2 Gas Sensor Analog Output (A0) → Arduino Analog Pin A1
Arduino 5V → Breadboard Positive Rail
Arduino GND → Breadboard Negative Rail
Arduino USB → Computer
// Gas Sensor Pin Declaration
int gasSensor = A1;
void setup()
{
pinMode(A1, INPUT);
Serial.begin(9600);
Serial.println("Gas Detection System Initialized");
Serial.println("Warming up sensor...");
delay(20000);
Serial.println("Ready to detect gas!");
}
void loop()
{
int sensorValue = analogRead(gasSensor);
Serial.print("GAS LEVEL: ");
Serial.println(sensorValue);
if(sensorValue > 400)
{
Serial.println("WARNING: Gas Leakage Detected!");
}
else if(sensorValue > 200)
{
Serial.println("CAUTION: Elevated Gas Level");
}
else
{
Serial.println("Normal Gas Level");
}
delay(1000);
}