Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
BETTESWORTHConstruction
Arduino Nano

Gas Leak Detector Alarm System With Arduino Nano and MQ-2

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Safety note: This Arduino Nano and MQ-2 project is an educational prototype for detecting changes associated with combustible gases and vapors. It is not a certified residential gas alarm and must not replace a listed detector protecting a home, workshop, or other occupied building.

The circuit reads the MQ-2 module’s analog output, filters the reading, and uses LEDs and a buzzer to indicate normal, warning, and alarm conditions. It is useful for learning, experiments, data logging, and supplemental monitoring—but it does not provide certified gas concentration accuracy or guaranteed life-safety performance.

As an Amazon Associate I earn from qualifying purchases.

What this project detects

The MQ-2 is a heated metal-oxide semiconductor sensor that can respond to several combustible gases and vapors, including LPG, propane, hydrogen, methane, alcohol vapor, and smoke. Its broad response makes it inexpensive and easy to demonstrate, but it cannot reliably identify which gas caused a reading.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

An MQ-2 project should be described as a combustible-gas and vapor prototype, not as a methane detector, propane detector, smoke alarm, or carbon-monoxide alarm. Carbon monoxide requires a sensor and alarm system designed and evaluated specifically for CO. As UL explains, CO alarms do not detect methane or other combustible gases.

#1 Best Overall
Kidde Carbon Monoxide + Explosive Gas, Natural Gas & Propane Alarm, Plug-in with 9V Battery Backup, Digital Display, 85 dB Alarm, LED Status Indicators, 3rd Edition
  • Easy Installation - simply plug-in to a standard, 120V outlet in your home
  • 9-volt battery backup provides protection during a power outage
  • Digital LED display shows the level of carbon monoxide the CO alarm is sensing or states "GAS" when explosive gas is present
  • 85-decibel alarm announces when carbon monoxide or explosive gas is detected
  • Peak Level Memory records the last time carbon monoxide was detected or when the unit was last tested

Natural gas is primarily methane and generally rises, while LPG and propane are heavier than air and can accumulate lower down. That difference affects placement, but there is no universal mounting height that is correct for every gas, room, appliance, airflow pattern, code, and jurisdiction.

The classic Arduino Nano is a 5 V ATmega328-based board with a compact form factor of approximately 45 × 18 mm. That makes it a convenient match for many 5 V MQ sensor modules.

Parts required

  • Classic 5 V Arduino Nano or a compatible ATmega328P Nano
  • MQ-2 gas sensor module
  • Regulated 5 V USB or external power supply
  • One or more LEDs
  • One 220–330 Ω resistor for each LED
  • 5 V active buzzer
  • Breadboard and jumper wires

Useful additions include a transistor or logic-level MOSFET for driving a larger buzzer, an OLED or LCD, a pushbutton, a data-logging module, a wireless module, a battery-backed supply, and a visible system-ready indicator.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Pay particular attention to power. The MQ-2 heater uses 5 V and the sensor datasheet specifies consumption of up to 900 mW—roughly 180 mA at 5 V. A weak USB source, unsuitable regulator, or thin wiring can cause unstable readings or reset the Nano. The module’s actual current should be checked against its documentation and measured where necessary. See the MQ-2 datasheet for the stated heater requirements.

Wiring the MQ-2 to an Arduino Nano

MQ-2 module Arduino Nano
VCC 5V
GND GND
AO or AOUT A0
DO or DOUT Optional digital input
Output Nano connection
Green LED Digital pin through a 220–330 Ω resistor
Warning LED Digital pin through a 220–330 Ω resistor
Red alarm LED Digital pin through a 220–330 Ω resistor
Buzzer Digital pin through a suitable driver when required

Connect every ground together. Each LED needs its own series resistor; do not use one resistor for several LEDs. A small, low-current active buzzer may be driven directly from a Nano output, but check its current rating. Use a transistor or MOSFET, a suitable supply, and a flyback diode for a larger or inductive sounder. Never assume every buzzer is safe to connect directly to a microcontroller pin.

The optional DO connection comes from the module’s comparator and adjustable potentiometer. It reports only whether the module signal has crossed that setting. AO is more useful because the Nano can filter the reading, detect trends, and implement separate warning and alarm levels.

How the MQ-2 reading works

