חיישן טמפ דיגיטלי DHT-11
ערכה: קורס ערכת למידה IOT
זהו חיישן בעזרתו ניתן למדוד טמפרטורה וכן לחות באוויר
יש ליצור השהייה של 2 שניות בין מדידות
לשימוש ברכיב נשתמש בספריה
DHT-sensor
מתוך מנהל הספריות של הארדואינו
ניתן גם למצוא את הספריה הזו בכתובת: https://github.com/adafruit/DHT-sensor-library
#include <DHT_U.h>
#include <DHT.h>
יצירה של האובייקט
#define DHTPIN D4 // what pin we're connected to
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
בתוך SETUP נבצע אתחול של הרכיב
dht.begin();
וכאשר נרצה לבצע מדידה נוכל לעשות
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
וכך כל הקוד של תוכנית הבדיקה יהיה
//using library DHT-sensor
#include <DHT_U.h>
#include <DHT.h>
#define DHTPIN D4 // what pin we're connected to
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
// the loop function runs over and over again until power down or reset
void loop() {
delay(5000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
Serial.print("Temperature = ");
Serial.println(t);
Serial.print("Humidity = ");
Serial.println(h);
}