STM32f103VET6搭配数字温湿度传感器 DHT11 模块QT显示温度

本文详细介绍了DHT11数字温湿度传感器的特性,包括其供电电压、输出信号类型、测量范围及精度。传感器采用单线制串行接口,易于系统集成,适用于各种应用场合。文中还提及了实际接线示例和在QT环境下显示温湿度的方法。
摘要由CSDN通过智能技术生成

数字温湿度传感器 DHT11 模块

      DHT11 数字温湿度传感器是一款含有已校准数字信号输出的温湿度复合传感器,它 应用专用的数字模块采集技术和温湿度传感技术,确保产品具有极高的可靠性和卓越的 长期稳定性。该产品具有品质卓越、超快响应、抗干扰能力强、性价比极高等优点。单线制串行接口,使系统集成变得简易快捷。超小的体积、极低的功耗,信号传输距离可 达 20 米以上,使其成为给类应用甚至最为苛刻的应用场合的最佳选择。产品为 4 针单排 引脚封装,连接方便

特点:

  1. 供电电压: 3.3~5.5V DC
  2. 输 出: 单总线数字信号
  3. 测量范围: 湿度 20-90%RH, 温度 0~50℃
  4. 测量精度: 湿度+-5%RH, 温度+-2℃
  5. 分 辨 率: 湿度 1%RH, 温度 1℃
  6. 长期稳定性: <±1%RH/年

 

S:信号线     VCC:3.3V    GND:数字地

信号线我这里接的是引脚PB13

头文件:

.c文件:

 

 

 

main()函数

 实物图:

QT显示温湿度:

好的,我可以为您提供基于Keil编写的STM32F103VET6DHT11湿度传感器的控制代码,如下所示: ```c #include "stm32f10x.h" #include "delay.h" #define DHT11_GPIO GPIOB #define DHT11_PIN GPIO_Pin_0 void DHT11_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); GPIO_InitStructure.GPIO_Pin = DHT11_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(DHT11_GPIO, &GPIO_InitStructure); GPIO_SetBits(DHT11_GPIO, DHT11_PIN); } void DHT11_Start(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); GPIO_InitStructure.GPIO_Pin = DHT11_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(DHT11_GPIO, &GPIO_InitStructure); GPIO_ResetBits(DHT11_GPIO, DHT11_PIN); delay_ms(18); GPIO_SetBits(DHT11_GPIO, DHT11_PIN); delay_us(30); GPIO_InitStructure.GPIO_Pin = DHT11_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(DHT11_GPIO, &GPIO_InitStructure); } u8 DHT11_Response(void) { u8 cnt = 0; while (GPIO_ReadInputDataBit(DHT11_GPIO, DHT11_PIN) && cnt < 100) { cnt++; delay_us(1); } if (cnt >= 100) return 1; cnt = 0; while (!GPIO_ReadInputDataBit(DHT11_GPIO, DHT11_PIN) && cnt < 100) { cnt++; delay_us(1); } if (cnt >= 100) return 1; cnt = 0; while (GPIO_ReadInputDataBit(DHT11_GPIO, DHT11_PIN) && cnt < 100) { cnt++; delay_us(1); } if (cnt >= 100) return 1; return 0; } u8 DHT11_Read_Bit(void) { u8 cnt = 0; while (GPIO_ReadInputDataBit(DHT11_GPIO, DHT11_PIN) && cnt < 100) { cnt++; delay_us(1); } if (cnt >= 100) return 1; delay_us(40); if (GPIO_ReadInputDataBit(DHT11_GPIO, DHT11_PIN)) return 1; else return 0; } u8 DHT11_Read_Byte(void) { u8 i, dat = 0; for (i = 0; i < 8; i++) { dat <<= 1; dat |= DHT11_Read_Bit(); } return dat; } u8 DHT11_Read_Data(u8 *temperature, u8 *humidity) { u8 buf[5]; u8 i; DHT11_Start(); if (DHT11_Response()) return 1; for (i = 0; i < 5; i++) buf[i] = DHT11_Read_Byte(); if ((buf[0] + buf[1] + buf[2] + buf[3]) == buf[4]) { *humidity = buf[0]; *temperature = buf[2]; return 0; } else return 1; } ``` 在以上代码中,使用了delay.h库提供的延时函数来实现精确的时间控制,需要注意的是,需要先在工程中添加delay.h和delay.c文件。 另外,在使用DHT11_Read_Data函数读取湿度数据时,需要传入温度和湿度变量的指针,以便在函数内部进行数据的存储。 希望这份代码对您有所帮助!
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值