import machine
import math
import time
adc = machine.ADC(machine.Pin(34))
adc.atten(machine.ADC.ATTN_11DB)
adc.width(machine.ADC.WIDTH_10BIT)
led = machine.Pin(21, machine.Pin.OUT)
BETA = 3950
while True:
analog_read = adc.read()
celsius = 1 / (math.log(1 / (1023. / analog_read - 1)) / BETA + 1.0 / 298.15) - 273.15
print("Temperature: {:.2f} °C".format(celsius))
if celsius >= 35.0:
led.on()
else:
led.off()
time.sleep(1)