Subscribe to Arduino Academy and start learning today for FREE!

Gas Sensor Tutorial

We just received a bunch of MQ Series Gas Sensors. These inexpensive sensors include: MQ2 – Flammable Gas & Smoke MQ3 – Alcohol MQ4 – Methane MQ5 – LPG / Natural Gas MQ6 – LPG / IsoButane / Propane MQ7 – Carbon Monoxide MQ9 – Carbon Monoxide & Flammable Gas

Today’s project is a smoke detector that turns on an LED when smoke concentrations exceed a certain level.  We soldered the sensor to the carrier board, along with a sensitivity resistor and a 3 pin header. The carrier board pins are VCC (+5v), GND, and Out, which connects to A0 on our Arduino. We connected a LED to Pin 13 and Gnd as indication of an alarm state (smoke detected). See the video and the code we used: Next step is a temp sensor for heat detection, and a relay for a siren.

Become the Maker you were born to be. Try Arduino Academy for FREE!

// These constants won't change.  They're used to give names
// to the pins used:
const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
const int ledPin = 13;                 // LED connected to digital pin 13

int sensorValue = 0; // value read from the sensor

void setup() {
// initialize serial communications at 9600 bps:
pinMode(ledPin, OUTPUT); // sets the digital pin as output

void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// determine alarm status
if (sensorValue >= 750)
digitalWrite(ledPin, HIGH); // sets the LED on
digitalWrite(ledPin, LOW); // sets the LED off

// print the results to the serial monitor:
Serial.print(“sensor = “ );

// wait 10 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:

Become the Maker you were born to be. Try Arduino Academy for FREE!



Notify of
Inline Feedbacks
View all comments
Ida Refsgaard
3 years ago

You can use this tutorial to read values from all MQ gas sensors (MQ-2, MQ-3, MQ-4, MQ-5, MQ-6, MQ-7, etc) I hope you liked this, let me know in the comments. There will be more of them, so make sure to click Follow button!

4 years ago

Thnq for sharing Good Info Fixed Gas Detector designed for detection of the most common gases in commercial and light industrial applications.

11 years ago

Hey. Great post. Just testing this sensor right now. I was wondering if you have calibrated the sensor as documented in the datasheet? If so, which equipment did you use?

Steve Spence
11 years ago

No, I did not calibrate it. I was just shooting for a confirmation that smoke existed.

Bhuwnesh Joshi
11 years ago

what is the value for resistor R1 Shown in diagram Above .Thank you in advance

Jasmin Patel
10 years ago

hey how did you solder the sensor on the breakout board because i am confuse between six pins.

Porn??? Tidak.....???
10 years ago

i want to ask, if i want use buzzer and fan can i get the source code? i need your help..
send to my email,

10 years ago

Hi, Great post.

Did you get the MQ7 to work?

Would you mind telling us how you connected the sensor especially with the PWM part for the heating coil?

Thank you so much!

Tarun kumar
10 years ago

hey am having MQ-2 gas sensor with 6 pins wat to do…..
can we make this experiment without using arduino

Steve Spence
10 years ago

The data sheet explains the pins.

Yes, you need the Arduino.

Jeff Verive
Jeff Verive
2 years ago
Reply to  Steve Spence

Do you really need an Arduino or other microcontroller-based module? A comparator should work just as well.

jose jr. lacanaria
10 years ago

can you plz share us how to make the fire alam with fire senzor using arduino

Steve Spence
10 years ago

Just connect a 5v piezo instead of the LED.

6 years ago

hi i have MQ2 sensor i need to display results of all parametrs like LPG,propane,butane ,methane, alcohol at a time can pls help me

Steve Spence
6 years ago

you would need several sensors, each calibrated for a specific gas. These sensors aren't that discriminating.

soard raspi
6 years ago

What should be the value of R1 in the schematic? Is it a constant value or a variable? If variable, then in what range?

Thank you.

Steve Spence
6 years ago

Depends on the sensor. See the sensor datasheet for your particular application.

Steve Spence
6 years ago

Depends on the sensor. Please review the data sheet for your particular sensor.


Would love your thoughts, please comment.x