from machine import Pin
from utime import sleep_ms
# Pin configuration for NTC temperature sensor
ntc_pin = Pin(26, Pin.IN)
# Pin configuration for LEDs
red_led_pin = Pin(5, Pin.OUT)
blue_led_pin = Pin(4, Pin.OUT)
def read_temperature():
# Read analog value from NTC sensor
sensor_value = ntc_pin.read_u16()
# Convert analog value to temperature using NTC resistance-temperature curve
# Replace the coefficients with values specific to your NTC sensor
resistance = 10000.0 / ((65535.0 / sensor_value) - 1)
temperature = 1 / ((resistance / 10000.0) / 3950.0 + 1.0 / 298.15) - 273.15
return temperature
def blink_led(pin):
# Blink the LED connected to the specified pin
pin.toggle()
sleep_ms(1000)
pin.toggle()
sleep_ms(1000)
while True:
# Read temperature from NTC sensor
temperature = read_temperature()
# Print data to serial terminal
print("Temperature: {:.2f} °C".format(temperature))
# Check temperature conditions and control red LED
if 20 < temperature < 40:
blink_led(red_led_pin)
# Wait for 3 minutes
sleep_ms(180000)