Stufin
Home Quick Cart Profile

MQ-2 Gas Sensor Module For H2, LPG, CH4, CO, Smoke or Propane Detector Module ( Pack of 25)

Buy Now on Stufin

Sensor Type

Metal Oxide Semiconductor (MOS)

Detection Range

100-10000 ppm (dependent on gas type)

Output Type

Analog

Operating Voltage

5V

Operating Temperature

-20C to 50C

Response Time

<10 seconds

Dimensions

32mm x 22mm x 14mm (L x W x H)

Application Areas

The MQ-2 Gas Sensor Module is suitable for a wide range of applications, including

Home and industrial safety systems

Gas leak detection systems

Environmental monitoring systems

IoT projects and prototypes

Industrial automation and control systems

Smart home automation systems

Conclusion

The MQ-2 Gas Sensor Module is a highly sensitive and versatile detection module that offers a cost-effective solution for detecting a wide range of combustible gases. Its compact design, easy-to-use interface, and high sensitivity make it an ideal choice for various IoT applications, prototyping, and development projects.

Pin Configuration

  • MQ-2 Gas Sensor Module Documentation
  • The MQ-2 Gas Sensor Module is a versatile and sensitive gas sensor module capable of detecting various gases such as H2, LPG, CH4, CO, smoke, and propane. This module comes in a pack of 25 and is widely used in IoT projects and applications. In this documentation, we will delve into the details of the module's pins and provide a step-by-step guide on how to connect them.
  • Pinouts:
  • The MQ-2 Gas Sensor Module has 5 pins, each with a specific function:
  • 1. VCC (Power Supply):
  • Pin Type: Input
  • Voltage Range: 5V
  • Function: Provides power to the module
  • 2. GND (Ground):
  • Pin Type: Input
  • Voltage Range: 0V
  • Function: Ground connection for the module
  • 3. DOUT (Digital Output):
  • Pin Type: Output
  • Logic Level: TTL (5V)
  • Function: Provides a digital output signal when the detected gas concentration exceeds a certain threshold
  • 4. AOUT (Analog Output):
  • Pin Type: Output
  • Voltage Range: 0-5V
  • Function: Provides an analog output signal proportional to the detected gas concentration
  • 5. HEAT (Heater):
  • Pin Type: Input
  • Voltage Range: 5V
  • Function: Powers the internal heater, which is necessary for the sensor to operate
  • Connecting the Pins:
  • To connect the MQ-2 Gas Sensor Module, follow these steps:
  • Step 1: Power Supply
  • Connect the VCC pin to a 5V power supply (e.g., Arduino's 5V pin or a dedicated 5V power source)
  • Connect the GND pin to a common ground (e.g., Arduino's GND pin or a dedicated ground)
  • Step 2: Digital Output
  • Connect the DOUT pin to a digital input on your microcontroller (e.g., Arduino's digital pin)
  • Note: The DOUT pin provides a TTL-level digital output signal. Ensure your microcontroller can handle this voltage level.
  • Step 3: Analog Output
  • Connect the AOUT pin to an analog input on your microcontroller (e.g., Arduino's analog pin)
  • Note: The AOUT pin provides an analog output voltage between 0V and 5V. Ensure your microcontroller can handle this voltage range.
  • Step 4: Heater Power
  • Connect the HEAT pin to a 5V power supply (e.g., Arduino's 5V pin or a dedicated 5V power source)
  • Note: The HEAT pin requires a 5V power supply to operate the internal heater.
  • Important Considerations:
  • Ensure the power supply voltage is within the recommended range (5V) for the module.
  • Use a suitable voltage regulator or power supply module to regulate the voltage if necessary.
  • Handle the module with care to avoid damaging the sensor or other components.
  • Follow proper safety precautions when working with gas sensors, as they may be sensitive to certain gases and environments.
  • By following these steps and considering the important notes, you can successfully connect and integrate the MQ-2 Gas Sensor Module into your IoT project or application.

Code Examples

MQ-2 Gas Sensor Module Documentation
Overview
The MQ-2 Gas Sensor Module is a highly sensitive gas detection module that can detect various gases, including H2, LPG, CH4, CO, smoke, and propane. This module is suitable for a wide range of applications, from simple gas detection to industrial automation.
Technical Specifications
Supply Voltage: 5V
 Operating Current: 150mA
 Sensitivity: 0.1-10 ppm
 Response Time: 10-60 seconds
 Output Signal: Analog Voltage (0-5V)
 Detection Range:
	+ H2: 100-1000 ppm
	+ LPG: 100-1000 ppm
	+ CH4: 100-1000 ppm
	+ CO: 10-100 ppm
	+ Smoke: 10-100 ppm
	+ Propane: 100-1000 ppm
Pinout
VCC: 5V Power Supply
 GND: Ground
 OUT: Analog Output Signal
Code Examples
### Example 1: Basic Gas Detection with Arduino
This example demonstrates how to use the MQ-2 Gas Sensor Module with an Arduino board to detect the presence of gas.
```c++
const int gasSensorPin = A0;  // Analog input pin for the gas sensor
int sensorValue = 0;
void setup() {
  Serial.begin(9600);
}
void loop() {
  sensorValue = analogRead(gasSensorPin);
  Serial.print("Gas Sensor Value: ");
  Serial.println(sensorValue);
if (sensorValue > 400) {
    Serial.println("Gas Detected!");
  } else {
    Serial.println("No Gas Detected.");
  }
delay(1000);
}
```
In this example, we connect the OUT pin of the MQ-2 Gas Sensor Module to an analog input pin on the Arduino board (A0). We then read the analog value from the sensor using the `analogRead()` function and print it to the serial monitor. If the value exceeds 400, we trigger an alarm by printing "Gas Detected!" to the serial monitor.
### Example 2: Gas Level Monitoring with ESP32 and WiFi
This example demonstrates how to use the MQ-2 Gas Sensor Module with an ESP32 board to monitor gas levels and send the data to a remote server using WiFi.
```c++
#include <WiFi.h>
#include <HTTPClient.h>
const char ssid = "your_wifi_ssid";
const char password = "your_wifi_password";
const char serverUrl = "http://example.com/gas_level";
WiFiClient wifiClient;
HTTPClient http;
int gasSensorPin = 32;  // Digital pin for the gas sensor
int sensorValue = 0;
void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
Serial.println("Connected to WiFi");
  Serial.println("Initializing HTTP client...");
}
void loop() {
  sensorValue = analogRead(gasSensorPin);
  Serial.print("Gas Level: ");
  Serial.println(sensorValue);
http.begin(wifiClient, serverUrl);
  http.addHeader("Content-Type", "application/x-www-form-urlencoded");
String json = "{""gas_level"": " + String(sensorValue) + "}";
  int httpResponseCode = http.POST(json);
if (httpResponseCode > 0) {
    Serial.println("Data sent successfully!");
  } else {
    Serial.println("Error sending data: " + String(http.errorString(httpResponseCode)));
  }
http.end();
  delay(10000);
}
```
In this example, we connect the OUT pin of the MQ-2 Gas Sensor Module to a digital pin on the ESP32 board (32). We then read the analog value from the sensor using the `analogRead()` function and send the data to a remote server using the `HTTPClient` library. The server can then log the gas level data and trigger alarms or notifications as needed.