درجة الحرارة والرطوبة من DHT22 على شاشة ذات 7 قطاعات باستخدام Arduino RJT43
يُظهر هذا المشروع كيفية بناء نظام بسيط ولكنه فعّال لعرض قراءات الحرارة والرطوبة على شاشة ذات سبع مقاطع باستخدام أردوينو. هذا الإعداد مفيد لتطبيقات متنوعة حيث يكون مراقبة الظروف البيئية أمرًا حيويًا. يجمع المشروع بين حساس الحرارة والرطوبة DHT22 وشاشة ذات سبع مقاطع TM1637، مما يوفر مخرجًا واضحًا وسهل القراءة.


أفكار للمشاريع:
- مراقبة بيئة المنزل لتحقيق راحة مثلى.
- تتبع الظروف في الدفيئة أو التيراريوم
- بناء محطة أرصاد جوية أساسية.
- عرض درجة الحرارة والرطوبة في مشروع تسجيل البيانات.
الأجهزة/المكونات
لبناء هذا المشروع، ستحتاج إلى المكونات التالية:
- أردوينو أونو (أو لوحة متوافقة)
- مستشعر درجة الحرارة والرطوبة DHT22
- شاشة عرض 7-قطاعات TM1637
- أسلاك التوصيل
- لوحة التجارب (اختيارية، لكن يُوصى بها)
دليل الأسلاك



