("Project: MQ2 Gas Leak Alarm System")
print("Developed by: Fatihah Zulkefli")
print("Date: 14/4/2025")
#Import library/module
from machine import ADC, Pin, PWM
from time import sleep
#Pin Declaration
gas_sensor = ADC(Pin(36, Pin.IN))
buzzer = PWM(Pin(4, Pin.OUT))
#Parameter Declaration (Optional)
THRESHOLD = 2000
#Main Program
while True:
gas_level = gas_sensor.read()
print("Gas Level: ", gas_level)
if gas_level > THRESHOLD:
print("Gas Detected!")
buzzer.init(freq = 5000, duty = 512)
else:
buzzer.init(freq = 5000, duty = 0)
sleep(1)