Python 在raspberry pi B模型上使用DHT22控制继电器

Python 在raspberry pi B模型上使用DHT22控制继电器,python,relay,geany,adafruit,Python,Relay,Geany,Adafruit,我试图用DHT22传感器创建一个恒温器控制器。我想从传感器读取数据,并使用if语句将传感器值与设定温度值进行比较。如果实现,If语句将使用常闭出口打开继电器。下面是我在Geany编程中编写的代码,以大致了解我想做什么 from time import sleep import RPi.GPIO as GPIO import Adafruit_DHT as dht GPIO.setmode(GPIO.BCM) AC_1_GPIO = 17

我试图用DHT22传感器创建一个恒温器控制器。我想从传感器读取数据,并使用if语句将传感器值与设定温度值进行比较。如果实现,If语句将使用常闭出口打开继电器。下面是我在Geany编程中编写的代码,以大致了解我想做什么

from time import sleep

import RPi.GPIO as GPIO

import Adafruit_DHT as dht


GPIO.setmode(GPIO.BCM) 

AC_1_GPIO = 17                              #sets relay to GPIO pin 17 for AC unit control

DHT_1_GPIO = 3

GPIO.setup(AC_1_GPIO, GPIO.OUT)             #sets up GPIO to be on or off based on condition

#GPIO.setup(DHT_1_GPIO, GPIO.OUT)                           #

humdtemp = dht.read_retry(dht.DHT22, DHT_1_GPIO)

Temp_Max = 32                                           #this is temperature maximum value for tent

#Humd_Max = 60                                          #this is relative humidity maximum value for 
#Humd_Min = 30                                          #this is relative humidity mininum value for 

while True:                                           #creates continuous loop

    if humdtemp > Temp_Max:                                     #compares sensor value to maximum 
# temperature value

        GPIO.output(AC_1_GPIO, GPIO.LOW)                #turns on AC unit using controllable relay

    elif humdtemp == Temp_Max:

        print ("Achieving 72 degree temperature")     #we need to select a temperature setpoint value

    else:
        GPIO.output(AC_1_GPIO, GPIO.HIGH)               #turns 'on' normally off relay

dht.read\u retry()
返回湿度和温度的元组。将元组与整数进行比较是毫无意义的。您应该执行类似于
湿润,temp=dht.read_retry()
的操作,以便在单独的变量中获取值。您好,我能够做到这一点,并且它起到了作用。谢谢你的帮助!