التوصيل الكهربائي بسيط. راجع الفيديو (في الفيديو عند 01:51) للحصول على دليل مرئي. التوصيلات الرئيسية هي:
- شاشة TM1637:VCC إلى 5V، GND إلى GND، CLK إلى دبوس Arduino رقم 2، DIO إلى دبوس Arduino رقم 3 (في الفيديو عند 02:00).
- مستشعر DHT22:VCC إلى 5V، GND إلى GND، DATA إلى دبوس أردوينو 9 (في الفيديو عند 02:20). لاحظ أن الفيديو يستخدم دبوس أردوينو 8 لتوفير 5V للمستشعر (في الفيديو عند 02:41).
شرح الشيفرة
يستخدم كود الأردوينو مكتبتين: TM1637Display لشاشة ذات 7 مقاطع وDHT لمستشعر DHT22. توجد المعلمات القابلة للتكوين في الكود بشكل أساسي في البداية:
// Module connection pins (Digital Pins)
#define CLK 2
#define DIO 3
#define DHTPIN 9 // DHT22 data pin
#define DHTTYPE DHT22 // DHT sensor type
تحدد هذه الأسطر دبابيس الأردوينو المتصلة بشاشة العرض ومستشعر DHT22. قد تحتاج إلى تعديلها إذا استخدمت دبابيس مختلفة. الـgetTemp()الدالة (في الفيديو عند 07:03) أساسية. تتيح لك استرجاع قيم مختلفة من حساس DHT22 عن طريق تمرير وسيطة نصية:
float getTemp(String req) {
// ... (Sensor reading code) ...
if(req =="c"){ return t; } // Celsius
else if(req =="f"){ return f; } // Fahrenheit
// ... (Other options for Kelvin, humidity, heat index) ...
}
تُبسط هذه الدالة قراءة أنواع مختلفة من بيانات المستشعر (الدرجة المئوية، الفهرنهايت، الرطوبة، مؤشر الحرارة). تستخدم الحلقة الرئيسية هذه الدالة لجلب البيانات وعرضها على الشاشة المكوّنة من 7 مقاطع، مع تقريب القيم العشرية إلى أعداد صحيحة لأغراض العرض (في الفيديو عند 07:14).
مشروع حي/عرض توضيحي
يُظهر الفيديو (في الفيديو عند 00:32) عرضًا مباشرًا للمشروع. شاشة العرض ذات 7 مقاطع تُظهر درجة الحرارة بوضوح بالفهرنهايت. كما يوضح الفيديو كيف يمكن تعديل الشيفرة لعرض قيم الدرجة المئوية والكلفن والرطوبة ومؤشر الحرارة (في الفيديو عند 08:21).
الفصول
- [00:06] مقدمة ونظرة عامة على المشروع
- [00:53] البدء ونظرة عامة على المكونات
- [01:51] توصيل أسلاك شاشة TM1637
- [02:20] توصيل أسلاك حساس DHT22
- [03:14] شرح الكود: إعداد TM1637
- [04:00] شرح الشيفرة: إعداد DHT22
- [05:54] شرح الكود: الحلقة الرئيسية ودالة العرض
- [07:03] شرح الكود: الدالة getTemp()
- [08:21] عرض توضيحي وخيارات إخراج مختلفة
/*
* Original code from TM1637 https://github.com/avishorp/TM1637
* Original code and library for DHT22 https://github.com/adafruit/DHT-sensor-library
* Modified for Robojax video on January 7, 2018
* by Ahmad Shamshiri, in Ajax, Ontario, Canada
* Watch the video for this code https://youtu.be/z_FvRm6Te78
* Other Arduino library and videos https://robojax.com
* Get this code and other Arduino codes from Robojax.com
Learn Arduino step by step in a structured course with all material, wiring diagrams, and libraries
all in one place.
If you found this tutorial helpful, please support me so I can continue creating
content like this.
or make a donation using PayPal http://robojax.com/L/?id=64
* * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.*
* This code has been downloaded from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// ****** Start of TM1637 Display code
#include <Arduino.h>
#include <TM1637Display.h>
// Module connection pins (Digital Pins)
#define CLK 2
#define DIO 3
// The amount of time (in milliseconds) between tests
#define TEST_DELAY 1000
TM1637Display display(CLK, DIO);
// ****** end of TM1637 Display code
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
// ****** Start of DHT code
#include "DHT.h"
#define DHTPIN 9 // what digital pin we're connected to
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
// ********** end of DHT22 code
void setup()
{
Serial.begin(9600);
Serial.println("DHT22 Robojax Test with Display");
pinMode(8,OUTPUT);
digitalWrite(8,HIGH);// gives 5v for DHT22
dht.begin();
}
void loop()
{
delay(TEST_DELAY);// wait
// **** TM1637 code start
display.setBrightness(0x0f);// set brightness
uint8_t data[] = { 0x0, 0x0, 0x0, 0x0 };// clear display values
display.setSegments(data);//clear display
// **** TM1637 code end
// Robojax.com test video
Serial.println(getTemp("h"));
int temp = round(getTemp("h"));
display.showNumberDec(temp, false, 3,1);
}// loop end
/*
* getTemp(String req)
* returns the temperature related parameters
* req is string request
* This code can display temperature in:
* getTemp("c") is used to get Celsius
* getTemp("f") is used to get Fahrenheit
* getTemp("k") is used for Kelvin
* getTemp("hif") is used to get Fahrenheit
* getTemp("hic") is used to get Celsius
* getTemp("h") is used to get humidity
* written by Ahmad Shamshiri for Robojax.com on January 7, 2018
* in Ajax, Ontario, Canada
*/
float getTemp(String req)
{
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (it's a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return 0.0; //return 0.0 instead of nothing.
}
// Compute heat index in Kelvin
float k = t + 273.15;
if(req =="c"){
return t;//return Celsius
}else if(req =="f"){
return f;// return Fahrenheit
}else if(req =="h"){
return h;// return humidity
}else if(req =="hif"){
return hif;// return heat index in Fahrenheit
}else if(req =="hic"){
return hic;// return heat index in Celsius
}else if(req =="k"){
return k;// return temperature in Kelvin
}else{
return 0.000;// if no request found, return 0.000
}
}
الموارد والمراجع
لا توجد موارد حتى الآن.
ملفات📁
مكتبات أردوينو (ملف مضغوط)
-
وحدة PCB DHT22 حمراء
DHT22-module-red.fzpz0.01 MB
Fritzing File
-
مستشعر الرطوبة ودرجة الحرارة DHT22
DHT22 Humidity and Temperature Sensor.fzpz0.01 MB -
وحدة PCB DHT22 حمراء
DHT22-module-red.fzpz0.01 MB -
وحدة DHT22 البيضاء
DHT22-module-white.fzpz0.01 MB -
نموذج سبعةSegments TM1637
TM1637.fzpz0.01 MB -
حساس الرطوبة ودرجة الحرارة DHT11 (3 دبابيس)
DHT11 Humitidy and Temperature Sensor (3 pins).fzpz0.20 MB
دليل المستخدم
-
دليل مستخدم حساس درجة الحرارة والرطوبة DHT22
robojax-DHT22_manual.pdf0.36 MB