from machine import Pin, ADC
import time
# Define the analog pin connected to the gas sensor
gas_sensor = ADC(Pin(2)) # Use appropriate pin (e.g., 26 for Pico)
# Define the pin connected to the LED
led = Pin(0, Pin.OUT) # Use the correct GPIO number
# Set threshold for gas detection
GAS_THRESHOLD = 30000 # Adjust this value based on calibration
while True:
gas_value = gas_sensor.read_u16() # For 16-bit ADC resolution
print("Gas Sensor Reading:", gas_value)
if gas_value > GAS_THRESHOLD:
print("Gas detected!")
led.on()
else:
led.off()
time.sleep(0.5)