from machine import Pin
from time import sleep
import dht
# --- 센서 설정 ---
pir = Pin(28, Pin.IN, Pin.PULL_DOWN) # PIR 센서 (GPIO 28)
sensor = dht.DHT22(Pin(27)) # DHT22 온·습도 센서 (GPIO 27)
led = Pin(22, Pin.OUT) # LED (GPIO 22 가정)
TEMP_LIMIT = 25.0 # 온도 기준 (25°C 이상이면 LED 켬)
last = 0
while True:
# PIR 감지
now = pir.value()
if last == 0 and now == 1:
print("🏃♂️ 운동선수 움직임 감지! 트레이닝 시작!")
try:
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
print(f"🌡 현재 온도: {temp:.1f}°C")
print(f"💧 현재 습도: {hum:.1f}%")
# 🔥 온도에 따른 LED 제어
if temp >= TEMP_LIMIT:
led.value(1)
print("🔴 온도가 높습니다! LED 경고 켜짐!")
else:
led.value(0)
print("🟢 온도 정상입니다. LED 꺼짐.")
print()
except OSError:
print("⚠ DHT22 센서 값을 읽는 데 실패했습니다.\n")
last = now
sleep(0.1)