MQ2 Gas/Smoke Sensor Pinout and Connection with Arduino
Hi, in this article, we are going to see the MQ2 Gas Sensor or Smoke Sensor Pinout Diagram and Its connection with Arduino for smoke detection with an alarming system. The MQ2 gas sensor is a widely used sensor for detecting gas leakage and smoke. It is highly sensitive to flammable and combustible gases like LPG, methane, butane, hydrogen, propane, alcohol, and smoke. It is most suitable for building safety systems like gas leakage detection, smoke detection, or fire alarm systems.
The MQ2 Gas Sensor operates with the 5V DC power supply. With its Analog Output, it provides a continuous voltage signal proportional to the gas concentration. With its Digital Output, it provides Outputs HIGH or LOW based on a user-set threshold via a potentiometer.
The MQ2 sensor contains a heating element and a metal oxide semiconductor layer. When these are exposed to gas the resistance of the layer changes which alters the output signal. The analog pin provides a voltage based on the gas concentration, while the digital pin switches states based on the set threshold.
MQ2 Sensor Pinout Diagram
Here, you can see the pinout diagram of the MQ2 Gas Sensor or Smoke Sensor.
As you can see the actual MQ Gas Sensor has six terminals which are named as A, H, A, B, H, B. And the MQ2 sensor module has four terminals. Basically, the MQ2 sensor module is built by housing the MQ sensor and some electronic components on a PCB board e.g. LM393 IC, LEDs, Potentiometer, Capacitors, resistors, etc.
The MQ2 Sensor Module has the following pinout,
- Pin no.1(VCC): Power supply (5V).
- Pin no.2(GND): Ground.
- Pin no.3(AO): Analog output pin.
- Pin no.4(DO): Digital output pin.
MQ2 Gas/Smoke Sensor Connection with Arduino
Here, you can see the connection diagram for interfacing the MQ2 Gas/Smoke Sensor with the Arduino Module for Gas/Smoke detection with an alarming system. Here, in this system, when the gas or smoke level is below a certain level the green LED will remain On but when the gas or smoke level increases above a set level the red LED and the Buzzer will be turned On.
Connection Description
- The VCC and GND terminals of the MQ2 sensor are connected to the 5V and GND terminals of the Arduino respectively.
- The Analog Output(AO) terminal of the MQ2 sensor is connected to the Analog Input(A5) terminal of the Arduino.
- The Indication LEDs and the Buzzer are connected to the Digital output terminals of the Arduino.
Here is a simple Arduino code given below for the above wiring setup.
// Assign Input and Output Pins
int redLed = 12;
int greenLed = 11;
int buzzer = 10;
int smokeA0 = A5;
// Gas or smoke level threshold value
int sensorThres = 400;
void setup() {
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
Serial.begin(9600);
}
void loop() {
int analogSensor = analogRead(smokeA0);
Serial.print("Pin A0: ");
Serial.println(analogSensor);
// Checks if the gas or smoke level reached the threshold value
if (analogSensor > sensorThres)
{
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
tone(buzzer, 1000, 200);
}
else
{
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
noTone(buzzer);
}
delay(100);
}
Read Also:
- Automatic Water Pump Control with Moisture Sensor Circuit Diagram
- Door Access Control System Wiring Diagram
- Remote Control Switch Board Internal Circuit Diagram
- Motor Driver L293D and L298N Connection with Arduino and Motors
- RFID RC522 Pinout and Interfacing with Arduino for Door Lock System
- Bluetooth Module HC05 and HM10 Pinout and Connection with Arduino
MQ2 Gas/Smoke Sensor Pinout and Connection with Arduino
Reviewed by Author
on
December 15, 2024
Rating: