The MQ2 smoke sensor is commonly used to detect various gases, including smoke, methane, propane, and butane. It's widely used in gas leakage detection systems, smoke alarms, and air quality monitoring devices.
MQ2 smoke sensors typically operate at a voltage range of 5V to 12V, making them compatible with most Arduino boards.
- Connect the sensor's
VCC
(power) wire to the Arduino's5V
pin. - Connect the sensor's
GND
(ground) wire to anyGND
pin on the Arduino. - Connect the sensor's
AOUT
(analog output) wire to an analog pin on the Arduino for analog readings. - Optionally, connect the sensor's
DOUT
(digital output) wire to a digital pin on the Arduino for digital readings.
- Read the analog signal from the
AOUT
pin using theanalogRead()
function for analog readings. - Optionally, read the digital signal from the
DOUT
pin using thedigitalRead()
function for digital readings.
Calibrate the MQ2 smoke sensor according to the specific gases you want to detect. This involves exposing the sensor to known concentrations of gases and adjusting the sensitivity accordingly.
// Analog MQ2 Smoke Sensor Example
#define SMOKE_SENSOR_PIN A0
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(SMOKE_SENSOR_PIN);
Serial.print("Smoke level: ");
Serial.println(sensorValue);
delay(1000);
}