# Measures the ambient temperature using a NTC Thermistor module KY013
from utime import sleep
from machine import ADC, Pin
import math
analog_value = ADC(0)
# Calculate the temperature using Steinhart-Hart equation
def Temperature(RawValue):
c1 = 0.001129148
c2 = 0.000234125
c3 = 0.0000000876741
R1 = 10000.0
ADC_Res = 65535.0
R2 = R1 / ((ADC_Res/RawValue - 1))
T = math.log(R2)
Tmp = 1.0 / (c1 + (c2 + (c3 * T * T)) * T)
Temp = Tmp - 273.15
return Temp
while True:
Raw = analog_value.read_u16() # Read temp
Temp = Temperature(Raw) # Calculate
print("Temperature (C): ",Temp) # Display
sleep(1) # Wait 1 second