当前位置:网站首页>arduino+DS18B20温度传感器(蜂鸣器报警)+LCD1602显示(IIC驱动)
arduino+DS18B20温度传感器(蜂鸣器报警)+LCD1602显示(IIC驱动)
2022-07-06 09:19:00 【麓南的风】
实验器材
arduino mega2560(uno及其他系列同)
ds18b20温度传感器(防水封装)
lcd1602A (节省io口,外接pcf8574,四线驱动)
杜邦线若干
介绍
ds18b20
特点:适应电压范围宽,3.0~5.5v,单线传输数据,可以多个温度传感器并在三线上,多点测量温度,短时间正负极接反时,不会烧毁芯片,但不能正常工作。
测量温度范围:-55℃~+125℃
可编程分辨率,9位到12位,分别为0.5℃,0.25℃,0.125℃,0.0625℃。默认12位精度
ds18b20,这里外接了端子适配器,如果没有端子适配器在数据端外接1k欧左右的上拉电阻即可(模块上贴片电阻也只用了472欧)
调用库,简单实现功能程序如下
其他库添加后引用同理
代码段
#include <OneWire.h>
#include <LiquidCrystal_I2C.h> //4针pcf8574驱动lcd1602库
#include <DallasTemperature.h> //ds18b20库
#define buzzpin 6 //定义蜂鸣器6号引脚
#define Onewire_bus 7 //ds18b20连接7引脚
OneWire oneWire(Onewire_bus);
DallasTemperature sensors(&oneWire);
LiquidCrystal_I2C lcd(0x27,16,2); //LCD1602的I2C地址为0x27,LCD1602为两行,每行16个字符的液晶显示器
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
lcd.init(); // 执行两次LCD的I2C通讯初始化
delay(20);
lcd.init();
delay(20);
lcd.backlight();//点亮LCD背光灯
}
void loop() {
// put your main code here, to run repeatedly:
delay(50);
Serial.print("获取温度:"); // 发送几个字
sensors.requestTemperatures(); //获取温度
Serial.println(sensors.getTempCByIndex(0));
lcd.setCursor(0, 0); // 将LCD光标移动到第一位0,0(列,行)
lcd.print("temp:");
lcd.print(sensors.getTempCByIndex(0)); // 传感器温度值
lcd.print(" C"); // 继续前面语句写入
if(sensors.getTempCByIndex(0)>40) //温度大于40报警
{
digitalWrite(buzzpin,HIGH);
}
else
{
digitalWrite(buzzpin,LOW);
}
delay(10);
}
测试
这里没有放入水中,简单触摸温度测试
串口显示
若lcd1602IIC地址不是0x27,可以通过下边程序查找一下,串口发送地址
#include <Wire.h>
void setup() {
Serial.begin (115200);
while (!Serial) { }
Serial.println ();
Serial.println ("I2C scanner.Scanning ...");
byte count = 0;
Wire.begin();
for (byte i = 8; i < 120; i++) {
Wire.beginTransmission (i);
if (Wire.endTransmission () == 0) {
Serial.print ("Found address: ");
Serial.print (i, DEC); Serial.print (" (0x");
Serial.print (i, HEX); Serial.println (")");
count++; delay (1); // maybe unneeded?
} // end of good response
} // end of for loop
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
} // end of setup
void loop() {}
(来源csdn,找不到大佬原文章了,侵删)
遇到问题
IIC地址错误
焊接的pcf8574转接板后面有个电位计,如果串口正常显示数值,lcd未显示可以调整一下电位计,lcd亮度调整后得以显示
边栏推荐
- Fgui project packaging and Publishing & importing unity & the way to display the UI
- 国企秋招经验总结
- Role movement in the first person perspective
- Dark chain lock (lca+ difference on tree)
- MySQL 30000 word essence summary + 100 interview questions, hanging the interviewer is more than enough (Collection Series
- View UI Plus 发布 1.3.1 版本,增强 TypeScript 使用体验
- String class
- Record: solution of 404 error of servlet accessing database in dynamic web project
- 10 minutes pour maîtriser complètement la rupture du cache, la pénétration du cache, l'avalanche du cache
- Tyut Taiyuan University of technology 2022 introduction to software engineering
猜你喜欢

Code example of MATLAB reading GNSS observation value o file

Several high-frequency JVM interview questions

Application architecture of large live broadcast platform

MySQL 三万字精华总结 + 面试100 问,吊打面试官绰绰有余(收藏系列

10 minutes pour maîtriser complètement la rupture du cache, la pénétration du cache, l'avalanche du cache

XV Function definition and call

Alibaba cloud side: underlying details in concurrent scenarios - pseudo sharing

TYUT太原理工大学2022数据库大题之分解关系模式
![[algorithm] sword finger offer2 golang interview question 3: the number of 1 in the binary form of the first n numbers](/img/64/0f352232359c7d44f12b20a64c7bb4.png)
[algorithm] sword finger offer2 golang interview question 3: the number of 1 in the binary form of the first n numbers

Implementation of Excel import and export functions
随机推荐
Network layer 7 protocol
记录:初次cmd启动MySQL拒接访问之解决
2-year experience summary, tell you how to do a good job in project management
Summary of multiple choice questions in the 2022 database of tyut Taiyuan University of Technology
Introduction and use of redis
系统设计学习(一)Design Pastebin.com (or Bit.ly)
Common method signatures and meanings of Iterable, collection and list
Differences and application scenarios between MySQL index clock B-tree, b+tree and hash indexes
The port is occupied because the service is not shut down normally
Exception: ioexception:stream closed
XV Function definition and call
Edit distance (multi-source BFS)
A brief introduction to the database of tyut Taiyuan University of technology in previous years
KF UD decomposition pseudo code implementation advanced [2]
[GNSS data processing] Helmert variance component estimation analysis and code implementation
[algorithm] sword finger offer2 golang interview question 8: the shortest subarray with a sum greater than or equal to K
Ten minutes to thoroughly master cache breakdown, cache penetration, cache avalanche
View UI Plus 發布 1.3.1 版本,增强 TypeScript 使用體驗
错误: 找不到符号
Record: newinstance() obsolete replacement method