#include #include #include LiquidCrystal_I2C lcd(0x27, 20,4); //change this with the pin that you use int pin = 5; float lpg, co, smoke; MQ2 mq2(pin); void setup(){ Serial.begin(115200); lcd.begin(); lcd.backlight(); delay(250); lcd.noBacklight(); delay(250); lcd.backlight(); lcd.setCursor(0,0); lcd.print("Fablab Kamakura"); delay(1000); lcd.setCursor(0,1); lcd.print("Setyawan UGM"); delay(2000); lcd.clear(); // calibrate the device mq2.begin(); } void loop(){ /* * read the values from the sensor, it returns * an array which contains 3 values. * 0 : LPG in ppm * 1 : CO in ppm * 2 : SMOKE in ppm */ float* values= mq2.read(true); //set it false if you don't want to print the values to the Serial // lpg = values[0]; lpg = mq2.readLPG(); lcd.setCursor(0,0); lcd.print("LPG(ppm) :"); lcd.setCursor(11,0); lcd.print(lpg); // co = values[1]; co = mq2.readCO(); lcd.setCursor(0,1); lcd.print("CO(ppm) :"); lcd.setCursor(11,1); lcd.print(co); // smoke = values[2]; smoke = mq2.readSmoke(); lcd.setCursor(0,2); lcd.print("Smoke(ppm):"); lcd.setCursor(11,2); lcd.print(smoke); delay(1000); }