[王老師玩ESP32系列]第三課,DHT11溫度檢測


1. 介紹
用溫度傳感器 DHT11 檢測溫度2. 硬件
    2.1      ESP32 開發板
                DHT11 溫度傳感器
    2.2      接線

     [ESP32 IO14 - DHT22 DATA]
     [ESP32 GND - DHT22 GND]
     [ESP32 GND - DHT22 GND]
  2.3 接線圖

    <ignore_js_op style='color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: "Microsoft YaHei", SimHei, Verdana, Arial, sans-serif; font-size: 14px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; -ms-word-wrap: break-word; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;'> 
3.軟件

 

#include "DHT.h"
//here we use pin IO14 of ESP32 to read data
#define DHTPIN 14
//our sensor is DHT22 type
#define DHTTYPE DHT22
//create an instance of DHT sensor
DHT dht(DHTPIN, DHTTYPE);
void setup() {
  Serial.begin(115200);
  Serial.println("DHT22 sensor!");
  //call begin to start sensor
  dht.begin();
}
 
void loop() {
  //use the functions which are supplied by library.
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // print the result to Terminal
  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.println(" *C ");
  //we delay a little bit for next read
  delay(2000);
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM