#author("2022-09-08T13:09:10+09:00","default:okada","okada")
*DHT11を使用してみる [#v6ebc871]
 
RIGHT:更新日 &lastmod();

Arduinoを使用してDHT11で温度、湿度を測定してみる
Arduinoを使用してDHT11(VDD 3,3V-5.5V)で温度、湿度を測定してみる

**必要ファイルのDownload [#ka6549a5]

adafruitのオープンソースの[[DHT-sensor-library(ダウンロード)>https://github.com/adafruit/DHT-sensor-library/archive/master.zip]]をダウンロードする。

***以下の手順でインストール [#cd14b661]

&ref("./Add_Lib1.png");

&ref("./Add_Lib2.png");

以下のように「DHT sensor library」があることを確認

&ref("./Add_Lib3.png");


-「Adafruit_Sensor.h」のインストール

&ref("./Add_Lib4.png");

&ref("./Add_Lib5.png");

&ref("./Add_Lib6.png");


**サンプルファイル [#b52db866]

DHT11からのデータをシリアルモニタに表示する

接続図

&ref("./配線図.png");

''プログラム''

 #include <DHT.h>
 #include <DHT_U.h>
 
 /*
  * DHT11センサー
  * Arduinoのデジタル2ピンでDHT11センサーを接続する
  */
 
 #define DHT11_PIN 2 
 
 DHT dht(DHT11_PIN, DHT11);
 unsigned long ti;
 
 void setup() {
   // put your setup code here, to run once: 
 
   Serial.begin(9600);
   dht.begin();
 
   
 }
 
 void loop() {
   // put your main code here, to run repeatedly:
   delay(2000);
 
   ti = millis();
  
   // 湿度
   float humidity = dht.readHumidity();
   // 温度
   float temperature = dht.readTemperature();
 
   if (isnan(humidity) || isnan(temperature)) {
     Serial.println("センサーから読み取りに失敗しました。");
     return;
   }
  
   // 体感温度
 
   Serial.print(ti);
   float heatIndex = dht.computeHeatIndex(temperature, humidity, false);
  
   Serial.print("温度:");
   Serial.print(temperature);
   Serial.print("℃ 湿度:");
   Serial.print(humidity);
   Serial.print("% 体感温度:");
   Serial.print(heatIndex);
   Serial.println("℃");
 }

**シリアルモニタ [#k97dd884]

&ref("./シリアルモニタ.png");


**Arduino基板図 [#rc4387cc]

&ref("./Pin配置.png");


**参考 [#ib6a4961]

-https://www.petitmonte.com/robot/howto_dht11.html



トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS