from machine import ADC, Pin
import math, utime
adc = ADC(Pin(34))
def get_temp():
value = adc.read()
voltage = value / 4095 * 3.3
T0 = 298.15
B = 3950
R0 = 10000
R = 10000 * voltage / (3.3 - voltage)
# Using Steinhart-hart equation
T = 1 / (1/T0 + (1/B) * math.log(R/R0)) - 273.15
return T
while True:
temp = get_temp()
print("Temperature: {:.1f} C".format(temp))
utime.sleep(0.5)