Die DHT-Bibliothek installieren
Fügen Sie die Bibliothek hinzu und binden Sie sie in Ihren Sketch ein.
Die DHT-Bibliothek installieren ist eine kostenlose Arduino & IoT Academy-Lektion auf CoddyKit. Dies ist Lektion 2 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Arduino & IoT Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Arduino & IoT Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
Why Use a Library
Talking to a DHT by hand means tricky timing. A library hides that work so you can read climate data with one simple call. 📚
Open Library Manager
In the Arduino IDE, open the Library Manager from the Tools menu or the side panel. It is your store for ready-made code.
Search for DHT
Type DHT sensor library into the search box. The well-known one is published by Adafruit and works with both the DHT11 and DHT22.
It Has a Helper
The DHT library leans on the Adafruit Unified Sensor library. The IDE usually offers to install this dependency for you.
Click Install
Press Install and accept the prompt to add the dependency too. In a few seconds both libraries are ready to use.
Include It in Code
At the top of your sketch, pull the code in with #include. This line gives your program access to the DHT functions.
#include <DHT.h>Tell It Your Pin
Define which pin the sensor uses and which type you own. Clear names up top make the rest of the sketch easy to read.
#define DHTPIN 2
#define DHTTYPE DHT11Create the Object
Make a DHT object by passing your pin and type. This object is how you will ask for readings throughout the program.
DHT dht(DHTPIN, DHTTYPE);Start It in setup
Inside setup, call dht.begin() once to wake the sensor. After this line the library is ready to take measurements.
void setup() {
Serial.begin(9600);
dht.begin();
}Match Type to Hardware
Set DHTTYPE to DHT22 if that is your part. A mismatch here leads to wrong or failed readings, so pick the right one.
#define DHTTYPE DHT22Restart If Hidden
If the IDE does not see your new library right away, restart it. A fresh start makes the included header resolve cleanly.
Quick Check
You installed the DHT library. Which call belongs in setup() before you can read values?
Recap
You installed the DHT library and its helper, included the header, set your pin and type, made the object, and called begin. 🎉
Häufig gestellte Fragen
Ist die Lektion „Die DHT-Bibliothek installieren“ kostenlos?
Ja — der vollständige Text von „Die DHT-Bibliothek installieren“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Arduino & IoT Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Arduino & IoT Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Die DHT-Bibliothek installieren“?
Fügen Sie die Bibliothek hinzu und binden Sie sie in Ihren Sketch ein. Du übst Arduino & IoT Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Arduino & IoT Academy zu starten?
Keine Vorkenntnisse erforderlich. Arduino & IoT Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 4.
Wie lange dauert die Lektion „Die DHT-Bibliothek installieren“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Arduino & IoT Academy-Lektion Code schreiben und ausführen?
Ja. Jede Arduino & IoT Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- DHT11/DHT22 anschließen
- Die DHT-Bibliothek installieren
- Temperatur und Luftfeuchtigkeit auslesen
- Fehlgeschlagene Messungen behandeln