Gas sensors play a crucial role in safety and environmental monitoring applications. One of the most popular sensors for detecting flammable gases and smoke is the MQ-2 gas sensor. In this blog, we will explore how to interface the MQ-2 gas sensor with an Arduino to detect gases like LPG, methane, hydrogen, and smoke. We will also cover the wiring, coding, and real-time monitoring of gas concentrations using the Serial Monitor in Arduino IDE.
![]() |
MQ-2 gas sensor with Arduino |
What is the MQ-2 Gas Sensor?
The MQ-2 gas sensor is a versatile electronic module designed to detect combustible gases. It has high sensitivity to LPG, propane, hydrogen, methane, carbon monoxide, and even alcohol fumes. The sensor provides both analog and digital outputs, making it easy to integrate with microcontrollers like Arduino.
![]() |
MQ-2 gas sensor specifications |
Components Required
To get started, you will need the following components:
![]() |
Components required for this tutorial |
✅ Arduino UNO board
✅ MQ-2 Gas Sensor Module
✅ Jumper Wires
✅ USB cable for Arduino
Components Required
Follow this simple connection guide:
![]() |
Connection MQ-2 gas sensor |
![]() |
The connection between the MQ-2 gas sensor and Arduino |
![]() |
Wiring diagram |
✅VCC → 5V (Arduino)
✅GND → GND (Arduino)
✅A0 → A0 (Arduino) (for analog readings)
✅D0 (Digital Output, optional) → Any digital pin on Arduino (not used in this example)
Components Required
Using the Arduino IDE, upload the following Arduino sketch to read sensor values and display them on the Serial Monitor or you can download the code HERE.
const int sensorPin = A0; // Analog pin connected to MQ-2 int sensorValue = 0; // Variable to store sensor readings void setup() { Serial.begin(9600); // Start serial communication } void loop() { sensorValue = analogRead(sensorPin); // Read gas concentration Serial.print("Gas Sensor Value: "); Serial.println(sensorValue); delay(1000); // Wait for a second before next reading }
![]() |
Open Arduino IDE and copy-paste the code |
Testing the Sensor
After uploading the code to your Arduino, open the Serial Monitor in the Arduino IDE.
![]() |
Introduce a gas source near the sensor and observe the increase in values. |
Conclusion
The MQ-2 gas sensor is a powerful tool for detecting various combustible gases, making it ideal for home safety and industrial applications. By integrating it with an Arduino, you can create a gas leakage detection system that provides real-time monitoring. This simple yet effective project is a great starting point for anyone interested in sensor technology and IoT applications.
Tools and components
Shopee:
Lazada:
Aliexpress:
Video
🔔 If you found this guide helpful, share it with fellow makers! For more tutorials, subscribe to our YouTube channel and follow us on social media. 🚀
#arduino #gassensor #mq2 #arduinoprojects #gasdetector
No comments:
Post a Comment