python - How can I run my fan if temp/humid > 26c, 60%? -
raspberry pi, a2302 sensor, 5v fan
qn how can request fan connected gpio 18 activates , stays active, until temperature sensor @ pin 5 reads either temperature of less 26 celcius, or humidity of less 60%?
#!/usr/bin/python import time import adafruit_dht import rpi.gpio gpio sensor = adafruit_dht.am2302 pin = 5 humidity, temperature = adafruit_dht.read_retry(sensor, pin) if humidity not none , temperature not none: print('temp={0:0.1f}*c humidity={1:0.1f}%'.format(temperature, humidity)) else: print('failed reading. try again!') gpio.setmode(gpio.bcm) gpio.setup(18,gpio.out) gpio.output(18, 1) time.sleep(5) gpio.output(18, 0) gpio.cleanup()
i can't provide actual code, seems want know logic use?
do following once every minute (or often): if temp< 26 turn off fan elseif hum < 60 turn off fan else keep fan on
Comments
Post a Comment