import dht # นําเข้า library dht
from machine import Pin # นําเข้า Pin จากโมดูล machine เพื่อควบคุมขา GPIO
import time # นําเข้า time เพื่อใช้คําสั่งหน่วงเวลา
sensor = dht.DHT22(Pin(32))
led_red = Pin(23,Pin.OUT)
led = Pin(18,Pin.OUT)
while True:
sensor.measure() # อ่านค่าจาก DHT22
temp = sensor.temperature() # อุณหภูมิ (°C)
print("Temperature:", temp, "°C")
if(temp >30):
print("อุณหภูมิสูง")
led_red.on()
led.off()
else:
print("อุณหภูมิปกติ")
led.on()
led_red.off()
time.sleep(5)