import time
from machine import Pin
from machine import ADC
from math import log
sensor_read = ADC(26)
def read(Pin):
BETA = 3950
bits = (2**16)-1
digital_val = Pin.read_u16()
analogue_voltage = float((digital_val * 3.3) / bits)
#volt to celsius
resistor = 10000
ntc_resistance = resistor * (3.3 / analogue_voltage - 1)
R25 = 10000 # Resistance of NTC at 25°C
B_coefficient = 3950 # B coefficient of NTC
Tref = 298.15 # Reference temperature in Kelvin (25°C)
# Calculate temperature in Kelvin
temperature_kelvin = 1 / (1 / Tref + 1 / B_coefficient * log(R25 / ntc_resistance))
# Convert temperature from Kelvin to Celsius
temperature_celsius = temperature_kelvin - 273.15
return temperature_celsius
while True:
print(read(sensor_read))
time.sleep(5)