当前位置:网站首页>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亮度调整后得以显示
边栏推荐
- 165. Compare version number - string
- Network layer 7 protocol
- Error: sorting and subscript out of bounds
- TYUT太原理工大学2022数据库大题之概念模型设计
- Exception: ioexception:stream closed
- [algorithm] sword finger offer2 golang interview question 4: numbers that appear only once
- Employment of cashier [differential constraint]
- [GNSS] robust estimation (robust estimation) principle and program implementation
- [algorithm] sword finger offer2 golang interview question 12: the sum of the left and right sub arrays is equal
- Dark chain lock (lca+ difference on tree)
猜你喜欢

2年经验总结,告诉你如何做好项目管理

Tyut Taiyuan University of technology 2022 introduction to software engineering summary

阿里云一面:并发场景下的底层细节 - 伪共享问题
![[untitled]](/img/b1/9a2bebebb24132a405fc4e7d854e51.png)
[untitled]

2-year experience summary, tell you how to do a good job in project management
![Fundamentals of UD decomposition of KF UD decomposition [1]](/img/e9/564e0163c3756c0ba886913f1cfaef.jpg)
Fundamentals of UD decomposition of KF UD decomposition [1]

Basic DOS commands
![[algorithm] sword finger offer2 golang interview question 12: the sum of the left and right sub arrays is equal](/img/11/ee0628a68542236fc641966579a31a.png)
[algorithm] sword finger offer2 golang interview question 12: the sum of the left and right sub arrays is equal

Problems and solutions of robust estimation in rtklib single point location spp

Common method signatures and meanings of Iterable, collection and list
随机推荐
2-year experience summary, tell you how to do a good job in project management
记录:初次cmd启动MySQL拒接访问之解决
View UI Plus 发布 1.3.0 版本,新增 Space、$ImagePreview 组件
Problems and solutions of robust estimation in rtklib single point location spp
System design learning (I) design pastebin com (or Bit.ly)
First acquaintance with C language (Part 1)
【快趁你舍友打游戏,来看道题吧】
System design learning (III) design Amazon's sales rank by category feature
Differences and application scenarios between MySQL index clock B-tree, b+tree and hash indexes
167. Sum of two numbers II - input ordered array - Double pointers
What are the advantages of using SQL in Excel VBA
面渣逆袭:Redis连环五十二问,三万字+八十图详解。
MySQL 30000 word essence summary + 100 interview questions, hanging the interviewer is more than enough (Collection Series
分支语句和循环语句
Solution: warning:tensorflow:gradients do not exist for variables ['deny_1/kernel:0', 'deny_1/bias:0',
错误:排序与角标越界
[algorithm] sword finger offer2 golang interview question 4: numbers that appear only once
Pride-pppar source code analysis
[algorithm] sword finger offer2 golang interview question 5: maximum product of word length
IText 7 generate PDF summary