当前位置:网站首页>Arduino温湿度传感器DHT11(含代码)
Arduino温湿度传感器DHT11(含代码)
2022-06-23 03:53:00 【Loading_create】

产品引入
在我们的日常生活中,温度和湿度对我们的生活有着很大的影响,尤其是对于工厂 的生产,如果我们不能很好的掌握并采取相关的措施,那么其带来的损失将会很大,不过现在好了,有一种传感器它不仅能测温度而且还能测湿度,那还真能解决我们的烦恼呢。好了,下面就一起来学着如何使用它,让它为您的生活带来方便。
技术参数
供电电压: 3.3~5.5V DC
输 出: 单总线数字信号
测量范围: 湿度 20-90%RH, 温度 0~50℃ 测量精度: 湿度±5%RH, 温度±2℃
分辨率: 湿度 1%RH, 温度 1℃ 长期稳定性: <±1%RH/ 年
接线
- 模块的“+”端接+5V 输出
- “-”端接 GND
- “S”端接数字端口 7 号引脚(当
然这个也可以自己定义数字引脚);接法很简单,下面就剩测试阶段了。。。。。。
int DHpin = 8;
byte dat[5];
byte read_data(){
byte data;
for(int i=0; i<8; i++){
if(digitalRead(DHpin) == LOW){
while(digitalRead(DHpin) == LOW); //等待 50us;
delayMicroseconds(30); //判断高电平的持续时间,以判定数据是‘0’还是‘1’; if(digitalRead(DHpin) == HIGH)
data |= (1<<(7-i)); //高位在前,低位在后;
while(digitalRead(DHpin) == HIGH); //数据‘1’,等待下一位的接收;
}
}
return data;
}
void start_test()
{
digitalWrite(DHpin,LOW); //拉低总线,发开始信号; delay(30); //延时要大于 18ms,以便 DHT11 能检测到开始信号; digitalWrite(DHpin,HIGH);
delayMicroseconds(40); //等待DHT11 响应; pinMode(DHpin,INPUT); while(digitalRead(DHpin) == HIGH);
delayMicroseconds(80); //DHT11 发出响应,拉低总线 80us; if(digitalRead(DHpin) == LOW);
delayMicroseconds(80); //DHT11 拉高总线 80us 后开始发送数据;
for(int i=0;i<4;i++) //接收温湿度数据,校验位不考虑; dat[i] = read_data();
pinMode(DHpin,OUTPUT);
digitalWrite(DHpin,HIGH); //发送完一次数据后释放总线,等待主机的下一次开始信号;
}
void setup()
{
Serial.begin(9600); pinMode(DHpin,OUTPUT);
}
void loop()
{
start_test();
Serial.print("Current humdity = "); Serial.print(dat[0], DEC); //显示湿度的整数位; Serial.print('.');
Serial.print(dat[1],DEC); //显示湿度的小数位; Serial.println('%');
Serial.print("Current temperature = "); Serial.print(dat[2], DEC); //显示温度的整数位; Serial.print('.');
Serial.print(dat[3],DEC); //显示温度的小数位; Serial.println('C');
delay(700);
}
好了,我们把测试代码编译一下,编译通过我们就可以看结果了,真想看看现在所 处的环境中温湿度到底是多少,它们是看不见摸不着的,我们把程序烧入 Arduino 板子,然后迫不及待的打开 Serial Monitor 窗口,看,结果出来了,哇,是不是有点兴奋!
边栏推荐
- prometheus、influxdb2.2安装及flume_export下载编译使用
- Win10 view my Ini path
- 七年码农路
- DSP7 环境
- [OFDM communication] simulation of OFDM multi-user resource allocation based on MATLAB [including Matlab source code 1902]
- 395. redundant path
- 20000 words + 20 pictures | details of nine data types and application scenarios of redis
- Can bus Basics
- 微信小程序实例开发:跑起来
- Emergency response HW review
猜你喜欢

ApiPost接口测试的用法之------Post

WPF 基础控件之 TabControl样式

Abnova liquidcell negative enrichment cell separation and recovery system

AlertManager告警的单独使用及prometheus配置告警规则使用

Please use the NLTK Downloader to obtain the resource

Object structure diagram, which can quickly illustrate the internal structure of an object

centos7部署docker,安装mysql

centos7安装postgresql8.2.15及存储过程创建

ICer技能02makefile脚本自跑vcs仿真

Can bus Basics
随机推荐
PCB placing components at any angle and distance
Shadertoy basic teaching 01. Circle drawing (explanation of smoothstep() function)
Less than a year after development, I dared to ask for 20k in the interview, but I didn't even want to give 8K after the interview~
Actual combat | multiple intranet penetration through Viper
E45: ‘readonly‘ option is set (add ! to override)
apache atlas 快速入门
Usage of API interface test ------ post
ICer技能01正则匹配
OGNL Object-Graph Navigation Language
笔者认为所谓的产业互联网,就是一个产业与互联网深度融合的过程
ICER skill 01 regular matching
Mini Homer - can you get a remote map data transmission link for hundreds of yuan?
元数据管理Apache Atlas编译(内嵌式)部署及遇到各种错误记录
Wechat applet example development: run
Thinkphp6 solving jump problems
ApiPost接口测试的用法之------Post
欢迎使用CSDN-markdown编辑器
Altium designer 09 screen printing displays a green warning near the pad. How to prevent it from alarming?
《微信小程序-基础篇》带你了解小程序的路由系统(二)
Laravel customizes the paging style through the service provider