Stufin
Home Quick Cart Profile

MQ-4 Natural Gas sensor For Methane(CNG) gas Detector Module

Buy Now on Stufin

Operating Voltage

5V

Operating Current

150mA

Detection Range

300-10,000 ppm

Sensitivity

0.5-5V (analog output)

Response Time

10-30 seconds

Operating Temperature

-20C to 50C

Operating Humidity

30-90% RH

Sensor Material

Tin dioxide (SnO2)

Dimensions

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

Weight

20g

Applications

The MQ-4 Natural Gas Sensor is suitable for a wide range of applications, including

Industrial gas detection

Commercial kitchen gas detection

Residential gas leak detection

Environmental monitoring

Gas alarm systems

IoT-based gas detection systems

Precautions

Avoid exposing the sensor to direct sunlight, high humidity, or extreme temperatures.

Keep the sensor away from corrosive substances and chemicals.

Handle the sensor module with care to avoid physical damage.

By following proper usage guidelines and precautions, the MQ-4 Natural Gas Sensor can provide accurate and reliable gas detection in a variety of applications.

Pin Configuration

  • MQ-4 Natural Gas Sensor Module for Methane (CNG) Gas Detector
  • The MQ-4 Natural Gas Sensor Module is a widely used gas sensor module designed to detect methane (CNG) gas. It is a versatile module suitable for various applications, such as gas leak detection, industrial automation, and IoT projects. This documentation provides a comprehensive overview of the module's pinouts and connection guidelines.
  • Pin Description:
  • The MQ-4 Natural Gas Sensor Module has a total of 6 pins, which are as follows:
  • 1. VCC
  • Pin: 1
  • Description: Power supply pin for the module. Connect to a +5V power source.
  • 2. GND
  • Pin: 2
  • Description: Ground pin for the module. Connect to the negative terminal of the power source or the system's ground.
  • 3. OUT
  • Pin: 3
  • Description: Analog output pin. Provides a varying voltage signal proportional to the concentration of methane gas. Connect to an analog-to-digital converter (ADC) or a microcontroller's analog input pin.
  • 4. DOUT
  • Pin: 4
  • Description: Digital output pin. Provides a digital signal (HIGH or LOW) indicating the presence or absence of methane gas. Connect to a digital input pin of a microcontroller or a logic gate.
  • 5. AOUT
  • Pin: 5 (optional)
  • Description: Additional analog output pin. Provides a duplicate of the analog output signal from pin 3. Can be used for connecting multiple devices or for redundancy.
  • 6. H
  • Pin: 6
  • Description: Heater pin. Connect to a +5V power source to activate the internal heater, which enhances the sensor's sensitivity and accuracy.
  • Connection Guidelines:
  • 1. Power Supply:
  • Connect the VCC pin (1) to a +5V power source.
  • Connect the GND pin (2) to the negative terminal of the power source or the system's ground.
  • 2. Analog Output:
  • Connect the OUT pin (3) to an analog-to-digital converter (ADC) or a microcontroller's analog input pin.
  • 3. Digital Output:
  • Connect the DOUT pin (4) to a digital input pin of a microcontroller or a logic gate.
  • 4. Heater Connection:
  • Connect the H pin (6) to a +5V power source to activate the internal heater.
  • 5. Additional Analog Output (Optional):
  • Connect the AOUT pin (5) to an analog-to-digital converter (ADC) or a microcontroller's analog input pin, if required.
  • Important Notes:
  • Ensure proper power supply and grounding to prevent damage to the module.
  • Handle the module with care, as it is sensitive to environmental factors such as temperature and humidity.
  • The MQ-4 sensor has a built-in potentiometer to adjust the sensitivity of the sensor. Adjust the potentiometer according to your specific application requirements.
  • For improved accuracy, calibrate the sensor module before use.
  • By following these connection guidelines and pin descriptions, you can successfully integrate the MQ-4 Natural Gas Sensor Module into your IoT project or application.

Code Examples

MQ-4 Natural Gas Sensor Module for Methane (CNG) Gas Detector
Overview
The MQ-4 Natural Gas Sensor Module is a highly sensitive and reliable gas detector designed to detect methane (CNG) and other combustible gases. This module is based on the MQ-4 gas sensor, which has a high sensitivity to methane and a low sensitivity to other gases. The module is widely used in various applications, including gas leak detection, industrial process control, and home security systems.
Pinout
The MQ-4 Natural Gas Sensor Module has the following pinout:
VCC: 5V power supply
 GND: Ground
 DO: Digital output (TTL level)
 AO: Analog output (0-5V)
Operating Characteristics
Operating Voltage: 5V
 Operating Current: 150mA
 Sensing Gas: Methane (CNG) and other combustible gases
 Detection Range: 300-10,000 ppm
 Response Time: 10-30 seconds
 Temperature Range: -20C to 50C
 Humidity Range: 30-90% RH
Code Examples
### Example 1: Basic Digital Output Example using Arduino
In this example, we will use the MQ-4 Natural Gas Sensor Module with an Arduino board to detect the presence of methane gas and trigger an alarm when the gas concentration exceeds a certain threshold.
```cpp
const int gasSensorPin = 2;  // Digital output pin of the MQ-4 sensor module
const int alarmPin = 13;     // Output pin for the alarm
void setup() {
  pinMode(gasSensorPin, INPUT);
  pinMode(alarmPin, OUTPUT);
}
void loop() {
  int sensorValue = digitalRead(gasSensorPin);
  if (sensorValue == HIGH) {
    digitalWrite(alarmPin, HIGH);  // Turn on the alarm
  } else {
    digitalWrite(alarmPin, LOW);  // Turn off the alarm
  }
  delay(1000);
}
```
### Example 2: Analog Output Example using Raspberry Pi (Python)
In this example, we will use the MQ-4 Natural Gas Sensor Module with a Raspberry Pi board to read the analog output voltage and convert it to a gas concentration value.
```python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
gasSensorPin = 17  # Analog output pin of the MQ-4 sensor module
GPIO.setup(gasSensorPin, GPIO.IN)
def read_gas_concentration():
  voltage = GPIO.input(gasSensorPin)  5.0 / 1023.0
  concentration = voltage  1000.0 / 5.0  # Assuming a linear response
  return concentration
while True:
  concentration = read_gas_concentration()
  print("Gas Concentration: {:.2f} ppm".format(concentration))
  time.sleep(1)
```
### Example 3: IoT-Based Gas Leak Detection System using ESP32 and Wi-Fi
In this example, we will use the MQ-4 Natural Gas Sensor Module with an ESP32 board to detect gas leaks and send notifications to a remote server or mobile app using Wi-Fi.
```cpp
#include <WiFi.h>
#include <HTTPClient.h>
const char ssid = "your_wifi_ssid";
const char password = "your_wifi_password";
const char serverUrl = "https://your-remote-server.com/gas-leak-notification";
WiFiClient client;
HTTPClient http;
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 gas sensor...");
}
void loop() {
  int sensorValue = analogRead(A0);  // Analog output pin of the MQ-4 sensor module
  float concentration = sensorValue  5.0 / 1023.0  1000.0 / 5.0;
  if (concentration > 500) {
    Serial.println("Gas leak detected!");
    http.begin(client, serverUrl);
    http.addHeader("Content-Type", "application/json");
    int httpResponseCode = http.POST("{""gas_concentration"": " + String(concentration) + "}");
    http.end();
  }
  delay(1000);
}
```
Note: These code examples are for illustration purposes only and may require modifications to suit your specific application. Ensure proper calibration and testing of the MQ-4 Natural Gas Sensor Module before use in a real-world application.