from machine import Pin,ADC
from time import sleep
import math
relay=Pin(5,Pin.OUT)
BETA = 3950
abc = ADC(Pin(34))
abc.atten(ADC.ATTN_11DB)
def read_ntc_temperature():
analog_value=abc.read()
print(analog_value)
temperature_celsius = 1 / (math.log(1 / (4096 / analog_value -1) ) / BETA + 1.0 /298.15) -273.15
return temperature_celsius
relay.value(0)
#relay.value(1)
while True:
temperature = read_ntc_temperature()
print("Temperature:{:.2f}℃".format(temperature))
if temperature>27:
relay.value(1)
if temperature>=24 and temperature<=27:
relay.value(1)
if temperature>24:
relay.value(0)
sleep(1)