當談到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