Professional Documents
Culture Documents
T
T
T
h>
void setup() {
// Khởi động Serial Plotter
Serial.begin(9600);
while (!Serial) {
; // Đợi kết nối Serial Plotter
}
//Thiết lập lcd
lcd.begin(16, 2);
// Thiết lập chân kết nối
pinMode(ledPin, OUTPUT);
pinMode(speakerPin, OUTPUT);
delay(1000);
}
void loop() {
unsigned long currentMillis = millis();
previousMillis = currentMillis;
}
if (gasValue > threshold) {
lcd.setCursor(2, 0);
lcd.print("WARNING!!!");
lcd.setCursor(0, 1);
lcd.print("Chay ngay di !!!");
digitalWrite(ledPin, HIGH); // Bật đèn LED
tone(speakerPin, 1000); // Phát âm thanh từ loa
} else {
digitalWrite(ledPin, LOW); // Tắt đèn LED
noTone(speakerPin); // Tắt âm thanh
}
lcd.clear();
}