#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int buzzerPin = 13;
int ledPin = 5;
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Alat Pendeteksi");
lcd.setCursor(0,1);
lcd.print("Kebocoran Gas");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("By:");
lcd.setCursor(0,1);
lcd.print("Kelompok 8");
delay(2000);
Serial.begin(9600);
pinMode(A1, INPUT);
pinMode(2, INPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
int ketebalanGas = analogRead(A1);
Serial.print("Sinyal Analog: ");
Serial.println(ketebalanGas);
Serial.print("Sinyal Digital: ");
Serial.println(digitalRead(2));
delay(300);
lcd.setCursor(0,0);
if (ketebalanGas >= 0 && ketebalanGas < 200) {
lcd.print("Gas Aman ");
noTone(buzzerPin);
digitalWrite(ledPin, LOW);
}
else if (ketebalanGas >= 200 && ketebalanGas < 400) {
lcd.print("Butuh Pengawasan ");
digitalWrite(ledPin, millis() % 3000 < 1000);
if (millis() % 500 < 50)
tone(buzzerPin, 500);
else
noTone(buzzerPin);
}
else {
lcd.print("Gas Bocor! ");
digitalWrite(ledPin, HIGH);
tone(buzzerPin, 1000);
}
lcd.setCursor(0,1);
lcd.print("Ketebalan= ");
lcd.print(ketebalanGas);
delay(300);
}