当前位置:网站首页>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
边栏推荐
- What is the meaning of load balancing
- The unity camera rotates with the mouse
- 数据孤岛是什么?为什么2022年仍然存在数据孤岛?
- Druid -- JDBC tool class case
- Huawei machine test -- high precision integer addition
- 520.检测大写字母
- 補:注解(Annotation)
- getprop 属性
- Bridge between ischemic stroke and intestinal flora: short chain fatty acids
- 229. Find mode II
猜你喜欢
QML advanced (V) - realize all kinds of cool special effects through particle simulation system
520. Detect capital letters
The 14th issue of HMS core discovery reviews the long article | enjoy the silky clip and release the creativity of the video
那些年我面试过的Android开发岗总结(附面试题+答案解析)
Summary of Android development posts I interviewed in those years (attached test questions + answer analysis)
使用model.load_state_dict()时,出现AttributeError: ‘str‘ object has no attribute ‘copy‘
zynq平台交叉编译器的安装
補:注解(Annotation)
New terminal play method: script guidance independent of technology stack
Spark FAQ sorting - must see before interview
随机推荐
Logger and zap log Library in go language
General enumeration constant class
[pytoch foundation] torch Split() usage
Supplement: Annotation
Eight misunderstandings that should be avoided in data visualization
win10, mysql-8.0.26-winx64.zip 安装
Small volume Schottky diode compatible with nsr20f30nxt5g
补充番外14:cmake实践项目笔记(未完待续4/22)
L2-011 玩转二叉树(建树+BFS)
Key points of AWS eks deployment and differences between console and eksctl creation
The 14th issue of HMS core discovery reviews the long article | enjoy the silky clip and release the creativity of the video
What is the meaning of load balancing
协程与多进程的完美结合
Ali's ten-year technical experts jointly created the "latest" jetpack compose project combat drill (with demo)
leetcode009--用二分查找在数组中搜索目标值
leetcode004--罗马数字转整数
RC低通滤波器的逆系统
做数据可视化应该避免的8个误区
[paper reading] [3D target detection] point transformer
第四章 --- 了解标准设备文件、过滤器和管道