Table of Contents
Example Description
Learn how to interface an MQ sensor with Arduino to detect multiple gases like CO2, LPG, and more.
introduction

The MQ series of sensors offers a diverse range of gas detectors used for detecting multiple gases like CO2, LPG, and more. These sensors have numerous applications, from detecting smoke caused by fires in buildings to identifying gas leaks and natural gases in mining operations.

Buy MQ-137 NH3 Gas Sensor Module Online in India | Robocraze

In this example, we will interface an MQ sensor with Arduino to detect gas levels above a certain threshold. When the gas levels surpass the set limit, Arduino will trigger a buzzer alarm. Let’s delve into the exciting world of gas detection using Arduino!

Circuit

connection

Sensor                                Arduino

VCC                                        5V

GND                                      GND

A0                                           A0

buzzer+                                   D13

Buzzer-                                    GND

Code

  1. From the event palette, add the “when flag clicked” block into the scripting area.
  2. Add the “forever” block from the controls palette.
  3. Inside the “forever” block, add the “if-else” block from the control palette.
  4. From the operator palette, add the “greater than” operator into the “if” conditional part.
  5. In the first space of the “greater than” operator, use the “read analog sensor () at ()” block from the Arduino sensor palette and insert the MQ sensor value from A0.
  6. In the second space of the “greater than” operator, set a specific value as the threshold for gas detection.

Script.

Output