from machine import ADC, Pin
import math
import time
BETA = 3950
R1 = 10000
V_in = 5.0
adc = ADC(Pin(2))
adc.atten(ADC.ATTN_11DB)
def read_ntc_temperature():
analog_value = adc.read()
print(analog_value)
V_out = (analog_value / 4096.0) * V_in
R2 = R1 * (V_in / V_out -1)
temperature_kelvin = 1 / (math.log(R2 / R1) / BETA + 1.0 / 298.15)
temperature_celsius = temperature_kelvin - 273.15
return temperature_celsius
while True:
temperature = read_ntc_temperature()
print("Temperature: {:.2f} ℃".format(temperature))
time.sleep(1)