当谈到Python和Raspberry Pi单元时,我是一个完整的noob,但我正在计算它。Raspberry-pi-DHT11 +中继触发器
我正在编写一个脚本来监视我正在建造的温室的当前温度。当温度达到28C时,我想让它激活我的继电器,它将打开风扇。在26℃时,继电器应关闭。
生成信息: 树莓派3 DHT11 tempurature - GPIO引脚20 单继电器板 - GPIO引脚21
import RPi.GPIO as GPIO
import dht11
import time
import datetime
from time import sleep
# initialize GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()
# Set relay pins as output
GPIO.setup(21, GPIO.OUT)
# read data using pin 20
instance = dht11.DHT11(pin=20)
while True:
result = instance.read()
tempHI = 28
tempLOW = 26
if result >= tempHI
GPIO.output(21, GPIO.HIGH) #turn GPIO pin 21 on
ifels result < tempLOW
GPIO.output(21, GPIO.LOW) #Turn GPIO pin 21 off
time.sleep(1)
当前的错误我得到:
python ghouse.py
File "ghouse.py", line 19
result = instance.read()
^
IndentationError: expected an indented block
Python使用缩进来分组块。阅读https://docs.python.org/release/3.4.3/tutorial/introduction.html#first-steps-towards-programming并使用Python感知编辑器。然后在行'while True:'下面添加四个空格。 – Dietrich