当前位置:网站首页>Arduino UNO r3+LCD1602+DHT11
Arduino UNO r3+LCD1602+DHT11
2022-04-23 04:44:00 【Vivid_ Mm】
In order to save the cost of the board IO The four wire drive display connection used for the display here , Display the used LiquidCrystal library , The library can be installed directly from
IDE Under the item option in include Library Choose from manage library Mid search LCD, Install the necessary library files . It can also be in github Download zip Package to install ,URL:http://https://github.com/adafruit/Adafruit_LiquidCrystal

Code :
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int temp;// temperature
int humi;// humidity
int tol;// Proofreading code
int j;
unsigned int loopCnt;
int chr[40] = {0};// Create a numeric array , For storage 40 individual bit
unsigned long time;
#define pin 8
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
//lcd.print("hello, world!");
Serial.begin(9600);
}
void loop() {
bgn:
delay(2000);
// Set up 2 No. interface mode is : Output
// Output low level 20ms(>18ms)
// Output high level 40μs
pinMode(pin,OUTPUT);
digitalWrite(pin,LOW);
delay(20);
digitalWrite(pin,HIGH);
delayMicroseconds(40);
digitalWrite(pin,LOW);
// Set up 2 No. 1 interface mode : Input
pinMode(pin,INPUT);
// High level response signal
loopCnt=10000;
while(digitalRead(pin) != HIGH)
{
if(loopCnt-- == 0)
{
// If it does not return to high level for a long time , Output a prompt , Start over .
Serial.println("HIGH");
goto bgn;
}
}
// Low level response signal
loopCnt=30000;
while(digitalRead(pin) != LOW)
{
if(loopCnt-- == 0)
{
// If it does not return to low level for a long time , Output a prompt , Start over .
Serial.println("LOW");
goto bgn;
}
}
// Start reading bit1-40 The numerical
for(int i=0;i<40;i++)
{
while(digitalRead(pin) == LOW)
{}
// When a high level occurs , Write down the time “time”
time = micros();
while(digitalRead(pin) == HIGH)
{}
// When a low level appears , Write down the time , Then subtract the stored time
// If the value obtained is greater than 50μs, Then for ‘1’, Otherwise ‘0’
// And store it in the array
if (micros() - time >50)
{
chr[i]=1;
}else{
chr[i]=0;
}
}
// humidity ,8 Bit bit, Convert to numeric
humi=chr[0]*128+chr[1]*64+chr[2]*32+chr[3]*16+chr[4]*8+chr[5]*4+chr[6]*2+chr[7];
// temperature ,8 Bit bit, Convert to numeric
temp=chr[16]*128+chr[17]*64+chr[18]*32+chr[19]*16+chr[20]*8+chr[21]*4+chr[22]*2+chr[23];
// Proofreading code ,8 Bit bit, Convert to numeric
tol=chr[32]*128+chr[33]*64+chr[34]*32+chr[35]*16+chr[36]*8+chr[37]*4+chr[38]*2+chr[39];
// Output : temperature 、 humidity 、 Proofreading code
if(tol >= humi + temp){
Serial.print("temp:");
Serial.println(temp);
Serial.print("humi:");
Serial.println(humi);
Serial.print("tol:");
Serial.println(tol);
}else{
Serial.println("error!");
// Proofreading code , I don't use it here -
// Theoretically , humidity + temperature = Proofreading code
// If the values are not equal , It indicates that the data read is wrong .
}
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Tem(");
lcd.print((char)223);// Show o Symbol
lcd.print("C):");
lcd.setCursor(8,0);
lcd.print(temp);
lcd.setCursor(0,1);
lcd.print("Hum(");
lcd.print((char)37);// Show % Symbol
lcd.print("):");
lcd.setCursor(7,1);
lcd.print(humi);
}
版权声明
本文为[Vivid_ Mm]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220558084650.html
边栏推荐
- QML advanced (V) - realize all kinds of cool special effects through particle simulation system
- Case of using stream load to write data to Doris
- Summary of Android development posts I interviewed in those years (attached test questions + answer analysis)
- [paper reading] [3D object detection] voxel transformer for 3D object detection
- Installation and deployment of Flink and wordcount test
- Leetcode004 -- Roman numeral to integer
- [timing] empirical evaluation of general convolution and cyclic networks for sequence modeling based on TCN
- Flink case - Kafka, MySQL source
- Mysql, binlog log query
- C language: spoof games
猜你喜欢

Use recyclerview to realize left-right side-by-side classification selection

Recommended scheme of national manufactured electronic components for intelligent electronic scales

程序员抱怨:1万2的工资我真的活不下去了,网友:我3千咋说

Recommended scheme of national manufactured electronic components

Installation and use of Apache bench (AB pressure test tool)

Gut liver axis: host microbiota interaction affects hepatocarcinogenesis
![[paper reading] [3D target detection] point transformer](/img/c5/b1fe5f206b5fe6e4dcd88dce11592d.png)
[paper reading] [3D target detection] point transformer

Recommended scheme for national production of electronic components of wireless keyboard

Windows remote connection to redis

Microbial neuroimmune axis -- the hope of prevention and treatment of cardiovascular diseases
随机推荐
Coinbase:关于跨链桥的基础知识、事实和统计数据
[paper reading] [3D target detection] point transformer
Windows remote connection to redis
New terminal play method: script guidance independent of technology stack
getprop 属性
Brushless motor drive scheme based on Infineon MCU GTM module
Spark small case - RDD, broadcast
unity摄像机旋转带有滑动效果(自转)
Leetcode006 -- find the longest common prefix in the string array
Installation du compilateur croisé de la plateforme zynq
No such file or directory problem while executing shell
Eksctl deploying AWS eks
基于英飞凌MCU GTM模块的无刷电机驱动方案开源啦
mysql ,binlog 日志查询
What's the difference between error and exception
Unity camera rotation with sliding effect (rotation)
Innovative practice of short video content understanding and generation technology in meituan
Recommended scheme of national manufactured electronic components for intelligent electronic scales
io. Platform. packageRoot; // ignore: deprecated_ Member_ use
Open the past and let's start over.