The sensor contains a heated sensing element whose electrical resistance changes in the presence of certain gases. The module converts that change into an analog voltage. The Nano’s analogRead() function returns an ADC value, normally from 0 to 1023 on the classic Nano’s 10-bit analog input.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

That number is not automatically a parts-per-million measurement. The voltage-to-concentration relationship depends on the exact sensor and module, load resistance, gas type, temperature, humidity, sensor age, supply voltage, and calibration conditions. A module listing may quote a nominal range such as 100–10,000 ppm, while the MQ-2 datasheet lists 300–10,000 ppm under stated test conditions. Those figures are not a universal, accurate range for every module or gas.

Do not label an ADC value such as 240 as “240 ppm.” A frequently copied Arduino Project Hub design uses values such as 80, 120, 160, 200, and 240 for staged LEDs and a buzzer, but these are arbitrary ADC thresholds, not certified alarm setpoints or concentration values. The original design uses A0, pins 2–6 for LEDs, pin 7 for the buzzer, and 9,600 baud; it is a useful starting demonstration, not a calibrated detector.

Rank #2
Kidde Carbon Monoxide & Explosive Gas Alarm, Plug-in & AA Battery, COPDLG | Natural Gas and Propane Detection, Low-Level CO Alerts for Children, Seniors, & Pets, Digital Backlit Display, 5th Edition
  • 3X THE DETECTION: Model COPDLG detects low levels of CO, natural gas, propane and sounds a loud 85-dB alarm; backlit digital display indicates level of CO presence or the word "GAS" when explosive gas is present; replaces model 900-0113, KN-COEG-3
  • ADVANCED LOW-LEVEL CO TECHNOLOGY: Alerts earlier at 30-70ppm with distinct light & sound pattern, helping safeguard young children, older adults, pregnant women, and pets*; at 70ppm a separate alarm pattern signals dangerous levels for all occupants
  • PLUG-IN + AA BATTERY BACKUP: Simply plug into a standard, 120V outlet with two included AA backup batteries for coverage during power outages; rotating plug fits vertical or horizontal outlets; sleep peacefully with no low battery chirps
  • TESTED & TRUSTED: This carbon monoxide alarm is rigorously tested to meet UL 2034, 5th Edition standards, and is ETL Listed; includes a 7-year limited warranty on the alarm
  • BUILT FOR EVERY HOUSEHOLD: Designed to help provide dependable carbon monoxide monitoring for everyday home use; supports renters, homeowners, and pet owners seeking added awareness and detection from CO and explosive gas hazards

Burn-in and warm-up

A new MQ-2 should not be treated as stable after a five-second delay. The manufacturer-style datasheet specifies more than 48 hours of preheating for its standard test condition. One current module specification recommends an initial continuous burn-in of approximately 48–168 hours, followed by about 10–15 minutes of heating after later startups.

  1. Power the sensor continuously for the recommended initial burn-in period.
  2. After a later power-up, allow the sensor to heat for at least the module’s stated warm-up time.
  3. Keep the sensor in clean air while establishing its baseline.
  4. Do not announce a “safe” reading while the system is still warming up.

Baseline drift can occur after the sensor has been switched off for a long period, after relocation, or after changes to the enclosure, supply, temperature, or humidity.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Calibrating a hobbyist prototype

For a relative-warning project, take many clean-air readings after warm-up and calculate an average or median. Set warning and alarm levels above that baseline, then test the behavior in a controlled way. Re-establish the baseline if the sensor, enclosure, location, or power supply changes.

A true concentration measurement requires calibration against a known gas concentration with documented temperature, humidity, load resistance, and sensor-response characteristics. Without that process, describe the thresholds as experimental relative levels—not ppm and not regulatory limits.

Improved Arduino Nano code

The following sketch demonstrates baseline-relative logic with averaging, a warm-up state, persistence, hysteresis, and serial diagnostics. The offsets are examples only and must not be presented as residential alarm thresholds.

const byte MQ2_PIN = A0;
const byte BUZZER_PIN = 7;
const byte READY_LED = 2;
const byte WARNING_LED = 3;
const byte ALARM_LED = 6;

const unsigned long WARMUP_MS = 15UL * 60UL * 1000UL;
const unsigned long PERSIST_MS = 3000;

int baseline = 0;
int warningLevel = 0;
int alarmLevel = 0;
int clearLevel = 0;
bool alarmLatched = false;
unsigned long startedAt;
unsigned long highSince = 0;

