0Pricing
Arduino & IoT Academy · درس

تثبيت مكتبة DHT

أضف المكتبة وضمّنها في sketch الخاص بك.

تثبيت مكتبة DHT درس مجاني في Arduino & IoT Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Arduino & IoT Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Arduino & IoT Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

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 DHT11

Create 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 DHT22

Restart 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. 🎉

الأسئلة الشائعة

هل درس «تثبيت مكتبة DHT» مجاني؟

نعم — نص درس «تثبيت مكتبة DHT» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Arduino & IoT Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Arduino & IoT Academy 4 دروس في المجموع.

ماذا ستتعلم في «تثبيت مكتبة DHT»؟

أضف المكتبة وضمّنها في sketch الخاص بك. تتمرن على Arduino & IoT Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Arduino & IoT Academy؟

لا تُشترط خبرة سابقة. Arduino & IoT Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.

كم من الوقت يستغرق درس «تثبيت مكتبة DHT»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Arduino & IoT Academy هذا؟

نعم. كل درس في Arduino & IoT Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. توصيل DHT11/DHT22
  2. تثبيت مكتبة DHT
  3. قراءة درجة الحرارة والرطوبة
  4. معالجة القراءات الفاشلة
← العودة إلى Arduino & IoT Academy