108个传感器之- 温湿度模块DHT11(14)

108个传感器之- 温湿度模块DHT11(14)

介绍

DHT11传感器是紧凑设计的温度和湿度传感器的组合。它以±2°C的精度测量0°C至50°C的温度,以±5%的精度测量20%至90%的相对湿度。由于其低采样率,该传感器每两秒钟只提供一次新的读数,使其成为长期测量的理想选择。DHT11易于集成到Arduino和Raspberry Pi等微控制器平台中,并且由于工厂校准,不需要额外的校准。其稳健的设计和可靠性使其成为温室、气候控制系统和仓库监控等连续监测项目的最佳选择。

Technical Data
Chipset DHT11
Communication Protocol 1-Wire
Measuring range 0 °C to 50 °C
Measurement accuracy ±2 °C
Measurement Accuracy ±5 % RH
Measurable humidity 20-90 % RH

引脚连接

pin 引脚连接开发板的 gpio 接口即可:

Arduino Sensor
pin 2 Signal
- +V
GND GND

代码示例

1. 普通版

该案例用到以下两个库:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>

#define DHTPIN A2
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
dht.begin();
}

void loop() {
delay(1000);
// Humidity is measured
float humidity = dht.readHumidity();
// Temperature is measured
float temperature = dht.readTemperature();
// Checks whether the measurements have run through without errors
// If an error is detected, an error message is output here
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Error when reading out the sensor");
return;
}
// Output to the serial console
Serial.println("-----------------------------------------------------------");
Serial.print(" Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print(" Temperature: ");
Serial.print(temperature);
Serial.println(" °C ");
Serial.println("-----------------------------------------------------------");
Serial.println(" ");
}

小结

待完善…

108个传感器之- 温湿度模块DHT11(14)

http://blog.jzxer.cn/20241218/20241219-temprature-wet/

作者

dev

发布于

2024-12-18

更新于

2025-01-15

许可协议

评论

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×