DHT11 Introduced inexpensive thermo-hygrometer [DHT11](https://www.amazon.co.jp/s/ref=nb_sb_noss?__mk_ja_JP=%E3%82%AB%E3%82%BF%E3%82%AB% Introduced python library to use E3% 83% 8A & url = search-alias% 3Daps & field-keywords = DHT11 & rh = i% 3Aaps% 2Ck% 3ADHT11) quickly. Just download).
git clone https://github.com/szazo/DHT11_Python
The dht11_example.py
published above is the start program.
dht11_example.py
import RPi.GPIO as GPIO
import dht11
import time
import datetime
# initialize GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()
# read data using pin 14
instance = dht11.DHT11(pin=14)
while True:
result = instance.read()
if result.is_valid():
print("Last valid input: " + str(datetime.datetime.now()))
print("Temperature: %d C" % result.temperature)
print("Humidity: %d %%" % result.humidity)
time.sleep(1)
Recommended Posts