from machine import Pin, ADC
import dht
import time
dht_sensor = dht.DHT22(Pin(15))
vibration = ADC(Pin(34))
vibration.atten(ADC.ATTN_11DB)
green = Pin(25, Pin.OUT)
yellow = Pin(26, Pin.OUT)
red = Pin(27, Pin.OUT)
while True:
dht_sensor.measure()
temp = dht_sensor.temperature()
vib = vibration.read()
print("Temp:", temp, "C | Vibration:", vib)
if temp < 50 and vib < 2000:
green.value(1)
yellow.value(0)
red.value(0)
elif (50 <= temp < 70) or (2000 <= vib < 3000):
green.value(0)
yellow.value(1)
red.value(0)
else:
green.value(0)
yellow.value(0)
red.value(1)
time.sleep(2)