from machine import ADC, Pin
import time
sensor = ADC(26) # GP26 (A0 pin)
buzzer = Pin(15, Pin.OUT)
while True:
reading = sensor.read_u16()
voltage = reading * 3.3 / 65535 # Convert ADC to voltage
# Temperature estimation logic (rough)
temperature = (1 - voltage) * 100 # Rough logic, for simulation only
print("🌡️ Temperature: {:.2f} °C".format(temperature))
# You can adjust this threshold as needed
if temperature > 30:
buzzer.value(1)
print("🔥 High Temperature! Buzzer ON")
else:
buzzer.value(0)
print("✅ Temperature Normal. Buzzer OFF")
print("-----")
time.sleep(1)