MQ2 Gas sensor showing wrong reading

Hello everyone. I am trying out a project to read the value from a MQ2 Gas Sensor using my Arduino Uno board and display it on the serial monitor. Following is the attached code :-

#define MQ2_PIN A0
void setup() {
  Serial.begin(115200);
  pinMode(MQ2_PIN, INPUT);
}
void loop() {
  int gasSensorValue = analogRead(MQ2_PIN);
  Serial.print("MQ2 Sensor Value: ");
  Serial.println((gasSensorValue/1023)*100);
  delay(1000);
}

I have set the correct baud rate and connected the pin A0 of the MQ2 sensor to the A0 pin of Arduino Uno, yet everytime I get a zero (0) reading as output from the sensor. Can anyone please help me ?

That is an integer divide, with result == 0 if gasSensorValue is less than 1023.

Just print out gasSensorValue, as there is no point in scaling it.

Don't forget to "burn in" the sensor for at least 48 hours before taking any readings.

1 Like

"Burn in" as in keep sensor connected to active power lines, right ?

Power the sensor normally for 48 to 72 hours, before making the first ever readings. Or take readings and notice how they change until settling down to something that might actually be useful.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.