Arduino 温湿度传感器DHT11示例——筑梦之路

/*
 * 接线说明:
 * - 接gnd负极
 * 中间接5V或者3.3V 正极
 * 剩下一个引脚接数字引脚 数据
 * 测量范围:温度0~50度,精度+-2 湿度20%~90%RH 精度5%RH
 * 人体承受湿度<=95%rh >=5%rh 
 * 舒适度:冬天:18~25度 30%RH~80%RH  夏天23~28度 30%~60%RH
 */

#include "DHT.h"   //引入温湿度传感器库文件
#define DHTTYPE DHT11    //定义传感器类型
#define D 8     //定义数据引脚 数字8

DHT dht(D,DHTTYPE); //初始化变量

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:
  float h = dht.readHumidity(); //读取dht湿度
  float t = dht.readTemperature(); //读取温度 摄氏度

    Serial.print("h:");
    Serial.print(h);
    Serial.print("%RH   ");
    Serial.print("t:");
    Serial.print(t);
    Serial.println("℃");
    delay(2000);
}

猜你喜欢

转载自blog.csdn.net/qq_34777982/article/details/124676602