Raspberry Luftfeuchtigkeit/Temperatur: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(→Links) |
|||
Zeile 10: | Zeile 10: | ||
=Beispiel Verkabelung/Anschluss= | =Beispiel Verkabelung/Anschluss= | ||
[[Image:anschlusstempe.jpg]] | [[Image:anschlusstempe.jpg]] | ||
+ | =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 (bespiel) 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("Temp={0:0.1f}C Humidity={1:0.1f}%".format(temperature, humidity)) | ||
+ | else: | ||
+ | print("Sensor failure. Check wiring."); | ||
+ | time.sleep(3); '' | ||
+ | |||
=Links= | =Links= | ||
https://www.thegeekpub.com/236867/using-the-dht11-temperature-sensor-with-the-raspberry-pi/ | https://www.thegeekpub.com/236867/using-the-dht11-temperature-sensor-with-the-raspberry-pi/ | ||
https://www.youtube.com/watch?v=GsG1OClojOk | https://www.youtube.com/watch?v=GsG1OClojOk |
Version vom 14. Dezember 2020, 09:06 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 (bespiel) 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("Temp={0:0.1f}C Humidity={1:0.1f}%".format(temperature, humidity)) else: print("Sensor failure. Check wiring."); time.sleep(3);
Links
https://www.thegeekpub.com/236867/using-the-dht11-temperature-sensor-with-the-raspberry-pi/