当前位置:网站首页>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 窗口,看,结果出来了,哇,是不是有点兴奋!
边栏推荐
- Win10 view my Ini path
- Dsp7 environment
- Altium designer 09 screen printing displays a green warning near the pad. How to prevent it from alarming?
- dolphinscheduler 2.0.5 spark 任务测试总结(源码优化)
- Abnova PSMA bead solution
- Reinstallation of cadence16.3, failure and success
- Do280openshift command and troubleshooting -- common troubleshooting and chapter experiments
- 396. mine site construction
- Is data scientist a promising profession?
- Banner banner
猜你喜欢

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~

Shadertoy基础教学01、画圆(smoothstep()函数讲解)

Flask Foundation: environment setup + configuration + mapping between URL and attempt + redirection + database connection

Official download and installation of QT and QT vs tools plug-ins

美团好文:从预编译的角度理解Swift与Objective-C及混编机制

Abnova acid phosphatase (wheat germ) instructions

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

Non return to zero code NRZ

【毕业季_进击的技术er】送别过去两年迷茫的自己。重整旗鼓,大三我来啦

OGNL Object-Graph Navigation Language
随机推荐
How to make social media the driving force of cross-border e-commerce? This independent station tool cannot be missed!
Question bank and answers of 2022 hoisting machinery safety management examination
Abnova abcb10 (human) recombinant protein specification
【图论】—— 二分图
ICer技能01正则匹配
ICER skills 03design compile
How to better organize the minimum web api code structure
电流继电器HDL-A/1-110VDC-1
Flask Foundation: environment setup + configuration + mapping between URL and attempt + redirection + database connection
如何更好地组织最小 WEB API 代码结构
聊聊 C# 中的 Composite 模式
《微信小程序-基础篇》带你了解小程序的路由系统(二)
微信小程序:土味情话恋爱话术
1183. electricity
20000 words + 20 pictures | details of nine data types and application scenarios of redis
Magnetoresistive saturation
Abnova liquidcell negative enrichment cell separation and recovery system
【论文阅读】Semi-Supervised Learning with Ladder Networks
Const understanding one
Wechat applet example development: run