from machine import Pin ,ADC
import time,dht
sensor=dht.DHT22(Pin(0))
ledRed=Pin(1,Pin.OUT)
ledYellow=Pin(2,Pin.OUT)
ledGreen=Pin(3,Pin.OUT)
relayWater=Pin(4,Pin.OUT) #relay of water pump
relayLight=Pin(5,Pin.OUT) #relay of lamp of lighting
relayAir=Pin(9,Pin.OUT)
ldr=ADC(28)
temp=ADC(26)
while True:
sensor.measure()
humidity=sensor.humidity()
light=ldr.read_u16() # unsigned 0--65500
temAir=temp.read_u16()#climatisation
lightPercent=(int(light*100/65500))
if humidity<30:
ledRed.on()
ledYellow.off()
ledGreen.off()
relayWater.off()
elif 30<=humidity<60:
ledRed.off()
ledYellow.on()
ledGreen.off()
relayWater.on()
else:
ledRed.off()
ledYellow.off()
ledGreen.on()
relayWater.off()
print(lightPercent)
if lightPercent>70: #turn on the light when th light quantity
relayLight.on() #turn on the lump
else:
relayLight.off()# turn off the lamp
print(temAir)
if temAir<34232:
relayAir.on()
else:
relayAir.off()
print("Hello, Pi Pico!")