0

I found a link on how to connect MQ-2 Gas Sensor to Arduino Uno.

http://electronicsprojectshub.com/how-to-connect-mq2-gas-sensor-to-arduino/

After I bought all the parts and tried it out, the sensor gave me this in the serial monitor

Ro: 10.81 kohm

LPG:0.00ppm CO:0.00ppm SMOKE:0.00ppm

LPG:0.00ppm CO:0.00ppm SMOKE:0.00ppm

and so on.

Here is the code I used

#include <MQ2.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16,2);
int Analog_Input = A0;
int lpg, co, smoke;
MQ2 mq2(Analog_Input);

void setup(){
  pinMode(A0, INPUT);
  Serial.begin(9600);
  lcd.begin();
  lcd.backlight();
  mq2.begin();
}

void loop(){
  float* values= mq2.read(true);
  //lpg = values[0];
  lpg = mq2.readLPG();
  //co = values[1];
  co = mq2.readCO();
  //smoke = values[2];
  smoke = mq2.readSmoke();

  lcd.setCursor(0,0);
  lcd.print("LPG:");
  lcd.print(lpg);
  lcd.print(" CO:");
  lcd.print(co);
  lcd.setCursor(0,1);
  lcd.print("SMOKE:");
  lcd.print(smoke);
  lcd.print(" PPM");
  delay(1000);
}

Please help me fix it so that it can perform just the same as the video. Thanks.

2
  • I want it to show this LPG: 4 CO:2803 SMOKE: 16 PPM on the LCD. Please help. Thanks.
    – charlotte
    Dec 15, 2019 at 13:24
  • blow the right amount of gas and smoke onto the sensor so that you get those readings
    – jsotola
    Dec 15, 2019 at 19:01

1 Answer 1

1

First this should be like this:

float* values= mq2.read(false); //false

and then write this to be printed in the serial monitor

Serial.print('\n');
  Serial.print("LPG:");
  Serial.print(lpg);
  Serial.print(" CO:");
  Serial.print(co);

  Serial.print('\n');
  Serial.print("SMOKE:");
  Serial.print(smoke);
  Serial.print(" PPM");
  Serial.print('\n');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.