Earn Maker Points on Every Order! Learn More!

MQ Gas Sensor with Arduino

Back to Blog
MQ Gas Sensor with Arduino - MQ Gas Sensor with Arduino - MQ Gas Sensor with Arduino - MQ Gas Sensor with Arduino

MQ Gas Sensor with Arduino

MQ Gas Sensor use a small heater inside with an electro-chemical sensor. They are sensitive to Gases.

Whenever the concentration of gas increases the resistance will decrease (but the current flow will get increased). It leads to change in voltage and it is read at Analog out pin which tells how much gas is concentrated in normal Air. This varied analog voltage is used to calculate the PPM of Gas.

Similarly, the Module has a Digital output (connected with an Op-Amp) along with a Potentiometer. The Threshold/Sensitivity can be adjusted using the Potentiometer. Because to calibrate the sensor to an Idle condition. Once it reaches the threshold, it will produce the output signal at D0 Pin.

The MQ-2 Gas Sensor module is useful for gas leakage detecting in home and industry. It can detect LPG, i-butane, propane, methane, alcohol, hydrogen and smoke.

Note: All MQ Sensor takes some time to work properly because of the Heater needs to be heated for a while.

Pin Details:

MQ-Gas-Sensor-Pinout

A0 – Analog Output (PPM Calculation)

D0 – Digital Output (HIGH/LOW depends on Threshold)

GND – Ground

VCC – Power Supply (+5v)

Circuit Diagram:

 MQ-Gas-Sensor-with-Arduino-Circuit-V2

 

Code:

int redLed = 8;

int greenLed = 9;

int buzzer = 11;

int smokeA0 = A0;

// Enter Your 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("Sensor Value from A0: ");

  Serial.println(analogSensor);

  // Checks if it has 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);

}

The above code will read the Gas Sensor Values from A0. A Buzzer and two LEDs are connected with Arduino to alarm when it exceeds the threshold value. The Green Light glows when the Air Quality is Normal. The Red Denotes the Air Quality is Bad/Smoke is detected. You need to modify the threshold value according to your sensor and type of Gas.

Share this post

Leave a Reply

Back to Blog