عرض درجة الحرارة والرطوبة

مبتدئ

image_pdf

الكود البرمجي للأردوينو

أولا نحن بحاجة إلى تثبيت مكتبة الـDHT  التي يمكنك تنزيلها من  هنا أو من الموقع الرسمي اردوينو هنا. ثم يتم تحديد رقم المنفذ لقراءة البيانات من المستشعر.

ثم قم برفع البرنامج التالي على الاردوينو:

#include  <LiquidCrystal.h> // includes the LiquidCrystal Library
#include <dht.h>
#define dataPin A0
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Creates an LCD object. Parameters: (rs, enable, d4, d5, d6, d7)
dht DHT;
void setup() {
  lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display
}
void loop() {
  int readData = DHT.read11(dataPin);
  float t = DHT.temperature;
  float h = DHT.humidity;
  lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed
  lcd.print("Temp.: "); // Prints string "Temp." on the LCD
  lcd.print(t); // Prints the temperature value from the sensor
  lcd.print((char)223); //degree symbol
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Humi.: ");
  lcd.print(h);
  lcd.print(" %");
  delay(2000);
}

لمحة عن الكود :

سيتم استخدام الدالة ()read11 ليتم قراءة البيانات من المستشعر

int readData = DHT.read11(dataPin);

 ثم الحصول على قيم درجة الحرارة و الرطوبة و يتم وضع القيم في متغيرات.

float t = DHT.temperature; 
float h = DHT.humidity;
X
تم إضافة المنتج إلى السلة بنجاح