> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/wokwi/wokwi-docs/llms.txt
> Use this file to discover all available pages before exploring further.

# MQ2 Gas Sensor

> MQ2 Gas Sensor module for detecting combustible gases

MQ2 Gas Sensor module

## Pin names

<ParamField path="VCC" type="Power">
  Positive power supply
</ParamField>

<ParamField path="GND" type="Ground">
  Ground
</ParamField>

<ParamField path="DO" type="Digital Output">
  Digital output
</ParamField>

<ParamField path="AO" type="Analog Output">
  Analog output
</ParamField>

## Attributes

<ParamField path="ppm" type="string" default="400">
  Initial gas concentration (in parts per million)
</ParamField>

<ParamField path="threshold" type="string" default="4.4">
  Digital output threshold voltage
</ParamField>

## Operation

The MQ2 Gas Sensor is a semiconductor sensor that can detect the presence of various combustible gases including LPG, Propane, Hydrogen, Methane, and Carbon Monoxide. The sensor has both analog and digital outputs:

* The analog output (AO) provides a continuous voltage reading that corresponds to the gas concentration (ppm). Higher gas concentration results in higher voltage output.
* The digital output (DO) acts as a threshold detector - it goes LOW when gas concentration exceeds the threshold set by the potentiometer.

To use the MQ2 sensor:

1. Connect VCC to 5V power supply
2. Connect GND to ground
3. For analog readings:
   * Connect AO to an analog input pin
   * Read the analog value to get relative gas concentration
4. For threshold detection:
   * Connect DO to a digital input pin
   * The pin will read LOW when gas concentration exceeds threshold
   * Adjust threshold using the `threshold` attribute

<Note>
  In real hardware, the sensor needs a pre-heating time of about 20-30 seconds before taking readings. The simulator provides readings immediately.
</Note>

## Digital output

The digital output (DO) pin will read LOW when gas concentration exceeds the threshold. The threshold is set by the `threshold` attribute. The default threshold is 4.4V.

## Simulator examples

* [MQ2 Gas Sensor Digital Example](https://wokwi.com/projects/424318978955716609)
