5V
5V
150mA
300-10,000 ppm
0.5-5V (analog output)
10-30 seconds
-20C to 50C
30-90% RH
Tin dioxide (SnO2)
32 x 22 x 18 mm (L x W x H)
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.
MQ-4 Natural Gas Sensor Module for Methane (CNG) Gas DetectorOverviewThe 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.PinoutThe 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 CharacteristicsOperating 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% RHCode Examples### Example 1: Basic Digital Output Example using ArduinoIn 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 alarmvoid 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 timeGPIO.setmode(GPIO.BCM)gasSensorPin = 17 # Analog output pin of the MQ-4 sensor moduleGPIO.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 concentrationwhile 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-FiIn 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.