当前位置:网站首页>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亮度调整后得以显示
边栏推荐
- How do architects draw system architecture blueprints?
- View UI Plus 发布 1.2.0 版本,新增 Image、Skeleton、Typography组件
- Application architecture of large live broadcast platform
- Error: sorting and subscript out of bounds
- 【话题终结者】
- Common method signatures and meanings of Iterable, collection and list
- 如何保障 MySQL 和 Redis 的数据一致性?
- Dark chain lock (lca+ difference on tree)
- Application architecture of large live broadcast platform
- WSL common commands
猜你喜欢
面渣逆袭:Redis连环五十二问,三万字+八十图详解。
IPv6 experiment
Alibaba cloud microservices (IV) service mesh overview and instance istio
One article to get UDP and TCP high-frequency interview questions!
What are the advantages of using SQL in Excel VBA
MySQL 30000 word essence summary + 100 interview questions, hanging the interviewer is more than enough (Collection Series
Application architecture of large live broadcast platform
The port is occupied because the service is not shut down normally
2022 National Games RE1 baby_ tree
阿里云微服务(二) 分布式服务配置中心以及Nacos的使用场景及实现介绍
随机推荐
First acquaintance with C language (Part 2)
Smart classroom solution and mobile teaching concept description
MySQL Database Constraints
Rt-ppp test using rtknavi
Quickly generate illustrations
Realization of the code for calculating the mean square error of GPS Height Fitting
2年经验总结,告诉你如何做好项目管理
TYUT太原理工大学2022数据库大题之分解关系模式
[algorithm] sword finger offer2 golang interview question 9: subarray with product less than k
12 excel charts and arrays
View UI Plus 发布 1.2.0 版本,新增 Image、Skeleton、Typography组件
MySQL backup -- common errors in xtrabackup backup
Introduction and use of redis
Shortest Hamilton path (pressure DP)
Conceptual model design of the 2022 database of tyut Taiyuan University of Technology
Several high-frequency JVM interview questions
Inheritance and polymorphism (Part 2)
Employment of cashier [differential constraint]
A brief introduction to the database of tyut Taiyuan University of technology in previous years
[dry goods] cycle slip detection of suggestions to improve the fixed rate of RTK ambiguity