int readAverage() {
  long total = 0;
  for (byte i = 0; i < 20; i++) {
    total += analogRead(MQ2_PIN);
    delay(5);
  }
  return total / 20;
}

void setup() {
  Serial.begin(9600);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(READY_LED, OUTPUT);
  pinMode(WARNING_LED, OUTPUT);
  pinMode(ALARM_LED, OUTPUT);
  startedAt = millis();
}

void loop() {
  int reading = readAverage();

  if (millis() - startedAt < WARMUP_MS) {
    digitalWrite(READY_LED, LOW);
    digitalWrite(WARNING_LED, HIGH);
    digitalWrite(ALARM_LED, LOW);
    noTone(BUZZER_PIN);
    Serial.println("WARMING_UP");
    delay(200);
    return;
  }

  // Establish this only after proper burn-in in clean air.
  if (baseline == 0) {
    baseline = reading;
    warningLevel = baseline + 40;
    alarmLevel = baseline + 100;
    clearLevel = baseline + 70;
  }

  Serial.print("MQ2=");
  Serial.print(reading);
  Serial.print(" baseline=");
  Serial.println(baseline);

  digitalWrite(READY_LED, HIGH);

  if (!alarmLatched && reading >= alarmLevel) {
    if (highSince == 0) highSince = millis();
    if (millis() - highSince >= PERSIST_MS) {
      alarmLatched = true;
    }
  } else if (reading < alarmLevel) {
    highSince = 0;
  }

  if (alarmLatched) {
    digitalWrite(WARNING_LED, LOW);
    digitalWrite(ALARM_LED, HIGH);
    tone(BUZZER_PIN, 2500);

    if (reading <= clearLevel) {
      alarmLatched = false;
      noTone(BUZZER_PIN);
      digitalWrite(ALARM_LED, LOW);
    }
  } else if (reading >= warningLevel) {
    digitalWrite(WARNING_LED, HIGH);
    digitalWrite(ALARM_LED, LOW);
    tone(BUZZER_PIN, 1200, 150);
  } else {
    digitalWrite(WARNING_LED, LOW);
    digitalWrite(ALARM_LED, LOW);
    noTone(BUZZER_PIN);
  }

  delay(200);
}

This sketch intentionally leaves several production issues visible: it does not verify sensor disconnection, retain a baseline in non-volatile memory, or provide battery-backed operation. A more serious design should add explicit FAULT, WARMING_UP, NORMAL, WARNING, and ALARM states. Loss of power should be indicated as unavailable, never silently treated as clean air.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Testing without creating a gas hazard

First test the wiring and software without fuel gas. Temporarily substitute simulated analog values, or use a controlled signal source, to confirm LED transitions, buzzer operation, hysteresis, persistence timing, and reset behavior.

Do not release uncontained LPG, propane, methane, or other fuel gas into a room. Do not test near flames, sparks, relays, mains equipment, or other ignition sources. For sensor calibration, use an appropriate controlled test gas and follow the sensor or detector manufacturer’s procedure.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting

The analog value never changes

  • Confirm VCC is actually 5 V and ground is shared.
  • Check that AO, not DO, is connected to A0.
  • Inspect jumper wires and breadboard contacts.
  • Allow the heater to warm up.
  • Use a supply that can handle the heater current.

The value is always high or unstable

  • Allow the full startup warm-up period.
  • Move the sensor away from alcohol, solvents, aerosols, smoke, cooking fumes, and cleaning products.
  • Check for supply-voltage dips and Nano resets.
  • Average multiple samples rather than reacting to one ADC reading.
  • Re-establish the clean-air baseline after relocation or enclosure changes.

The buzzer does not sound

  • Confirm whether it is an active buzzer; a passive buzzer needs a tone signal.
  • Check polarity and the pin number.
  • Measure its current requirement.
  • Use a transistor driver for a larger sounder.

The alarm triggers repeatedly

Add separate trigger and clear levels, require several consecutive high readings, and latch the alarm until the reading is safely below the clear threshold. Rapid changes around one threshold are normal for an unfiltered sensor.

