Gas leaks are one of the major causes of house fires. House fires result in an average of 2600 civilian deaths, 11000 injuries and 6.9 billion dollars in property damage!! And as we all know precaution is better than cure.
So today I will be taking you through a few basic steps to create your own gas sensor.
Materials required:
- Arduino Nano
- MQ2 Gas Sensor
- An Active buzzer (passive will not work)
- Wires
Circuit Diagram:

Steps:
- Connecting the MQ2 chip:
Create a common ground wire to use for the buzzer and power source as well.Connect the ground port of the Arduino ,gas sensor ,buzzer and power source.
Connect the analog pin of the gas sensor to the Arduino A0 pin.
Connect the VCC pin of the gas sensor to the Arduino 5V pin.
- Connecting the buzzer
Join the VCC pin of the buzzer to the 3.3V pin on the Arduino.
The I/O pin should go to the digital 2 pin (D2).
Connect the GND pin to the ground wire.
- CREATING A POWER SOURCE
A normal battery does not last long so, you would need to connect the Arduino to a power outlet of your house. You can do this by finding a unused phone charger and cuts it’s wire. Take the side with the USB port as shown below and remove the rubber cover on the red and black wire. This will be our power source. Now connect the red wire to the VIN pin on the Arduino and the block

Your final wiring should look more or less like the circuit diagram given above.
- CODE (Arduino IDE)
int gasSensor = 0 ;
int gasLimit = 220; //When the gas sensor sends a higher value than this number the buzzer will activate
//Set your own limits according to your need
void setup()
{
Serial.begin(9600);
pinMode(2, OUTPUT);
//The buzzer will turn on for 1 second to indicate that the device has turned on
digitalWrite(2, LOW);
delay(1000);
digitalWrite(2, HIGH);
delay(1000);
}
void loop()
{
gasSensor = analogRead(0) ;
Serial.println(gasSensor);
digitalWrite(2, HIGH);
if ( (gasSensor) > (gasLimit) )
{
Serial.print(“Gas/Fire detected”);
Serial.print(” “);
Serial.print(gasSensor);
Serial.print(” “);
Serial.println();
digitalWrite(2, LOW);
delay(1000);
}
}
Hope you guys enjoyed making this quick and amazing detector. Now u can peacefully have dinner outside without worrying about gas leaks at home. Any feedback is welcome at contact me.