Recommended Free Tools
Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Important: This Arduino project is an educational prototype for demonstrating combustible-gas and flame detection. It is not a substitute for a listed residential gas detector, smoke alarm, fire alarm, or industrial safety system. For real protection, install an approved detector suitable for the gas and location.
The system combines an MQ-series gas sensor with an optical flame-sensor module. An Arduino reads both inputs, then drives a buzzer and warning LEDs when either sensor crosses its configured threshold. Gas detection can provide an indication before ignition; flame detection can respond after ignition. Neither sensor proves that an area is safe.
As an Amazon Associate I earn from qualifying purchases.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →What this Arduino system does
The prototype monitors two separate hazards:
- Combustible gas: An MQ-2, MQ-5, or MQ-6 module changes its electrical response when exposed to certain gases or vapours.
- Visible flame: A flame module detects optical radiation associated with a flame, commonly in the infrared range.
- Alert output: The Arduino evaluates the readings and activates a buzzer, red LED, display, relay, or optional remote notification.
These sensing methods complement one another. A gas sensor may respond to a leak before ignition, while a flame sensor cannot detect an unignited leak. Conversely, a flame module may react quickly to a flame that produces little measurable gas-sensor change. Both are affected by placement, environment, and hardware quality.
Prototype architecture
MQ gas sensor AO ─────► Arduino analog input
MQ gas sensor DO ─────► Optional Arduino digital input
Flame sensor AO/DO ────► Arduino analog/digital input
Arduino output ────────► Buzzer driver
Arduino output ────────► Red warning LED
Arduino output ────────► Green/status LED
Optional ──────────────► LCD/OLED, GSM, Wi-Fi, or cloud service
An Arduino Uno Rev3 has six analog inputs and 14 digital I/O pins, which is enough for a basic two-sensor demonstration. Its 5 V logic is convenient for many Uno-compatible modules, but every sensor board must still be checked individually.
Popular on Amazon
- MQ-2 gas sensor sensitive material used in the clean air low conductivity tin oxide (SnO2). When there is the environment in which the combustible gas sensor, conductivity sensor with increasing concentration of combustible gases in air increases.
- Quick response and recovery characteristics
- The dual signal output (analog output and TTL output)
- The analog output and increased with the increase of concentration, the higher the concentration higher voltage
- Has a very high sensitivity to sulfide, benzene vapor, smoke and other harmful gases
Choosing the gas sensor
MQ-2: broad educational coverage
The MQ-2 is commonly used for demonstrations involving LPG, propane, butane, methane or natural gas, hydrogen, alcohol vapours, and smoke. It is broad-spectrum rather than selective. A vendor may state a nominal flammable-gas range of approximately 300–10,000 ppm, but that figure is specific to the sensor/module documentation and test conditions—not a universal guarantee for every MQ-2 breakout.
See the Olimex MQ-2 information, RAK12004 product page, and RAK documentation for examples of how specifications vary between modules.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteMQ-6: more targeted to LPG-related projects
Choose an MQ-6 when the demonstration is specifically concerned with LPG, propane, or butane. It is not automatically a certified LPG alarm. Calibration, cross-sensitivity, heater behaviour, environmental drift, and module construction remain limitations.
MQ-5: another LPG and natural-gas option
The MQ-5 is worth considering for projects focused on LPG and natural gas. Check the exact datasheet supplied with the module: inexpensive boards can differ in comparator circuitry, pin labels, heater requirements, and documentation.
When to use something better
For a more serious prototype, choose a sensor platform with a documented interface, calibration data, and a response curve for the target gas. Depending on the application, that could mean a calibrated electrochemical, catalytic-bead, NDIR, or semiconductor platform. For life safety, use a complete listed detector and treat the Arduino as supplemental monitoring only. Gas-sensor breakout manufacturers such as Adafruit explicitly warn that these boards are not intended for safety, medical, or finished-product use.
How the sensors work
MQ sensor
MQ sensors generally use a heated tin-oxide semiconductor sensing element. Exposure to combustible gases changes the element’s electrical characteristics. A typical module provides:
Also popular on Amazon
- Working voltage: DC 5V; With signal output indicator light;
- With a long service life and reliable stability;Quick response and recovery characteristics;
- The analog output and increased with the increase of concentration, the higher the concentration higher voltage
- For harmful gas family, environment detection device, is suitable for the detection of the ammonia, aromatic compounds, sulfide, benzene vapor, smoke and other harmful gas, gas sensitive element concentration range: 10 to 1000ppm provides reference cases.
- Package Includes: MQ-2 Smoke Sensor,MQ-3 Alcohol Sensor,MQ-4 Methane Sensor,MQ-5 LPG Natural Gas City Gas Sensor,MQ-6 isobutane propane sensor,MQ-7 Carbon Monoxide Sensor Module,MQ-8 hydrogen sensor,MQ-9 Carbon Monoxide Combustible Gas Sensor,MQ-135 air quality detection sensor
AO— analog output for a relative sensor response;DO— digital output from an onboard comparator;VCC— supply input; andGND— ground.
The analog value is not inherently a gas percentage or a ppm measurement. It depends on gas composition, sensor resistance, load resistance, heater state, temperature, humidity, airflow, and calibration. The digital output is normally just a comparator decision controlled by a trim potentiometer. It is not a standard safety threshold.
Heater requirements also vary. One MQ-2 listing specifies a 5 V heater and approximately 40 mA for a particular module, while other documentation lists roughly 150–160 mA and about 800 mW. Check the exact board before selecting a power supply. See the module guidance and Makeblock’s MQ-2 notes.
Flame module
A typical flame-sensor board contains an infrared-sensitive photodiode or phototransistor, a comparator such as an LM393, an adjustment potentiometer, and an indicator LED. Some boards expose analog and digital outputs.
It detects optical energy within its field of view; it does not detect gas. Sunlight, incandescent lamps, reflections, hot objects, and other infrared sources can cause false positives. Distance and viewing angle vary by module. A small, distant, blue, shielded, or oxygen-starved flame may produce a weak signal, while an obstruction can hide a flame completely. Because module wiring and polarity are not universal, identify the exact board before relying on a pinout or threshold.
Parts list
- Arduino Uno Rev3 or compatible Uno;
- MQ-2, MQ-5, or MQ-6 module;
- Optical flame-sensor module;
- Small active buzzer or piezo buzzer;
- One red LED and one green LED;
- Two LED resistors, typically 220–1,000 ohms depending on desired current;
- Breadboard and jumper wires;
- Stable 5 V supply with enough current for the Arduino and MQ heater;
- Optional pushbutton, 16×2 LCD, or I²C OLED.
For a larger buzzer, siren, relay, lamp, or other load, also use a transistor or logic-level MOSFET driver, a separate regulated supply rail, appropriate decoupling, and a flyback diode across a relay coil. Never drive a high-current actuator directly from an Arduino GPIO pin.
Representative Uno wiring
This is a representative wiring plan, not a universal pinout.
Also popular on Amazon
- THE MOST COMPLETE SMART HOME KIT--This universal kit are compatible for Arduino UNO R3 / Mega2560 / Mega328 /Nano / Raspberry Pi, it could DIY 16 projects according to your need.
- Those sensors will often being used in the beginner's project. It is included sound and obstacle avoidance sensor, obstacle avoidance sensor, temperature and humidity sensor, ultrasonic, a path tracing module and infrared human body induction sensor.
- This has 16 sensors modules and delicately selected sensors to detect temperature, humidity, sound, light, infrared, motion, flame, vibration, digital touch, air pressure and many other commonly-used sensors modules.
- We eliminate many old-fashioned sensors which have low reliability and duplicate function as other sensor in the kit, the UMLIFE modules sensor kits are choosed carefully for our user.
- With this kit, we will take you from knowing to utilizing, you are able to do more experiment, get your more idea into real action without the restriction of hardware and software. ❃❃ Any questions, you can contact us and we will give you a satisfied solution.
| Device | Connection |
|---|---|
| MQ module VCC | Uno 5 V, if the module requires 5 V |
| MQ module GND | Uno GND |
| MQ module AO | A0 |
| MQ module DO | Optional D2 |
| Flame module VCC | Module-rated supply |
| Flame module GND | Common GND |
| Flame module DO | D3 |
| Red LED | D7 through a resistor |
| Green LED | D8 through a resistor |
| Small buzzer | D9, or use a transistor driver |
| Optional flame analog output | A1 |
Before powering the circuit:
- Confirm the flame board’s supply-voltage range and whether it is 5 V-only or 3.3 V-compatible.
- Check whether its digital output is active-low or active-high.
- Confirm the MQ heater current and supply requirement.
- Make sure all grounds are common.
- Use a transistor driver for any load that exceeds the Arduino pin’s safe current capability.
Arduino sketch
This example uses the MQ analog output and flame digital output. The gas value of 450 is only a provisional, project-specific ADC threshold. It does not represent a certified concentration.
const byte GAS_PIN = A0;
const byte FLAME_PIN = 3;
const byte RED_LED_PIN = 7;
const byte GREEN_LED_PIN = 8;
const byte BUZZER_PIN = 9;
const int GAS_THRESHOLD = 450;
// Many flame modules pull DO LOW when flame is detected.
// Change to HIGH if your module behaves oppositely.
const byte FLAME_ACTIVE_STATE = LOW;
const unsigned long SAMPLE_INTERVAL_MS = 100;
const unsigned long CLEAR_DELAY_MS = 3000;
unsigned long lastSample = 0;
unsigned long clearStarted = 0;
bool alarmLatched = false;
void setup() {
pinMode(FLAME_PIN, INPUT);
pinMode(RED_LED_PIN, OUTPUT);
pinMode(GREEN_LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
Serial.begin(9600);
digitalWrite(GREEN_LED_PIN, HIGH);
digitalWrite(RED_LED_PIN, LOW);
noTone(BUZZER_PIN);
}
void loop() {
if (millis() - lastSample < SAMPLE_INTERVAL_MS) return;
lastSample = millis();
int gasValue = analogRead(GAS_PIN);
bool flameDetected = digitalRead(FLAME_PIN) == FLAME_ACTIVE_STATE;
bool gasDetected = gasValue >= GAS_THRESHOLD;
bool hazardDetected = gasDetected || flameDetected;
Serial.print("Gas ADC: ");
Serial.print(gasValue);
Serial.print(" | Flame: ");
Serial.print(flameDetected ? "YES" : "NO");
Serial.print(" | Hazard: ");
Serial.println(hazardDetected ? "YES" : "NO");
if (hazardDetected) {
alarmLatched = true;
clearStarted = 0;
} else if (alarmLatched) {
if (clearStarted == 0) clearStarted = millis();
if (millis() - clearStarted >= CLEAR_DELAY_MS) alarmLatched = false;
}
if (alarmLatched) {
digitalWrite(RED_LED_PIN, HIGH);
digitalWrite(GREEN_LED_PIN, LOW);
tone(BUZZER_PIN, 2200);
} else {
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(GREEN_LED_PIN, HIGH);
noTone(BUZZER_PIN);
}
}
The sketch uses millis() rather than a long blocking delay(), reports both sensor states over Serial, latches the alarm, and waits for a clear period before resetting. The Arduino language reference documents the functions used here, while the built-in examples include useful patterns for analog reading, smoothing, calibration, and non-blocking timing.
Upload and observe the readings
- Connect the Uno to the computer with USB.
- Open Arduino IDE.
- Choose the correct board and processor under the board-selection menu.
- Choose the correct serial port.
- Compile and upload the sketch.
- Open Serial Monitor and select 9600 baud.
- Record the normal gas readings and flame state during warm-up and normal operation.
MQ warm-up and burn-in
MQ sensors need stabilization. There are two separate issues:
- Initial burn-in: Some module documentation recommends many hours, with some guidance suggesting approximately 24–48 hours before serious calibration.
- Warm-up after power-up: Readings may drift for several minutes. Published hobby guidance ranges from roughly one to five minutes or more, depending on the module and conditions.
These figures are module-dependent rather than guaranteed universal values. Follow the documentation supplied with the exact sensor, allow the reading to settle, and do not treat an immediately changing value as a reliable measurement.
Calibrating a threshold
Gas channel
- Place the sensor in a well-ventilated environment away from intentional gas sources.
- Power it for the warm-up period specified by its documentation.
- Record readings for several minutes and note the baseline range, not just one number.
- Repeat in expected conditions, including different temperatures and humidity where practical.
- Check for interference from alcohol vapour, solvents, smoke, and cleaning products.
- Choose a provisional alarm threshold above normal baseline variation.
- Use a clear delay or hysteresis so small fluctuations do not chatter the alarm.
- Document the threshold as an experimental ADC value.
Do not convert analogRead() directly to ppm. A defensible concentration estimate requires the specific sensor and load resistor, target gas, heater conditions, calibration curve, environmental compensation, and repeatable test equipment.
Flame channel
- Determine whether the digital output is active-low or active-high.
- Adjust the module potentiometer with a controlled, safe optical test.
- Test at the intended distance and viewing angle.
- Check for false triggers from sunlight, lamps, and reflections.
- Test with partial obstruction and with the sensor window clean.
Do not release combustible gas or use an open flame indoors merely to prove the circuit works. Simulate inputs whenever possible with a potentiometer, pushbutton, or other low-risk test method.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Also popular on Amazon
- MQ-2 gas sensor sensitive material used in the clean air low conductivity tin oxide (SnO2). When there is the environment in which the combustible gas sensor, conductivity sensor with increasing concentration of combustible gases in air increases.
- Using a simple circuit to convert the change in conductivity of the gas concentration corresponding to the output signal.
- MQ-2 gas sensor high on gas, propane, hydrogen sensitivity of detection of natural gas and other flammable vapors are also very good.
- This sensor can detect a variety of flammable gas, is a low-cost sensors for a variety of applications.
- Analog output sensor for measuring changes in H2, LPG, CH4, CO, Alcohol, Smoke or Propane
Alert logic options
Gas-only alarm
A gas-only alarm is simple and can provide an indication before visible ignition. Its weaknesses are cross-sensitivity, baseline drift, and the fact that one ADC threshold is not a certified concentration.
Flame-only alarm
A flame-only alarm is easy to wire and can respond quickly to a visible flame in its field of view. It cannot detect an unignited leak and may miss a shielded, distant, small, or unusual flame.
Combined alarm
Use different patterns to make the prototype easier to interpret:
- Gas detected: repeated or slow buzzer pattern and red LED.
- Flame detected: faster or continuous alarm.
- Gas and flame together: highest-priority local alarm and optional remote notification.
Do not automatically switch a fan, relay, pump, valve, or other ordinary electrical device in a potentially explosive atmosphere unless the equipment and installation are specifically suitable for that hazardous location. A relay contact, connector, breadboard, or Arduino circuit can create an ignition source.
Useful improvements
Hysteresis
Use separate alarm and clear thresholds so the output does not oscillate around one boundary:
const int GAS_ALARM_THRESHOLD = 450;
const int GAS_CLEAR_THRESHOLD = 400;
Baseline and filtering
A rolling baseline, averaging, and rejection of very brief spikes can make a demonstration more stable. Store a baseline in EEPROM only after deliberate calibration; do not let an unverified startup value redefine “normal” during a real event.
Also popular on Amazon
- Nine MQ sensor modules in one kit - one module of each model: MQ-2, MQ-3, MQ-4, MQ-5, MQ-6, MQ-7, MQ-8, MQ-9 and MQ-135, for electronics learning, prototyping and hobbyist DIY projects
- Every module uses the same 5V DC supply, the same 4-pin 2.54 mm header (VCC / GND / DO / AO) and the same analog + digital outputs - one wiring pattern for the whole set
- Analog output AO follows the sensing element's response; digital output DO switches at a threshold you set with the potentiometer - raw trend and clean on-or-off for your own experiments
- Onboard LM393 comparator on each module, plus power and signal LEDs - DO can drive a buzzer or LED with no extra code, so results are easy to see in your project
- The sensor cap of each module is marked with its model number; needs warm-up and your own calibration - prototyping modules for DIY projects, not certified measuring instruments
Sensor-fault indication
Check for readings permanently at zero or saturated, a flame input stuck in one state, unexpected supply voltage, or a missing remote-module heartbeat. A suspected fault should produce a distinct fault indication, not silently report “safe.”
Logging and remote alerts
Log time, gas ADC value, flame state, alarm state, acknowledgment, warm-up status, and power-up events. Wi-Fi, GSM, LoRa, or Arduino Cloud can add secondary notifications. The local alarm must continue operating if the network fails. Rate-limit retries, protect credentials, and identify the exact board and service used. Examples of local and IoT architectures are shown by SunFounder’s gas monitor and IoT version.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Troubleshooting
| Symptom | Likely causes |
|---|---|
| Gas value remains high | Insufficient warm-up, contamination, poor ventilation, wiring error, or unstable supply |
| Flame is always detected | Wrong active polarity, excessive sensitivity, sunlight, lamp interference, or reflections |
| Buzzer resets the Uno | Excessive GPIO current, inadequate supply, or supply noise from a relay or siren |
| Readings jump | Breadboard noise, unstable power, airflow, or sensor warm-up drift |
| No response | Incorrect pin, wrong voltage, missing common ground, disconnected module, or failed sensor |
| Alarm chatters | No hysteresis and a threshold too close to normal baseline variation |
| Remote alert fails | Network outage, incorrect credentials, service configuration, or power instability |
Why this is not a certified safety system
A hobby MQ module and Arduino generally lack certified sensing accuracy, a listed enclosure and installation method, reliable fault supervision, tested alarm audibility, validated battery backup, end-of-life indication, electromagnetic-compatibility validation, and hazardous-location approval. The system also cannot guarantee detection throughout a room; gas behaviour depends on density, ventilation, temperature, room geometry, and sensor placement.
NFPA educational material recommends professionally listed detectors for propane applications and advises following the manufacturer’s instructions. Listed detector designs and applicable standards may define alarm points in relation to the lower explosive limit; those values must not be translated into an arbitrary Arduino ADC number. See NFPA’s educational guidance and its code material on listed detectors.
Safety rules
- Never use this project as the sole protection for a home, laboratory, workshop, RV, boat, or industrial area.
- Install approved detectors appropriate to the gas and installation location.
- Do not deliberately release LPG, propane, methane, or other combustible gas indoors to test it.
- Do not operate electrical switches or ignite a lighter near a suspected leak.
- If gas is suspected, leave the area and call the appropriate emergency or gas-service number from a safe location. Do not re-enter until professionals say it is safe.
- Keep the MQ heater and Arduino electronics away from places where flammable gas may accumulate unless the complete design is appropriately rated.
- A sounding buzzer does not prove the system is safe, and a silent buzzer does not prove that gas is absent.
Prototype versus certified detector
| Use case | Appropriate choice |
|---|---|
| Learning, experimentation, data logging, or classroom demonstration | Arduino, MQ module, flame module, LEDs, and buzzer |
| Home or propane life safety | Professionally listed detector matched to the gas and installation location |
| Both learning and safety | Use the Arduino only as supplemental monitoring; it must not replace, disable, or control the certified alarm |
For construction, workshop, or facilities work, the distinction is especially important: ordinary Arduino hardware is not automatically suitable for a hazardous location. Shutoff systems, ventilation controls, and industrial alarms require properly engineered, rated, and professionally installed equipment.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