Rank #3
Kidde Carbon Monoxide Detector, Propane, Natural, Methane, & Explosive Gas Alarm, Plug-in Wall with 9-Volt Battery Backup, Digital LED Display
  • Easy Installation - simply plug-in to a standard, 120V outlet in your home
  • 9-volt battery backup provides protection during a power outage
  • Digital LED display shows the level of carbon monoxide the CO alarm is sensing or states "GAS" when explosive gas is present
  • 85-decibel alarm announces when carbon monoxide or explosive gas is detected
  • Peak Level Memory records the last time carbon monoxide was detected or when the unit was last tested

Placement considerations

Placement depends on the target gas, appliance, room geometry, and airflow. Methane and natural gas generally rise; LPG and propane generally collect lower. Avoid direct supply or return airflow, fans, doorways, heat sources, water, condensation, grease, and locations where the sensor may be damaged. Do not put the sensing element in a sealed enclosure without a deliberate airflow path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The NFPA committee material discusses avoiding direct airstreams and doorways, but it should not be read as a universal installation instruction for every jurisdiction. Follow the instructions for the specific listed alarm when life safety is the objective.

Why this is not a residential safety alarm

A Nano, MQ-2 module, buzzer, and LEDs are individual hobbyist components, not a certified detector assembly. This prototype does not demonstrate the performance, fault handling, enclosure design, alarm audibility, power-failure behavior, environmental durability, installation validation, or certification expected of a residential product.

UL identifies UL 1484 for residential gas detectors and UL 2075 for gas and vapor detectors and sensors. Relevant alarm thresholds and installation requirements also depend on the complete product, gas type, adopted local rules, and jurisdiction. Do not claim UL or NFPA compliance merely because the circuit uses an Arduino and an MQ-2, and do not trust an unverified UL mark or marketplace description.

Use a listed residential combustible-gas alarm as the primary life-safety device. Keep the Arduino project for education, experimentation, logging, or supplemental indication. It should never be the only system protecting occupants from a gas leak.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

MQ-2 alternatives

An MQ-5 may be a more natural starting point for a project focused on LPG and natural gas, while an MQ-6 is worth considering for LPG-focused experimentation. Neither automatically becomes a certified safety device; exact performance still depends on calibration and the particular module.

An MQ-9 is positioned for carbon monoxide, methane, and LPG, but it still requires preheating and must not be presented as a certified CO alarm. More selective electrochemical or dedicated safety sensors are preferable when the design needs stable calibration, long-term monitoring, or safety-critical performance. They generally require a better analog front end, compensation, calibration, and certification work.

Useful upgrades

  • Add an OLED or LCD showing state and raw readings.
  • Store readings and state changes on an SD card.
  • Add Wi-Fi or cellular notifications, without making remote alerts the only warning.
  • Use a battery backup and a power-fail indicator.
  • Add a watchdog timer and startup self-test.
  • Record temperature and humidity to help interpret drift.
  • Add a second sensor for experimental redundancy.
  • Use a properly engineered interface if integrating with another control system; do not directly improvise a gas-valve shutoff.

Bottom line

The Arduino Nano and MQ-2 make a practical low-cost combustible-vapor demonstration: connect AO to A0, power the heater correctly, allow proper burn-in and warm-up, establish a clean-air baseline, and use averaging, persistence, and hysteresis instead of treating a raw ADC number as ppm. For actual household protection, install an appropriate listed residential gas alarm and use the Nano circuit only as a separate learning or supplemental project.

Quick Recap

Bestseller No. 1
Kidde Carbon Monoxide + Explosive Gas, Natural Gas & Propane Alarm, Plug-in with 9V Battery Backup, Digital Display, 85 dB Alarm, LED Status Indicators, 3rd Edition
Kidde Carbon Monoxide + Explosive Gas, Natural Gas & Propane Alarm, Plug-in with 9V Battery Backup, Digital Display, 85 dB Alarm, LED Status Indicators, 3rd Edition
Easy Installation - simply plug-in to a standard, 120V outlet in your home; 9-volt battery backup provides protection during a power outage
$57.47
Bestseller No. 3
Kidde Carbon Monoxide Detector, Propane, Natural, Methane, & Explosive Gas Alarm, Plug-in Wall with 9-Volt Battery Backup, Digital LED Display
Kidde Carbon Monoxide Detector, Propane, Natural, Methane, & Explosive Gas Alarm, Plug-in Wall with 9-Volt Battery Backup, Digital LED Display
Easy Installation - simply plug-in to a standard, 120V outlet in your home; 9-volt battery backup provides protection during a power outage
$74.00

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.