from machine import Pin, ADC, I2C
from time import sleep
from i2c_lcd import I2cLcd
# Inisialisasi LCD
i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=400000)
lcd = I2cLcd(i2c, 0x27, 2, 16)
# Sensor MQ2
mq2 = ADC(Pin(34))
mq2.atten(ADC.ATTN_11DB)
# Buzzer
buzzer = Pin(27, Pin.OUT)
while True:
gas = mq2.read()
lcd.clear()
lcd.move_to(0,0)
lcd.putstr("Gas Level:")
lcd.move_to(0,1)
lcd.putstr(str(gas))
# Jika gas tinggi
if gas > 2000:
buzzer.on()
else:
buzzer.off()
sleep(1)