from machine import Pin, ADC
import utime
import math
# Initialize ADC (assuming ADC is available)
adc = ADC(Pin(27))
# Define the Beta Coefficient of the thermistor
BETA = 3950
def read_temperature():
# Read raw analog value from ADC
analog_value = adc.read()
# Calculate resistance of the thermistor
resistance = (1023.0 / analog_value) - 1
resistance = 10000.0 / resistance
# Calculate temperature in Celsius
celsius = 1 / ((math.log(resistance / 10000.0) / BETA) + (1.0 / 298.15)) - 273.15
return celsius
def main():
while True:
temperature = read_temperature()
print("Temperature:", temperature, "°C")
utime.sleep(1) # Delay for 1 second
if __name__ == "__main__":
main()