当前位置:网站首页>Arduino temperature and humidity sensor DHT11 (including code)
Arduino temperature and humidity sensor DHT11 (including code)
2022-06-23 05:10:00 【Loading_ create】

Product introduction
In our daily life , Temperature and humidity have a great influence on our life , Especially for factories The production of , If we can't master and take relevant measures , Then it will bring great losses , But now it's all right , There is a sensor which can measure not only temperature but also humidity , That can really solve our troubles . Okay , Let's learn how to use it , Let it bring convenience to your life .
Technical parameters
Supply voltage : 3.3~5.5V DC
transport Out : Single bus digital signal
measuring range : humidity 20-90%RH, temperature 0~50℃ Measurement accuracy : humidity ±5%RH, temperature ±2℃
The resolution of the : humidity 1%RH, temperature 1℃ Long term stability : <±1%RH/ year
connection
- Modular “+” Termination +5V Output
- “-” Termination GND
- “S” Terminate the digital port 7 Pin No ( When
However, you can also define the digital pin by yourself ); The connection is simple , Now there is the testing phase ......
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); // wait for 50us;
delayMicroseconds(30); // Judge the duration of high level , To determine whether the data is ‘0’ still ‘1’; if(digitalRead(DHpin) == HIGH)
data |= (1<<(7-i)); // High in the former , Low in the back ;
while(digitalRead(DHpin) == HIGH); // data ‘1’, Wait for the next bit to receive ;
}
}
return data;
}
void start_test()
{
digitalWrite(DHpin,LOW); // Pull down the bus , Send a start signal ; delay(30); // The delay should be greater than 18ms, In order to DHT11 Can detect the start signal ; digitalWrite(DHpin,HIGH);
delayMicroseconds(40); // wait for DHT11 Respond to ; pinMode(DHpin,INPUT); while(digitalRead(DHpin) == HIGH);
delayMicroseconds(80); //DHT11 Respond , Pull down the bus 80us; if(digitalRead(DHpin) == LOW);
delayMicroseconds(80); //DHT11 Pull up the bus 80us Start sending data after ;
for(int i=0;i<4;i++) // Receive temperature and humidity data , The check bit does not consider ; dat[i] = read_data();
pinMode(DHpin,OUTPUT);
digitalWrite(DHpin,HIGH); // Release the bus after sending data once , Wait for the next start signal from the host ;
}
void setup()
{
Serial.begin(9600); pinMode(DHpin,OUTPUT);
}
void loop()
{
start_test();
Serial.print("Current humdity = "); Serial.print(dat[0], DEC); // Displays the integer digits of humidity ; Serial.print('.');
Serial.print(dat[1],DEC); // Decimal places for humidity ; Serial.println('%');
Serial.print("Current temperature = "); Serial.print(dat[2], DEC); // Displays the integer digits of the temperature ; Serial.print('.');
Serial.print(dat[3],DEC); // Display decimal places of temperature ; Serial.println('C');
delay(700);
}
Okay , Let's compile the test code , After the compilation, we can see the results , I really want to see What is the temperature and humidity in the environment , They are invisible and untouchable , We burn the program into Arduino The board , Then I can't wait to open Serial Monitor window , see , And here it is , wow , Is it a little excited !
边栏推荐
- 传统意义上的互联网式的平台或将不复存在,一个融合的产业特质和互联网特质的全新产业
- "Wechat applet - Basics" takes you to understand the routing system of the applet (2)
- Emergency response HW review
- MVC三層架構
- SwiftUI 2.0 课程笔记 Chapter 5
- How to use data to tell a wonderful story?
- 2022-06-22:golang选择题,以下golang代码输出什么?A:3;B:1;C:4;D:编译失败。 package main import ( “fmt“ ) func mai
- HCIP 交换机实验
- BGP实验
- This markdown artifact will be charged!
猜你喜欢

Cloud native database is in full swing, and the future can be expected

开源生态|超实用开源License基础知识扫盲帖(下)

Icer Skill 02makefile script Running VCS Simulation

Learn to draw Er graph in an article

teqc进行GNSS数据质量分析时生成的s文件介绍

超越芯片和AI,硬科技资本为什么越来越“硬核”?

云原生数据库如荼如火,未来可期

Do280openshift command and troubleshooting -- common troubleshooting and chapter experiments

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

HCIP第五次作业
随机推荐
[OFDM communication] simulation of OFDM multi-user resource allocation based on MATLAB [including Matlab source code 1902]
Decompile
Win10 view my Ini path
The solution to prompt "this list creation could be rewritten as a list literal" when adding elements to the list using the append() method in pychart
Arduino温湿度传感器DHT11(含代码)
【OFDM通信】基于matlab OFDM多用户资源分配仿真【含Matlab源码 1902期】
ICER skills 03design compile
Install and run mongodb under win10
985测试工程师被吊打,学历和经验到底谁更重要?
1183. electricity
MVC三层架构
ICER skill 01 regular matching
PRCS-1016 : Failed to resolve Single Client Access Name
Direct insertion sort - [common sort method (1/8)]
rtklib新版本2.4.3 b34测试对比
物体结构图,快速图解物体内部结构
硬核,成为高素质测试人员:学会和产品沟通需求
Banner banner
UI自动化定位利器-xpath实战
apache atlas 快速入门