2017-08-14 94 views
0

树莓裨,A2302传感器,5V风扇如何在温度/湿度> 26c,60%的情况下运行风扇?

QN如何可以请求我的风扇连接到GPIO 18个激活,并在销5保持活跃,直到从我的传感器的温度读取或者小于26的温度或者湿度低于60%?

#!/usr/bin/python 
import time 
import Adafruit_DHT 
import RPi.GPIO as GPIO 

sensor = Adafruit_DHT.AM2302 
pin = 5 
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) 

if humidity is not None and temperature is not None: 
    print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity)) 
else: 
    print('Failed to get 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() 

回答

0

我无法提供实际的代码,但它似乎只是想知道要使用的逻辑?

do the following once every minute (or however often): if temp< 26 turn off fan elseif hum < 60 turn off fan else keep fan on

+0

谢谢,我明白,如果其他的功能,但是我的语法,将特别适合已经写好的代码的情况下后。这不起作用,因为“每分钟做一次以下”并没有用任何特定的定时功能来定义,也没有“临时”或“嗡嗡声”。 – amx5

相关问题