How to Code Arduino and MQ-2 Gas Sensor?

Ravindra Rana
2 min readMay 16, 2020

MQ — 2 is one of the Gas Sensors, is capable of sensing the value of LPG, Propane, Hydrogen, CO, Alcohol, and Methane.

It is one of the most used sensors in the Arduino project for sensing data from these gas.

So in this project, we are going to use the MQ2 Gas Sensor to fetch the analog value from pin A0.

Pin Diagram of MQ-2 Gas Sensor

Image source: components101.com/mq2-gas-sensor

3 Steps then see the Magic

Step 1: Setup

This first step if you have not set up Arduino IDE then install and setup. Follow the link to set up.

Step 2: Code

Setup 3: Wiring

To develop this project you should need some components, the required components are:

  • Arduino Uno
  • MQ2
  • Buzzer
  • LEDs
  • Jumper Wire
  • Breadboard

Conclusion

MQ2 Gas Sensor is capable of sensing gases like LPG, Propane, Hydrogen, CO, Alcohol, and Methane. But in this project, we are testing the LPG from analog Pin A0.

Image by Ayush Shakya from Pixabay

--

--