Introduction: DIY Gas Leak and Smoke Detector

Ok, so this is my first instructable article, so i will try my best. :)

So the idea is quite simple, yet useful; Making a gas detector that can detect smoke(in case of fire) and LPG/Natural gas leak from kitchen and warn the owner of potential hazard via both alarm and text message or voicemail, and that too small enough to be hanged to the kitchen wall without taking much space. It is a small weekend project and can be completed in a day if materials are available and ready.


A little Introduction about MQ-6 Combustible Gas Sensor and MQ-2 Air Quality Sensor :-

First of all, they are both analog sensors, and their voltage output is directly proportional to the concentration of the gas. So, later you will observe we use analogRead() function of arduino to check the value of output voltage of sensors to determine the gas concentration.

MQ - 2 Datasheet :- www.seeedstudio.com/depot/datasheet/MQ-2.pdf
MQ - 6 Datasheet :- www.probots.co.in/Datasheets/MQ6.pdf

If you are geeky then you may consider reading the above two datasheets, will be useful. For others the brief introduction I have given below may suffice.

MQ-2 and MQ-6 both are made of SnO2 which have high resistance in clean air but their resistance decrease in presence of combustible gas. That means, when sensor get in contact with combustible gases, its output voltage will increase as resistance will decrease.

Whereas MQ-6 is combustible gas sensor, MQ-2 is a wide range gas sensor and it can detect combustible gases like propane,butane,iso-butane, hydrogen and also smoke.

Step 1: Items Required

The following items can be procured online or from robotics shop easily...

Electronic Components:-

1. Arduino Microcontroller
2. GSM GPRS Sim900A Module(Please first make sure your area supports GSM connection!)
3. MQ-6 LPG Sensor Module
4. MQ-2 Air Quality Sensor Module
5. Piezo Buzzer
6. Power adapter(that matches your GSM
module power specifications, will
also be used to power arduino)
7. Some wire jumpers
8. Two 10,000 Ohm resistance(not required if you get Sensors fixed with breakout board. )

Non- Electric Components:-

1. PVC box/casing

Tools and Misc:-

1. Wire cutters
2. Soldering kit
3. Glue(Silicone will be best, but superglue will still suffice)
4. Small screws and nuts
5. Multimeter(Optional but very useful for testing)

Step 2: Setting the Parts:-

So, here I have used a PVC box with lid to mount all the parts and connections in it. It can be easily opened and connections/electronics can be checked. Plus it protects the electronics and increase their life.

As you can see, I have cut a holes on the side of the box, first one for the insertion of power wire, second on the down side is for the sensor so that it can readily come contact with air.
Third hole on the lid of the box is for the piezo buzzer so that its noise can be reciprocated in the surrounding not get trapped in the box. I have cut the holes using a red hot knife, was much easier, you can use any alternative method you find suitable.

I have used small screws(preferably with nuts) to secure the components on the base of the box, after boring a small holes at the base so that screw insertion is easier.

Also one thing, i have secured the piezo buzzer by pushing it in molten plastic of the lid(done with a hot rod ), in that way, piezo buzzer get perfectly secured as the plastic cools down.

For the hanger(if you want to hang it one the wall) use a metal strip with one end punched and second end screwed to the OPPOSITE side of the box which houses sensor.

Step 3: The Circuit


OK, this part is easy if you have sensor with breakout board, BUT if you have just sensors, you may have to do some soldering and an extra component(a 10,000 Ohm resistance per sensor will be required). This link here explains the wiring of gas sensor. In the second picture you can see the wiring of the sensor without breakout board.

In the pictures I have used one sensor with breakout board another without it. The connections is given below or follow the first diagram for the circuit.

For GSM Module:-

Tx -> Rx of Arduino(pin 0)

Rx -> Tx of Arduino(pin 1)
Gnd -> Gnd Arduino
Vin -> Power Supply +ve
Gnd ->Power Supply -ve

A 2G or lower Simcard may be used for the GSM module to send messages/voicemail. Please make sure that your local area supports 2G connectivity over wireless transmission, otherwise you may have to use a higher version of cellular shield.


Piezo Buzzer:-
Two wires one to pin 2 Arduino another t pin3 Arduino. Sequence does not matter.

Additionally, Input power +ve to Arduino Vin and Input -ve to Gnd Arduino.

