当前位置:网站首页>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
边栏推荐
- 2021数学建模国赛一等奖经验总结与分享
- Migrate from MySQL database to AWS dynamodb
- 三十六计是什么
- Microbial neuroimmune axis -- the hope of prevention and treatment of cardiovascular diseases
- Supplement 14: cmake practice project notes (to be continued 4 / 22)
- Redis command Encyclopedia
- 補:注解(Annotation)
- Small volume Schottky diode compatible with nsr20f30nxt5g
- leetcode002--将有符号整数的数字部分反转
- No such file or directory problem while executing shell
猜你喜欢

做数据可视化应该避免的8个误区

Phishing for NFT

Recommended scheme of national manufactured electronic components
![[paper reading] [3D object detection] voxel transformer for 3D object detection](/img/a2/9f66789cc12fad99491309717cf418.png)
[paper reading] [3D object detection] voxel transformer for 3D object detection

zynq平臺交叉編譯器的安裝

数据孤岛是什么?为什么2022年仍然存在数据孤岛?

Installation of zynq platform cross compiler

MySQL queries users logged in for at least N consecutive days

Recommended scheme for national production of electronic components of wireless keyboard

Experience summary and sharing of the first prize of 2021 National Mathematical Modeling Competition
随机推荐
MySQL - data read / write separation, multi instance
Programmers complain: I really can't live with a salary of 12000. Netizen: how can I say 3000
补:注解(Annotation)
What's the difference between error and exception
Unity摄像头跟随鼠标旋转
Case of using stream load to write data to Doris
Spark case - wordcount
Redis command Encyclopedia
Record the blind injection script
Recommended scheme of national manufactured electronic components for intelligent electronic scales
QML进阶(五)-通过粒子模拟系统实现各种炫酷的特效
Leetcode004 -- Roman numeral to integer
Mysql, binlog log query
Recursive call -- Enumeration of permutations
阿里十年技术专家联合打造“最新”Jetpack Compose项目实战演练(附Demo)
List&lt; Map&gt; Replication: light copy and deep copy
Create VPC in AWS console (no plate)
那些年我面试过的Android开发岗总结(附面试题+答案解析)
Youqilin 22.04 lts version officially released | ukui 3.1 opens a new experience
leetcode007--判断字符串中的括号是否匹配