温度传感器DHT11实验
实验现象
读取DHT11温湿度传感器的值,然后发送给PC通过串口显示出来
理论学习
代码编写
安装DHT11库
#include <DHT.h>
DHT dht(8,DHT11);
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);
Serial.println();
Serial.print(" 温度是 : ");
Serial.println(dht.readTemperature());
Serial.print(" 湿度是 : ");
Serial.println(dht.readHumidity());
}