You may be having difficulty finding out sensor wiring terminals, follow the below steps in such case.

Note:- If you have both sensors with breakout board, follow 1 only. If don't have breakout board, follow 2 only.

Method 1.

The connection of sensor breakout board is as follows:-
sensor GND - arduino GND
sensor Vcc - 5V arduino
sensor OUT - A0 pin arduino

Method 2.

The connection without breakout board is:-
As followed in second picture EXCEPT the analog input pin which goes to arduino pin A1.


At last, please make sure for this project that there is NO loose connections, secure the connection by either soldering or driving a jumper pin in case of modules, trust me it will save you from problems later.

Step 4: Programming the Arduino

Copy and paste the following code from here, or you may make some modifications in it suiting your purpose.

int pin1=A0; // MQ-6 LPG GAS SENSOR OUTPUT PIN
int pin2=A1; // MQ-2 AIR QUALITY SENSOR OUTPUT PIN 

int trigger1=400; //AT WHAT SENSOR OUTPUT VOLTAGE VALUE LPG ALARM WILL BE TRIGGERED
int trigger2=400; //AT WHAT SENSOR OUTPUT VOLTAGE VALUE SMOKE ALARM WILL BE TRIGGERED

void setup() 
{
 pinMode(pin1,INPUT);
 pinMode(pin2,INPUT);
 Serial.begin(9600);
 delay(5000); 
 pinMode(2,OUTPUT);
 pinMode(3,OUTPUT);
}

void send_sms(char ch[]) // TO SEND SMS VIA GSM MODULE
{
 Serial.println("AT");
  delay(1000);
  Serial.println("AT+CMGF=1");
  delay(1000);
  Serial.println("AT+CMGS=\"+91**********\""); //CHANGE TO THE DESTINATION PHONE NUMBER
  delay(1000);
  Serial.print(ch);
  Serial.write(26);
  delay(300000);  
}

void beep(int pin) // TO WARN ABOUT GAS LEAK IF SOMEONE IS PRESENT AT HOME, BUZZER MUST          {                 //BE CONNECTED AT PIN 2 AND 3 OR CHANGE THEM AT YOUR WILL
  while(analogRead(pin)>=200)
  {
   for(int i=0;i<100;i++)
   { 
    digitalWrite(2,HIGH);   
    digitalWrite(3,LOW);
    delay(1);
    digitalWrite(3,HIGH);
    digitalWrite(2,LOW);
    delay(1);
   }
   delay(100);
   digitalWrite(2,LOW);
   digitalWrite(3,LOW);
   delay(100);
 }
}

void loop() 
{
char ch1[]="Attention! Gas leakage at Home! Attention!";   //DIFFERENT MESSAGE IN DIFFERENT CASES
char ch2[]="Attention! Thick smoke detected at Home! Attention!";
int sensor1 = analogRead(pin1);
int sensor2 = analogRead(pin2);
 if(sensor1>=trigger1)     //IN CASE LPG/COOKING GAS LEAKAGE IS DETECTED
 {
  beep(pin1);
  send_sms(ch1);
 }
 else if(sensor2>=trigger2) // IN CASE SMOKE IS DETECTED
 {
  beep(pin2);
  send_sms(ch2); 
 }
}

I have written the code in part and functions in case you may want to change some of it or add few extras for expansion.

One thing to notice that trigger values are the analog output values of the sensor. Arduino takes analog output in the pins A0 to A5 in range of 0-5 V and convert them in 1024 parts( 0V gives 0 and 5V gives 1023). Since trigger value here is set to 400, that means (400*5)/1024 = 1.9 V approx. and hence when sensor voltage gets above 1.9 V alarm will be triggered.

Step 5: Checking and Then Complete!

Great ! We are nearly finished. But before we start to use it, Do some checks to make sure the sensors are calibrated properly. So, make mock tests by exposing them to LPG/Gas(preferably from a cigarette lighter ) or Smoke to see at how much concentration is needed to trigger the sensors and change the trigger values accordingly.
In case you are leaking combustible gas from oven , DON'T LEAK TOO MUCH GAS ! seems silly but happens when you are testing. Remember I said no loose connections in circuit part ? Combustible gases and electricity don't mix well and will make a good Kaboom firework show ;)

Thanks for following and if you have any query please feel free to ask :)

Home Automation

Participated in the
Home Automation