Raspberry Luftfeuchtigkeit/Temperatur: Unterschied zwischen den Versionen

Aus xinux.net
Zur Navigation springen Zur Suche springen
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

Brebo.jpg

              Jumper Kabel 

Jumper.jpg

              DHT11 Temp./Luftfeuchtigkeitsensor

Dht11.jpeg

Beispiel Verkabelung/Anschluss

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

https://www.thegeekpub.com/236867/using-the-dht11-temperature-sensor-with-the-raspberry-pi/

https://www.youtube.com/watch?v=GsG1OClojOk