Arduino UNO Q - Gas Sensor
The MQ2 gas sensor detects LPG, smoke, alcohol, propane, hydrogen, methane, and carbon monoxide. It outputs a digital signal (gas/no gas) and an analog signal (gas concentration level). With Bridge and Telegram, your Arduino UNO Q can send instant gas leak alerts to your phone.
In this tutorial, you will learn:
- How the MQ2 gas sensor works and why it needs a warm-up period
- How to wire the MQ2 to the Arduino UNO Q MCU
- How to read both the digital (DO) and analog (AO) outputs
- How to use Bridge to expose gas state and events to the Linux side (Python)
- How to receive urgent Telegram gas leak alerts from Arduino UNO Q
- How to use OpenClaw on Arduino UNO Q with the gas sensor

※ NOTE THAT:
Use the gas sensor for early warning only. Always pair it with proper gas detectors, ventilation, and safety equipment. Never rely on this sensor alone for life-safety applications.
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of the MQ2 Gas Sensor
The MQ2 can detect: LPG, smoke, alcohol, propane, hydrogen, methane, and carbon monoxide. It does not distinguish individual gases — it measures overall flammable/harmful gas levels.

Pinout
- VCC pin: 5V power supply (the internal heating element requires 5V)
- GND pin: Ground
- DO pin: Digital output — HIGH = no gas, LOW = gas detected. Sensitivity is adjusted by the onboard potentiometer.
- AO pin: Analog output — higher value = more gas concentration
LED Indicators
- PWR-LED: Power indicator
- DO-LED: Lights up when gas is detected (DO pin LOW)
Warm-Up Requirement
The MQ2 has an internal heater that must reach operating temperature before accurate readings:
- First use after a long pause (>1 month): Warm up for 24–48 hours
- Normal use: 5–10 minutes warm-up; initial readings may be high but will stabilize
The code includes a 20-second warm-up delay in setup() as a minimum. Power the sensor and wait before trusting the readings.
※ NOTE THAT:
The MQ2 AO pin can output up to ~5V when powered from 5V. The Arduino UNO Q MCU's ADC reference is 3.3V — voltages above 3.3V will saturate the ADC at 4095. Use the DO pin as the primary gas detection method and AO for relative intensity only.
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
| MQ2 Gas Sensor Pin | Arduino UNO Q MCU |
|---|---|
| VCC | 5V |
| GND | GND |
| DO | D2 |
| AO | A0 |
How To Program For Gas Sensor
- Configure the DO pin as a digital input:
- Read both outputs:
- Check for gas from digital output:
Arduino UNO Q Code
The Arduino UNO Q has two processors working together:
- The STM32 MCU warms up the sensor for 20 seconds, then reads both DO and AO every 500 ms
- The Qualcomm MPU runs Debian Linux with Wi-Fi — in this section, only the MCU is programmed. A later section shows how both processors work together via Bridge.
Detailed Instructions
First time with Arduino UNO Q? Follow the Getting Started with Arduino UNO Q tutorial before proceeding.
- Connect: Wire the MQ2 gas sensor to the Arduino UNO Q MCU as shown in the wiring diagram.
- Open Arduino App Lab: Launch Arduino App Lab and wait until it detects your Arduino UNO Q.
- Create a new App: Click the Create New App button.

- Give the App a name, for example: GasSensor
- Click Create to confirm.

- Paste the sketch: Copy the MCU code above and paste it into sketch/sketch.ino.
- Upload: Click the Run button in Arduino App Lab.

- Wait for the 20-second warm-up message to finish in the Serial Monitor.
- Carefully expose the sensor to a small amount of gas (e.g., hold a lighter near it without igniting it) — observe the Serial Monitor output.
- Adjust the potentiometer if the DO LED does not respond.
App Lab Console Output
Bridge: Linux + MCU
This section shows how to program both processors of the Arduino UNO Q so the Linux side can read gas state and receive gas events via Bridge:
- The gas sensor is connected to the MCU — the MCU warms up for 20 seconds, then reads DO and AO every 500 ms
- The MPU cannot read the sensor pins directly — it calls Bridge functions to get state, intensity value, or events
- The MPU has Wi-Fi — running full Debian Linux, it can send urgent Telegram gas alerts the moment gas is detected
- Arduino_RouterBridge enables RPC communication between the two processors
- ⚠️ /dev/ttyHS1 (Linux) and Serial1 (MCU) are RESERVED by the router — never open them in user code
MCU Code (Bridge)
Python Code (Bridge)
Detailed Instructions
- Connect: Wire the MQ2 gas sensor to the Arduino UNO Q as shown in the wiring diagram.
- Open Arduino App Lab and create a new App named GasSensorBridge.
- Paste the MCU sketch into sketch/sketch.ino.
- Paste the Python code into the Python file.
- Install the library: Click the Add sketch library button (the open book icon with a + sign) in the left sidebar.

- Search for Arduino_RouterBridge created by Arduino and click the Install button.
- Upload: Click the Run button. Wait for the warm-up period to finish.

- Expose the sensor to gas — observe the event appear in both consoles.
App Lab Console Output
Telegram
Receive instant Telegram gas leak alerts from the Arduino UNO Q gas sensor, and query air quality remotely.
MCU sketch: Keep the same MCU sketch from the previous Bridge section.
Python Code (Telegram)
Detailed Instructions
- Replace YOUR_TELEGRAM_BOT_TOKEN with your actual bot token from BotFather.
- Replace YOUR_CHAT_ID with your Telegram chat ID.
- Paste this Python code into your App's Python file (keep the same MCU sketch).
- Click the Run button — wait for warm-up, then expose the sensor to gas to trigger the Telegram alert.
App Lab Console Output
ArduinoBot
OpenClaw
...OPENCLAW
OpenClaw support for Arduino UNO Q Gas Sensor is coming soon.
...OPENCLAW
Project Ideas
You can build many useful projects with the MQ2 gas sensor and Arduino UNO Q:
- Home Gas Leak Alarm: Install in your kitchen near the stove — when gas is detected, the MPU sends an urgent Telegram alert with intensity value and also triggers an audible alarm via relay
- Ventilation Controller: Combine the gas sensor with a relay-controlled fan — when gas AO exceeds a threshold, the MCU automatically turns the fan on, and Python sends a Telegram notification
- Air Quality Logger: Log gas state and AO values every minute to a CSV file on Linux — send a daily Telegram summary of air quality events and peak readings
- Garage Carbon Monoxide Monitor: Place the sensor in a garage — receive a Telegram alert when the car engine leaves CO in the air, with automatic alert cleared when AO drops back to baseline
- Multi-Gas Safety System: Combine the gas sensor with the flame sensor tutorial — if both detect danger simultaneously, send a "GAS + FIRE" Telegram alert for maximum urgency
Challenge Yourself
Ready to go further with the MQ2 gas sensor on Arduino UNO Q? Try these challenges:
- Easy: Add a /history Telegram command that returns the last 5 gas detection events with timestamps and AO intensity values stored in a Python list.
- Medium: Implement a false-alarm filter: gas must be detected for at least 3 consecutive readings (1.5 seconds) before the MPU sends a Telegram alert — this prevents single-reading spikes from triggering false alarms.
- Advanced: Build a gas intensity trend monitor: track the last 20 AO readings in Python — if the average of the most recent 10 readings is 50% higher than the average of the previous 10, send a "Gas concentration rising" Telegram alert even before the DO pin triggers.