#define gas GPIO_NUM_27
#define buzzer1 GPIO_NUM_4
#define flss GPIO_NUM_13
#define fan GPIO_NUM_16
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
//#define led1 GPIO_NUM_5
unsigned int T[] = {100, 150, 250, 300, 350};
unsigned int U[] = {100, 200, 300, 400, 500};
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(buzzer1, OUTPUT);
pinMode(fan, OUTPUT);
lcd.init();
lcd.clear();
lcd.backlight();
}
void loop() {
float analogValue_flss = analogRead(flss);
Serial.print("flame sensor RAW:");
Serial.println(analogValue_flss, 2); // so thuc dang sau de lam tron so
float flame_sensor = map(analogValue_flss, 0, 4095, 100, 0);
Serial.print(flame_sensor, 0);
Serial.println("%");
lcd.setCursor(0, 0);
lcd.print(F("Flame: "));
if (flame_sensor >= 90) {
Serial.print(" co lua");
lcd.print("CO LUA");
delay(1000);
for (int i = 0; i < 5; i++) {
tone(buzzer1, T[i], U[i]);
// delay(100);
// noTone(buzzer1);
// delay(100);
}
}
else {
lcd.print("ko lua");
Serial.println(" khong lua");
noTone(buzzer1);
//delay(300);
}
// put your main code here, to run repeatedly:
lcd.setCursor(0, 1);
lcd.print(F("Gas:"));
float analogValue_gas = analogRead(gas);
Serial.print("sensor_gas RAW:");
float mq2_sensor = map(analogValue_gas, 0, 4095, 0, 100);
Serial.println(analogValue_gas, 2);
if (mq2_sensor >= 10) {
lcd.print("co GAS");
Serial.print(" Co GAS");
digitalWrite(fan, HIGH);
}
else {
lcd.print("ko gas");
Serial.println(" KO gas");
digitalWrite(fan, LOW);
}
}