Random Nerd Tutorials
Shares

Guide for MQ-2 Gas/Smoke Sensor with Arduino

Shares

This guide shows how to build a smoke detector that beeps when it detects flammable gas or smoke.

The MQ-2 Gas Sensor

The MQ-2 smoke sensor is the one in the following figure:

smoke sensor r

The MQ-2 smoke sensor is sensitive to smoke and to the following flammable gases:

  • LPG
  • Butane
  • Propane
  • Methane
  • Alcohol
  • Hydrogen

The resistance of the sensor is different depending on the type of the gas.

The smoke sensor has a built-in potentiometer that allows you to adjust the sensor digital output (D0) threshold. This threshold sets the value above which the digital pin will output a HIGH signal.

smoke sensor label

How does it work?

The voltage that the sensor outputs changes accordingly to the smoke/gas level that exists in the atmosphere. The sensor outputs a voltage that is proportional to the concentration of smoke/gas.

In other words, the relationship between voltage and gas concentration is the following:

  • The greater the gas concentration, the greater the output voltage
  • The lower the gas concentration, the lower the output voltagesmokepicture

The output can be an analog signal (A0) that can be read with an analog input of the Arduino or a digital output (D0) that can be read with a digital input of the Arduino.

Pin Wiring

The MQ-2 sensor has 4 pins.

Pin Wiring to Arduino Uno
A0 Analog pins
D0 Digital pins
GND GND
VCC 5V

Example: Gas Sensor with Arduino

In this example, you will read the sensor analog output voltage and when the smoke reaches a certain level, it will make sound a buzzer and a red LED will turn on.

When the output voltage is below  that level, a green LED will be on.

Parts needed:

So, for this example, you’ll need:

DSC08397

Schematics

Follow these schematics to complete the project:

circuit

Code

Upload the following sketch to your Arduino board (feel free to adjust the variable sensorThres with a different threshold value):

Video demonstration

Watch this quick video demonstration to see this project in action:


I hope you found this guide useful.

Share this post with a friend that also likes electronics!

You can contact me by leaving a comment. If you like this post probably you might like my next ones (click here to subscribe my blog).

Thanks for reading,

-Rui Santos

Recommended Resources

Home Automation using ESP8266 »
Build IoT projects and home automation gadgets with the ESP8266 Wi-Fi module.

Build a Home Automation System »
Learn how to build a automation system using open-source hardware and software from scratch.

Arduino Step-by-Step Projects »
Build 25 cool Arduino projects with our couse even with no prior experience!

Leave a Comment:

Add Your Reply

⏰ Early Black Friday 2017 Special ⏰
Download all our courses up to 35% off