#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <MQUnifiedsensor.h>
#define Board ("ESP-32")
#define Pin (4)
#define Threshold (23)
#define Type ("MQ-2")
#define Voltage_Resolution (3.3)
#define ADC_Bit_Resolution (12)
#define RatioMQ2CleanAir (9.83)
// MQ2 Library Instance Setup
MQUnifiedsensor MQ2(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
// Display Setup
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Variables
int gas_value = 0;
void setup() {
lcd.init();
lcd.begin(16, 2);
lcd.backlight();
lcd.clear();
lcd.print("Gas Sensor");
delay(1000);
Serial.begin(9600);
// Set Parameters to detect PPM concentration for LPG
MQ2.setRegressionMethod(1);
MQ2.setA(574.25);
MQ2.setB(-2.222);
MQ2.init();
Serial.println("Hello, ESP32!");
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}
Loading
esp32-devkit-v1
esp32-devkit-v1