Interfacing MQ5 LPG Sensor to Arduino

In this guide, we learn how to interface MQ5 Gas sensor (which is a generic Gas Sensor more suited to detect and determine LPG concentrations) with Arduino.

In this tutorial, we are using the MQ5 Gas sensor module (which is widely available in market) . This module has two output possibilities – an analog out (A0) and a digital out (D0). The analog out can be used to detect Gas leakage and to measure volume of Gas leakage (by doing proper calculation of the sensor output inside program) in specific units (say ppm). The digital out can be used to detect Gas leakage and hence trigger an alert system (say a sound alarm or an sms activation etc). The digital out gives only two possible outputs – High and Low (hence its more suited for detection of gas leak than to measure volume of gas presence).

Note:- We have developed a Gas Leakage Detector using Arduino and MQ5 with SMS Alert, Sound Alarm and Relay activation. You can try this interesting project to gain more knowledge and build a practical application using MQ5 sensor.

Note 2:- We have created 100+ simple and advanced arduino projects – which you can try yourself for your electronics engineering course or to gain knowledge! You can also try most of these circuits and projects for your hobby and fun!


Interfacing MQ5 Gas Sensor Module to Arduino using Digital Out Pin

This is pretty simple. Connect the D0 pin of MQ5 module to any digital pin of arduino. Lets connect D0 to pin 7 of arduino. Now we need to give power supply (Vcc) and complete the circuit by connecting to ground (Gnd). Refer the circuit diagram given below. Take a +5V connection from arduino and connect it to Vcc of MQ5 module. Finally connect the GND pin of MQ5 module to GND of arduino. That’s all and we have finished the circuit.

Circuit Diagram of Interfacing MQ5 to Arduino (Digital Out)

Interfacing MQ5 to Arduino Circuit Diagram

Note:- MQ5 sensor has preheating requirement. We advise to keep the sensor powered on (from arduino) for some 15 minutes before applying gas to it.

The Program
int sensor=7;  int gas_value;  void setup()  {    pinMode(sensor,INPUT);  Serial.begin(9600);    }    void loop()  {    gas_value=digitalRead(sensor);  Serial.println(gas_value);  }

Note:- To apply a “gas leak” to MQ5 sensor, you can simply use a cigarette or cigar lighter! Press the trigger switch of cigarette lighter gently (gentle enough so as gas leaks and spark is not triggered) to get gas leaked continuously and place the lighter near MQ5 sensor.

Image Source

Image Source

Output Screenshots!

The screenshots below shows serial monitor readings of arduino before applying gas leak and after applying gas leak. Before applying gas leak, MQ5 captures atmospheric air concentration only (we get a HIGH in our digital out pin and is measured by arduino as 1, as shown in serial monitor).

Interface Mq5 with Arduino using D0 or Digital Out pin of MQ5

When we apply a “gas leak”, the heating element inside MQ5 gets heated up and output voltage varies (we get a LOW in our D0 pin and is measured by arduino as 0, as shown in serial monitor output screenshot )


Interfacing MQ5 Gas Sensor Module to Arduino using Analog Out Pin

The connections are very simple, just like we interfaced MQ5 using digital out pin. In this method, instead of DO, connect analog out pin AO of MQ5 to any of the arduino analog pins. In this tutorial, we are connecting analog out pin of MQ5 to A0 pin of Arduino. Connect Vcc and Ground properly as shown in circuit diagram and we are finished wiring part. Now there’s a little change in the program part. Instead of digitalRead, we need analogRead command of arduino to read sensor values. Output values are also different, instead of 0 and 1 we have a series of integer values ranging from 0 to 1023 (Arduino boards has a 10 bit ADC)

Circuit Diagram – MQ5 to Arduino (Analog Out)

Connecting MQ5 to Arduino

The Program
float sensor=A0;  float gas_value;  void setup()  {    pinMode(sensor,INPUT);  Serial.begin(9600);    }    void loop()  {    gas_value=analogRead(sensor);  Serial.println(gas_value);  }
Output screenshots!

The outputs as seen in serial monitor of arduino are given below. Let’s first see the default output values (when no gas leak is applied) where MQ5 senses atmospheric air concentration only.


Okay! Now let’s apply some “gas leak” by pressing the switch of a cigar lighter gently! You can see the output value is in the range of 800+ as opposed to very low values (in the range of 40’s) when there is no gas leak.


We have seen the sensor reading in different states – in digital out mode and in analog out mode. We know the sensor reading in different conditions for both output modes- i.e – when there is no gas leak and when there is gas leak. With these understandings in mind, we can now go ahead and create a Gas Leakage Detection System using Arduino.

If you are interested in doing other arduino based projects, do check out our Big List of Arduino Projects – listing 100+ different arduino projects!

If you have any doubts, please ask in comments section!