Raspberry Luftfeuchtigkeit/Temperatur: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Zeile 25: | Zeile 25: | ||
− | import Adafruit_DHT | + | ''import Adafruit_DHT |
import time | import time | ||
− | + | DHT_SENSOR = Adafruit_DHT.DHT11 | |
− | DHT_SENSOR = Adafruit_DHT.DHT11 | ||
DHT_PIN = 4 | DHT_PIN = 4 | ||
− | + | while True: | |
− | while True: | ||
humidity, temperature = Adafruit_DHT.read(DHT_SENSOR, DHT_PIN) | humidity, temperature = Adafruit_DHT.read(DHT_SENSOR, DHT_PIN) | ||
if humidity is not None and temperature is not None: | if humidity is not None and temperature is not None: | ||
Zeile 37: | Zeile 35: | ||
else: | else: | ||
print("Stop."); | print("Stop."); | ||
− | time.sleep(3); | + | time.sleep(3);'' |
=Links= | =Links= |
Version vom 15. Dezember 2020, 10:40 Uhr
Erste Schritte
Benötigt wird:
Breadboard
Jumper Kabel
DHT11 Temp./Luftfeuchtigkeitsensor
Beispiel Verkabelung/Anschluss
Python Code
Zuerst muss die DHT python library installiert werden.
sudo pip3 install Adafruit_DHT
Sollten Probleme auftreten, muss folgender Befehl benutzt werden.
sudo apt-get install python3-dev python3-pip
sudo python3 -m pip install --upgrade pip setuptools wheel
Zum Schluss wird nur noch eine Nano Datei erstellt mit dem Namen (Beispiel) mydht11.py . Folgender Code in dieser Datei gibt dann die Luftfeuchtigkeit und die Temperatur aus:
import Adafruit_DHT
import time
DHT_SENSOR = Adafruit_DHT.DHT11
DHT_PIN = 4
while True: humidity, temperature = Adafruit_DHT.read(DHT_SENSOR, DHT_PIN) if humidity is not None and temperature is not None: print("Temperatur={0:0.1f}C Luftfeuchtigkeit={1:0.1f}%".format(temperature, humidity)) else: print("Stop."); time.sleep(3);
Links
https://www.thegeekpub.com/236867/using-the-dht11-temperature-sensor-with-the-raspberry-pi/