当前位置:网站首页>【Arduino connects DHT11 humidity and temperature sensor】
【Arduino connects DHT11 humidity and temperature sensor】
2022-08-02 04:32:00 【WENJIE Technology】
Arduino 连接DHT11 湿度和温度传感器
前言
DHT11 The module has a temperature and humidity sensor complex,With calibrated digital signal output.Unique digital signal acquisition technology and temperature and humidity sensing technology ensure high reliability and excellent long-term stability.The sensor includes one for temperature measurement NTC and a resistive humidity measurement component for humidity measurement.They are connected to high performance 8 位微控制器,Provide excellent quality、快速的响应、Anti-jamming capability and cost-effectiveness.
DHT11 模块引脚
DHT11 模块共有 3 个引脚.Two of them are for power,one for communication.DHT11 Sensor The pinout of the module is as follows:
DHT11 模块
DHT11 Modules have very few parts,包括 DHT11、上拉电阻、Bypass capacitor and power supply with current limiting resistor LED.
DHT11模块电路图
DHT11 The schematic diagram of the module is shown below.如前所述,The board has a very low number of components.VCC 和 GND 直接连接到 DHT11,并且在 DATA A pull-up resistor is added to the pin.Tantalum capacitors and multilayer capacitors provide adequate filtering.with current limiting resistors LED Used as a power indicator.
关于 DHT11 Common problems with sensors
问:DHT11 有什么作用?
DHT11 is a basic、Ultra low cost digital temperature and humidity sensor.它使用电容式湿度传感器和热敏电阻来测量周围的空气,并通过 1-wire 协议发送数据.
问:DHT11 的准确度如何?
DHT11 可以测量 0-50⁰C 的温度,精度为 2%,The relative humidity measurement range is 20-80%,精度为 5%.
问:DHT11 防水吗?
不,it is not waterproof.
问:DHT11 What is the sampling rate of the sensor?
DHT11 的采样率为 1Hz.
DHT11 是如何工作的?
The humidity sensing assembly consists of a moisture retaining substrate sandwiched between two electrodes.When the substrate absorbs moisture,The resistance between the two electrodes will decrease.The change in resistance between the two electrodes is proportional to the relative humidity.较高的相对湿度会降低电极之间的电阻,而较低的相对湿度会增加电极之间的电阻.使用板载 MCU 的 ADC Measure resistance change and calculate relative humidity.
每个DHT11Components are rigorously calibrated in the laboratory,Humidity calibration is extremely accurate.The calibration coefficients are stored as a program OTP 存储器中,Used for the sensor's internal signal detection process.
DHT11 1-Wire 通讯协议
The single-bus data format is used MCU 和 DHT11 Communication and synchronization between sensors.A communication process is approx4ms.The data consists of a fractional part and an integer part.The complete data transfer is 40bit,The sensor sends the high-order data first.数据格式如下:8bit积分RH数据+8bit十进制RH数据+8bit积分T数据+8bit十进制T数据+8bit校验和.If the data transfer is correct,The checksum should be“8bit RH 积分+8bit RH 十进制数据+8bit 积分T 数据+8bit 十进制T 数据”的最后8bit.
当 MCU 发出启动信号时,DHT11 从低功耗模式切换到运行模式,等待 MCU 完成启动信号.完成后,DHT11 会向 MCU 发送一个包含相对湿度和温度信息的 40 位数据的响应信号.用户可以选择收集(读取)一些数据.没有来自 MCU 的启动信号,DHT11 不会给 MCU 响应信号.数据采集完毕后,DHT11 将切换到低功耗模式,直到再次收到来自 MCU 的启动信号.The figure above shows the communication timing diagram.
将 DHT11 传感器与 Arduino Connected circuit diagram
Now we have it all DHT11 传感器的工作原理,我们可以将所有必需的电线连接到 Arduino and write the code to get all the data from the sensor.下图显示了将 DHT11 sensor module with Arduino Connected circuit diagram.连接非常简单,Only three wires are required.将模块的 VCC 和 GND 连接到 Arduino 的 5V 和 GND 引脚.然后将 DATA 引脚连接到 Arduino 的数字引脚 2.We pass this pin with DHT11 通信.
Used to connect sensor modules Arduino DHT11 代码
Now let's look at connections DHT11 The code for the sensor.为此,First install through the library manager Adafruit 的DHT sensor library and Adafruit Unified sensor driver.
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTTYPE DHT11 // DHT 11
#define DHTPIN 2
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;
一开始,We have included all necessary libraries,and define the sensor type as DHT11,Define the sensor pins as digital pins 2.然后为 DHT The library creates an instance.A variable is also created to declare the minimum delay.
void setup() {
Serial.begin(9600);
dht.begin();
sensor_t sensor;
delayMS = sensor.min_delay / 1000;
}
在setup函数中,We have initialized serial communication and DHT 库.Then there is the minimum delay for data refresh.
void loop()
{
sensors_event_t event;
dht.temperature().getEvent(&event);
Serial.print(F("Temperature: "));
Serial.print(event.temperature);
Serial.println(F("°C"));
dht.humidity().getEvent(&event);
Serial.print(F("Humidity: "));
Serial.print(event.relative_humidity);
Serial.println(F("%"));
delay(delayMS);
}
在循环函数中,We create an event,and use that event from DHT11 Sensors read temperature and humidity data.Then print that value to the serial monitor.下图显示了 DHT11 界面.
code and library files
The code and library files have been uploaded to the personal homepage.
边栏推荐
猜你喜欢
随机推荐
MVC,MVP和MVVM架构解析
svg图片实战:自定义view打造中国地图
关于我的项目-实现一个数据库~
张量乘积—实验作业
Jetpack中各个组件简介
【Arduino连接GPS 模块 (NEO-6M)读取定位数据】
kotlin语法总结(二)
[Spark]-RDD详解之变量&操作
MQ-5 可燃气体传感器与 Arduino 接口
深度学习实战(1):花的分类任务
【NTC 热敏电阻与 Arduino 读取温度】
TimeSformer视频理解框架:视频理解中的Transformer
【opencv】error: (-215:Assertion failed) ssize.empty() in function ‘cv::resize‘报错原因
面试必备:Android性能分析与优化实战进阶手册
Go中的一些优化笔记,简约而不简单
kotlin语法总结(一)
【MQ-2 可燃气体和烟雾传感器与 Arduino 配合使用】
无源域适应(SFDA)方向的领域探究和论文复现(第一部分)
树莓派4B打开文件管理时出现闪退
修复APP的BUG,热修复的知识点和大厂的相关资料汇总