Skip to main content

Grove - Gas Sensor(MQ3)

pir

The Grove - Gas Sensor(MQ3) module is useful for gas leakage detection (in home and industry). It is suitable for detecting Alcohol, Benzine, CH4, Hexane, LPG, CO. Due to its high sensitivity and fast response time, measurements can be taken as soon as possible. The sensitivity of the sensor can be adjusted by using the potentiometer.

Note

The sensor value only reflects the approximated trend of gas concentration in a permissible error range, it DOES NOT represent the exact gas concentration. The detection of certain components in the air usually requires a more precise and costly instrument, which cannot be done with a single gas sensor. If your project is aimed at obtaining the gas concentration at a very precise level, then we do not recommend this gas sensor.

Sensor

Gas Type

Get One Now

MQ2Combustible Gas, Smoke
MQ3Alcohol Vapor
MQ5LPG, Natural Gas, Town Gas
MQ9Carbon Monoxide, Coal Gas, Liquefied Gas
tip
We've released the [Seeed Gas Sensor Selection Guide](https://wiki.seeedstudio.com/Sensor_gas/), it will help you choose the gas sensor that best suits your needs.

Features

  • High sensitivity to alcohol and small sensitivity to Benzine
  • Stable and long life
  • Fast response and High sensitivity
tip
More details about Grove modules please refer to [Grove System](https://wiki.seeedstudio.com/Grove_System/)

Specification

ItemParameterMinTypicalMaxUnit
VCCWorking Voltage4.955.1V
PHHeating consumption0.5-750mW
RLLoad resistanceadjustable
RHHeater resistance-33-Ω
RsSensing Resistance1-8
ScopeDetecting Concentration0.05-10mg/L

Application

  • Alcohol checker.
  • Breathalyser.
  • Toys.

Hardware Overview

This is an Analog output sensor. This needs to be connected to any one Analog socket in Grove Base Shield. The examples used in this tutorial makes uses of A0 analog pin. Connect this module to the A0 port of Base Shield.

It is possible to connect the Grove module to Arduino directly by using jumper wires by using the connection as shown in the table below:

ArduinoGas Sensor
5VVCC
GNDGND
NCNC
Analog A0SIG

The output voltage from the Gas sensor increases when the concentration of gas increases. Sensitivity can be adjusted by varying the potentiometer. Please note that the best preheat time for the sensor is above 24 hours. For detailed information about the MQ-3 sensor, please refer to the data-sheet provided in Resources section.

Platforms Supported

ArduinoRaspberryArduPy

pir

pir

pir

caution
The platforms mentioned above as supported is/are an indication of the module's software or theoritical compatibility. We only provide software library or code examples for Arduino platform in most cases. It is not possible to provide software library / demo code for all possible MCU platforms. Hence, users have to write their own software library.

Getting Started

Play With Arduino

Seeeduino V4.2Base ShieldGrove - Gas Sensor(MQ3)

pir

pir

pir

Get One NowGet One NowGet One Now

pir

Connect the Grove - Gas Sensor(MQ3) to A0 port as shown in the picture above.

Gas Detection : Basic Example

In this example, the sensor is connected to A0 pin. The voltage read from the sensor is displayed. This value can be used as a threshold to detect any increase/decrease in gas concentration.

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

Measurement : Approximation

This examples demonstrates a way to know the approximate concentration of Gas. As per the data-sheet of the MQ3 sensors, these equations are tested for standard conditions and are not calibrated. It may vary based on change in temperature or humidity.

  1. Keep the Gas Sensor in clean air environment. Upload the program below.
void setup()
{
Serial.begin(9600);
}

void loop()
{
float sensor_volt;
float RS_air; // Get the value of RS via in a clear air
float R0; // Get the value of R0 via in Alcohol
float sensorValue;

/*--- Get a average data by testing 100 times ---*/
for(int x = 0 ; x < 100 ; x++)
{
sensorValue = sensorValue + analogRead(A0);
}
sensorValue = sensorValue/100.0;
/*-----------------------------------------------*/

sensor_volt = sensorValue/1024*5.0;
RS_air = (5.0-sensor_volt)/sensor_volt; // omit *RL
R0 = RS_air/60.0; // The ratio of RS/R0 is 60 in a clear air from Graph (Found using WebPlotDigitizer)

Serial.print("sensor_volt = ");
Serial.print(sensor_volt);
Serial.println("V");

Serial.print("R0 = ");
Serial.println(R0);
delay(1000);

}
  1. Then, open the serial monitor of Arduino IDE. Write down the value of R0 and this needs to be used in the next program. Please node down the R0 after the reading stabilizes.
Replace the R0 below with value of R0 tested above . Expose the sensor to any one of the gas listed above.
void setup() {
Serial.begin(9600);
}

void loop() {

float sensor_volt;
float RS_gas; // Get value of RS in a GAS
float ratio; // Get ratio RS_GAS/RS_air
int sensorValue = analogRead(A0);
sensor_volt=(float)sensorValue/1024*5.0;
RS_gas = (5.0-sensor_volt)/sensor_volt; // omit *RL

/*-Replace the name "R0" with the value of R0 in the demo of First Test -*/
ratio = RS_gas/R0; // ratio = RS/R0
/*-----------------------------------------------------------------------*/

Serial.print("sensor_volt = ");
Serial.println(sensor_volt);
Serial.print("RS_ratio = ");
Serial.println(RS_gas);
Serial.print("Rs/R0 = ");
Serial.println(ratio);

Serial.print("\n\n");

delay(1000);

}

Now, we can get the concentration of gas from the figure below.

pir

According to the figure, we can see that the minimum concentration we can test is 0.1mg/L and the maximum is 10mg/L. However, we can't provide a formula because the relation between ratio and concentration is nonlinear.But also, we can convert mg/L to ppm, it's may convenient for us to watch the value.

Play With Raspberry Pi (With Grove Base Hat for Raspberry Pi)

Hardware

  • Step 1. Things used in this project:
Raspberry piGrove Base Hat for RasPiGrove - Gas Sensor(MQ3)

pir

pir

pir

Get ONE NowGet ONE NowGet ONE Now
  • Step 2. Plug the Grove Base Hat into Raspberry.
  • Step 3. Connect the Grove - Gas Sensor(MQ3) to port A0 of the Base Hat.
  • Step 4. Connect the Raspberry Pi to PC through USB cable.

pir

note
For step 3 you are able to connect the Grove - Gas Sensor(MQ3) to **any Analog Port** but make sure you change the command with the corresponding port number.

Software

  • Step 1. Follow Setting Software to configure the development environment.
  • Step 2. Download the source file by cloning the grove.py library.
cd ~
git clone https://github.com/Seeed-Studio/grove.py

  • Step 3. Excute below commands to write the code.
cd grove.py/grove
nano grove_gas_sensor_mq3.py

Then you should copy following code in this file and hit ++ctrl+x++ to quit and save.

import math
import sys
import time
from grove.adc import ADC


class GroveGasSensorMQ3:

def __init__(self, channel):
self.channel = channel
self.adc = ADC()

@property
def MQ3(self):
value = self.adc.read(self.channel)
return value

Grove = GroveGasSensorMQ3


def main():
if len(sys.argv) < 2:
print('Usage: {} adc_channel'.format(sys.argv[0]))
sys.exit(1)

sensor = GroveGasSensorMQ3(int(sys.argv[1]))

print('Detecting...')
while True:
print('Gas value: {0}'.format(sensor.MQ3))
time.sleep(.3)

if __name__ == '__main__':
main()

  • Step 4. Excute below commands to run code.
python grove_gas_sensor_mq3.py  0
tip
If everything goes well, you will be able to see the following result
pi@raspberrypi:~/grove.py/grove $ python grove_gas_sensor_mq3.py 0
Detecting...
Gas value: 564
Gas value: 564
Gas value: 564
Gas value: 565
Gas value: 565
Gas value: 565
Gas value: 566
Gas value: 566
Gas value: 566
Gas value: 566
Gas value: 566
^CTraceback (most recent call last):
File "grove_gas_sensor_mq3.py", line 69, in <module>
main()
File "grove_gas_sensor_mq3.py", line 66, in main
time.sleep(.3)
KeyboardInterrupt

You can quit this program by simply press ++ctrl+c++.

:::notice You may have noticed that for the analog port, the silkscreen pin number is something like A0, A1, however in the command we use parameter 0 and 1, just the same as digital port. So please make sure you plug the module into the correct port, otherwise there may be pin conflicts. :::

Play With Wio Terminal (ArduPy)

Hardware

  • Step 1. Prepare the below stuffs:
Wio TerminalGrove - Gas Sensor(MQ3)

pir

pir

Get One NowGet One Now
  • Step 2. Connect Grove - Gas Sensor(MQ3) to A0 port of Wio Terminal.

  • Step 3. Connect the Wio Terminal to PC through USB Type-C cable.

pir

Software

  • Step 1. Follow ArduPy Getting Started to configure the ArduPy development environment on Wio Terminal.

  • Step 2. Make sure that the ArduPy firmware is flashed into Wio Terminal. For more information, please follow here.

aip build
aip flash
  • Step 3. Copy the following code and save it as ArduPy-mq3.py:
from machine import Pin, ADC
from machine import LCD
from machine import Sprite
import time

mq3 = ADC(Pin(13))
lcd = LCD()
spr = Sprite(lcd) # Create a buff

def main():
spr.createSprite(320, 240)
while True:
spr.setTextSize(2)
spr.fillSprite(spr.color.BLACK)
spr.setTextColor(lcd.color.BLUE)
spr.drawString("MQ3 Reading", 90, 10)
spr.drawFastHLine(40, 35, 240, lcd.color.DARKGREY)
spr.setTextColor(lcd.color.WHITE)
spr.drawString("- Current Level: ", 20, 50)
spr.drawNumber(mq3.read(), 220,50)
spr.pushSprite(0,0)
time.sleep_ms(500)

print("MQ3 Gas Sensor Reading is: ", mq3.read())

if __name__ == "__main__":
main()
  • Step 4. Save the ArduPy-mq3.py in a location that you know. Run the following command and replace <YourPythonFilePath> with your ArduPy-mq3.py location.
aip shell -n -c "runfile <YourPythonFilePath>"
# Example:
# aip shell -n -c "runfile /Users/ansonhe/Desktop/ArduPy-mq3.py"
  • Step 5. We will see the gas value display on terminal as below, and displaying on the Wio Terminal LCD screen.
ansonhe@Ansons-Macbook-Pro ~:aip shell -n -c "runfile /Users/ansonhe/Desktop/ArduPy-mq3.py"
Positional argument (/dev/cu.usbmodem1413101) takes precedence over --open.
Connected to ardupy
MQ3 Gas Sensor Reading is: 609
MQ3 Gas Sensor Reading is: 611
MQ3 Gas Sensor Reading is: 614
MQ3 Gas Sensor Reading is: 616
MQ3 Gas Sensor Reading is: 618
MQ3 Gas Sensor Reading is: 621
MQ3 Gas Sensor Reading is: 623
MQ3 Gas Sensor Reading is: 625
MQ3 Gas Sensor Reading is: 627
MQ3 Gas Sensor Reading is: 628
MQ3 Gas Sensor Reading is: 629
MQ3 Gas Sensor Reading is: 632

pir

Schematic Online Viewer

Resources

Suggest Reading / References

Schematic

Datasheet

Tech Support

Please submit any technical issue into our forum.

Upgradable to Industrial Sensors

With the SenseCAP S2110 controller and S2100 data logger, you can easily turn the Grove into a LoRaWAN® sensor. Seeed not only helps you with prototyping but also offers you the possibility to expand your project with the SenseCAP series of robust industrial sensors.

The IP66 housing, Bluetooth configuration, compatibility with the global LoRaWAN® network, built-in 19 Ah battery, and powerful support from APP make the SenseCAP S210x the best choice for industrial applications. The series includes sensors for soil moisture, air temperature and humidity, light intensity, CO2, EC, and an 8-in-1 weather station. Try the latest SenseCAP S210x for your next successful industrial project.

Loading Comments...