Chipkit and MQ-4 Methane Gas Sensor example

The MQ-4 Methane Gas Sensor is a gas sensor that detects the presence of methane gas at concentrations from 200 ppm to 10,000 ppm, a range suitable for detecting gas leaks. The sensor’s simple analog voltage interface requires only one analog input pin from your microcontroller.

The MQ-4 Methane Gas Sensor detects the concentration of methane gas in the air and ouputs its reading as an analog voltage. The concentration sensing range of 200 ppm to 10,000 ppm is suitable for leak detection. For example, the sensor could detect if someone left a gas stove on but not lit. The sensor can operate at temperatures from -10 to 50°C and consumes less than 150 mA at 5 V.

Connections

Connecting 3.3 volts across the heating (H) pins keeps the sensor hot enough to function correctly. Connecting 3.3 volts at either the A or B pins causes the sensor to emit an analog voltage on the other pins. A resistive load between the output pins and ground sets the sensitivity of the detector.The resistive load should be calibrated for your particular application using the equations in the datasheet, but a good starting value for the resistor is 20 kΩ.

 

mq-4

 

Features

  • High sensitivity to CH4 and Natural gas
  • Slight sensitivity to alcohol, smoke
  • Fast response
  • Stable and long life
  • Simple drive circuit

Connection is a easy as this with a module like the picture below

VCC - 3v3
GND - GND
A0  - Analog pin0
D0  - Not connected

Code

The code is quite simple and good for a quick example but note that because these type’s of sensors require the heater inside them to heat up then they should actually be left powered up for a period of time, I have seen numbers from 2 minutes to over 1 hour quoted

void setup() 
{
  Serial.begin(9600);
}
 
void loop() 
{
  float sensorVoltage; 
  float sensorValue;
 
  sensorValue = analogRead(A0);
  sensorVoltage = sensorValue/1024*3.3;
 
  Serial.print("sensor voltage = ");
  Serial.print(sensorVoltage);
  Serial.println(" V");
  delay(1000);
}

 

Results

Again via the serial monitor

sensor voltage = 0.22 V
sensor voltage = 0.22 V
sensor voltage = 0.22 V
sensor voltage = 0.23 V
sensor voltage = 0.23 V
sensor voltage = 0.23 V
sensor voltage = 0.24 V

 

Links

Mq-4 datasheet
MQ4 Methane Gas Sensor

Share