×

Arduino代码的DHTxx

消耗积分:2 | 格式:zip | 大小:0.06 MB | 2023-01-05

mintsy

分享资料个

描述

我需要检查空调房的确切温度,以显示空调房与遥控器上显示的不一样。所以我决定做这个。

您将需要 x1 面包板(可选)

x1 套电线

x1 dhtxx

x1 Arduino uno

所以连接(从左到右)

引脚 1 至 5v

引脚 2 到数字引脚 7

引脚 3(留下它)

引脚 4 接地

它将以 C、F、K 和湿度显示

这里的代码

谢谢

//Libraries
#include ;
//#include:
//Constants
#define DHTPIN 7     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
//Variables
int chk;
float hum;  //Stores humidity value
float temp; //Stores temperature value
float faran;
float kel;
void setup()
{
 Serial.begin(9600);
 dht.begin();
}
void loop()
{
   delay(2000);
   //Read data and store it to variables hum and temp
   hum = dht.readHumidity();
   temp= dht.readTemperature();
   //Print temp and humidity values to serial monitor
   Serial.print("Humidity : ");
   Serial.print(hum);
   Serial.println(" %");
   Serial.print("Temp     :");
   Serial.print(temp);
   Serial.println(" Celsius");
   faran = (temp * 9.0) / 5.0 + 32;
   Serial.print("Faranheit: ");
   Serial.print(faran);
   Serial.println(" F");
   kel = temp + 273.15;
   Serial.print("Kelvin: ");
   Serial.print(kel);
   Serial.println(" K");
   Serial.println("");
   Serial.println("");
   delay(5000); //Delay 5 sec
  // This is free and unencumbered software released into the public domain Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OROTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OROTHER DEALINGS IN THE SOFTWARE.
//For more information, please refer to }

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !