当前位置:网站首页>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 !
边栏推荐
猜你喜欢

怎样利用数据讲一个精彩故事?

微信小程序:拼图工具箱

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

Separate use of alertmanager alarms and use of Prometheus configuration alarm rules

Dolphin scheduler 2.0.5 task test (spark task) reported an error: container exited with a non zero exit code 1

《微信小程序-基础篇》带你了解小程序的路由系统(二)

STP总结

Dolphin scheduler 2.0.5 spark task test summary (source code optimization)

dolphinscheduler 1.2.1 数据迁移到 dolphinscheduler 2.0.5方法及迁移后数据测试记录

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
随机推荐
[graph theory] - bipartite graph
云原生数据库如荼如火,未来可期
Official download and installation of QT and QT vs tools plug-ins
Kail infiltration basic literacy basic command
Install and run mongodb under win10
[C language] keyword
图片降噪DeNoise AI
AlertManager告警的单独使用及prometheus配置告警规则使用
百度飞桨“万有引力”2022首站落地苏州,全面启动中小企业赋能计划
ICER skill 01 regular matching
Beyond chips and AI, why is hard technology capital becoming more and more "hard core"?
Object structure diagram, which can quickly illustrate the internal structure of an object
Separate use of alertmanager alarms and use of Prometheus configuration alarm rules
The solution to prompt "this dictionary creation could be rewritten as a dictionary literal" when updating the dictionary key value in pychart
How to use data to tell a wonderful story?
Win10 view my Ini path
[OFDM communication] simulation of OFDM multi-user resource allocation based on MATLAB [including Matlab source code 1902]
MVC three-tier architecture
servlet自学笔记
PHP move_uploaded_file上传移动图片失败