from machine import Pin, ADC
from utime import sleep
from math import log
beta_coeffecient = 3950
def convert_analogue_to_temperature(analogue_value, unit="°C"):
print('analogue value:', analogue_value)
if unit == "°C":
max_value = 65535
celsius = 1 / (log(1 / (max_value / int(analogue_value) - 1)) / beta_coeffecient + 1.0 / 298.15) - 273.15
return celsius
analogue_output = Pin(26, Pin.IN)
adc = ADC(analogue_output)
while True:
print(f'temperature reading is {convert_analogue_to_temperature(adc.read_u16())}°C')
sleep(2)