from machine import ADC, Pin
from time import sleep
from math import log
# ESP32 Pin assignment for the Thermistor
ntc_pin = ADC(Pin(35))
ntc_pin.atten(ADC.ATTN_0DB)
# Beta Coefficient of the Thermistor
beta = 3950.0
# Temperature threshold in Celsius
warning_temp = 30.0
# Measure the temperature every second in an endless loop
while True:
# Begin new measurement:
# Read thermistor and calculate temperature in Celsius
ntc_data = ntc_pin.read()
temp = 1.0 / (log(1.0 / (4095.0 / ntc_data - 1)) / beta + 1.0 / 298.15) - 273.15
print('temp = ' + str(temp))
print('---------------------------')
# Check if temperature exceeds the threshold
if temp > warning_temp :
# Print a message if temperature exceeds threshold
print("Tempreture is High!")
else:
print("Tempreture is Normal!")
# Wait 1 second before new measurement
sleep(1)