Learn ESP32, ESP8266, Arduino, and Raspberry Pi

MQ2 Gas/Smoke Sensor and LCD1602 I2C module

We will learn how to use MQ2 Gas Sensor Module with Arduino board and LCD1602 I2C module. If you are planning on creating an indoor air quality monitoring system; breath checker or early fire detection system, MQ2 Gas Sensor Module is a great choice.

Tag: Project 121b MQ2 Gas/Smoke Sensor and LCD1602 I2C module.

Project resources

Sketch: sketch;


  • We used the Liquid Cristal library. It’s included in Arduino IDE.
  • We used the Wire library. It’s included in Arduino IDE.

Other attachments: None.

Parts required

In this project, you needed these parts (Dear visitors. You can support our project buy clicking on the links of parts and buying them or donate us to keep this website alive. Thank you):

1. MQ2 Gas/Smoke sensor 1 pc

MQ2 sensor

2. Jumper cables  F-M 7 pcs, jumper cables M-M 3 pcs, jumper cables F-F 2 pcs

jumper cables

3. Arduino Nano and Mini-B USB cable 1 pc


4. Resistor 220 Ohm 1 pc

resistor 220 ohm

5. Piezo (buzzer) 1 pc

piezo buzzer

6. LCD 1602 I2C module 1 pc

LCD1602 I2C module

7. Breadboard 1 pc


Understanding the MQ2 Gas sensor module

You can read more about it here.

Understanding LCD 1602 I2C module

The meaning of LCD1602 marking is Liquid Cristal Display 16 characters by 2 rows, each row displays 16 characters of either 5×7 or 5×8 dot matrix characters.The LCD is available in a 16 pin package. It consists of back light and contrast adjustment function and each dot matrix has 5×8 dot resolution.

As we all know, though LCD and some other displays greatly enrich the man-machine interaction, they share a common weakness. When they are connected to a controller, multiple IOs will be occupied of the controller which has no so many outer ports. Also it restricts other functions of the controller. Therefore, LCD1602 with an I2C bus is developed to solve the problem.I2C bus is a type of serial bus invented by PHILIPS. It is a high performance serial bus which has bus ruling and high or low speed device synchronization function required by multiple-host system. The blue potentiometer on the I2C LCD1602 is used to adjust the backlight  for better display. I²C uses only two bidirectional open-drain lines, Serial Data Line (SDA) and Serial Clock Line (SCL), pulled up with resistors. Typical voltages used are +5 V or +3.3 V although systems with other voltages are permitted.

Datasheet can be found here.

Understanding the Arduino Nano

You can read more about it here.

Signals and connections of LCD 1602 I2C module

Signals and contacts of LCD 1602 I2C module

As you can see on the back of LCD 1602 module there 4 connections:

  • GND – ground pin. Connect it to the GND pin of the Arduino board.
  • VCC – power supply pin. Connect it to the 5V pin of the Arduino board.
  • SDA – Serial Data Line pin. Connect it to the SDA pin or analog input pin A4 of the Arduino board.
  • SCL – Serial Clock Line pin. Connect it to the SCL pin or analog input pin A5 of the Arduino Board.

Signals and connections of the MQ2 gas sensor

Signals and connections of the MQ2 gas sensor
  • VCC – supply pin. Supplies power for the module. Connect it to 5V pin of your Arduino board.
  • GND – ground pin. Connected to GND pin on Arduino board.
  • DO – digital output pin. Provides a digital representation (0 or 1) of the presence of combustible gases.
  • AO – analog output pin. Provides analog output voltage 0-5V in proportional to the concentration of smoke/gas.

Sensor pins:

1H -PinsOut of the two H pins, one pin is connected to supply and the other to ground
2A-PinsThe A pins and B pins are interchangeable. These pins will be tied to the Supply voltage.
3B-PinsThe A pins and B pins are interchangeable.   One pin will act as output while the other will be pulled to ground.

Signals and connections of the Arduino Nano

You can read more about it here.


Wiring of MQ2 sensor and LCD1602 I2C module
Wiring LCD1602 I2C module and MQ2 gas sensor module
LCD1602 I2C moduleArduino board
MQ2 gas sensor moduleArduino board
PiezoArduino board

Step by Step instruction

  1. First mount the sensor to a breadboard.
  2. Do wiring.
  3. Open Arduino IDE.
  4. Plug your Arduino Nano board into your PC and select the correct board and com port
  5. Verify and upload sketch to your Arduino Nano.
  6. The MQ2 gas sensor module will warm up for about 20 minutes first.
  7. When the threshold value (in our case it is 300, you can adjust it in sensorLimit variable)will be breached you will get the alarm and see the concentration of the smoke in ppm on LCD screen.


You can adjust the variable sensorLimit with a different threshold value.

Wrapping up

We have learnt about the MQ2 gas sensor module and how to use it with LCD1602 module and Arduino Nano.

Check for more DIY projects here.

Thank you for reading and supporting us.

Check for more DIY projects on and!

If you are looking for high quality PCBs PCBWay is the best choice: