当前位置:网站首页>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亮度调整后得以显示
边栏推荐
- [algorithm] sword finger offer2 golang interview question 10: subarray with sum K
- MySQL 30000 word essence summary + 100 interview questions, hanging the interviewer is more than enough (Collection Series
- 记录:动态Web项目servlet访问数据库404错误之解决
- 4.30动态内存分配笔记
- Tyut Taiyuan University of technology 2022 introduction to software engineering
- Network layer 7 protocol
- Code example of MATLAB reading GNSS observation value o file
- 阿里云微服务(四) Service Mesh综述以及实例Istio
- 几道高频的JVM面试题
- Tyut Taiyuan University of technology 2022 introduction to software engineering summary
猜你喜欢
Detailed explanation of balanced binary tree is easy to understand
阿里云微服务(四) Service Mesh综述以及实例Istio
TYUT太原理工大学2022软工导论大题汇总
String class
[algorithm] sword finger offer2 golang interview question 4: numbers that appear only once
Application architecture of large live broadcast platform
一文搞定 UDP 和 TCP 高频面试题!
系统设计学习(二)Design a key-value cache to save the results of the most recent web server queries
MySQL 三万字精华总结 + 面试100 问,吊打面试官绰绰有余(收藏系列
Smart classroom solution and mobile teaching concept description
随机推荐
Error: sorting and subscript out of bounds
Edit distance (multi-source BFS)
The earth revolves around the sun
Data manipulation language (DML)
TYUT太原理工大学2022数据库大题之概念模型设计
2年经验总结,告诉你如何做好项目管理
MySQL Database Constraints
阿里云微服务(一)服务注册中心Nacos以及REST Template和Feign Client
记录:newInstance()过时的代替方法
Exception: ioexception:stream closed
Share a website to improve your Aesthetics
Record: newinstance() obsolete replacement method
2022 National Games RE1 baby_ tree
记录:Navicat Premium初次无法连接数据库MySQL之解决
Counter attack of flour dregs: redis series 52 questions, 30000 words + 80 pictures in detail.
Smart classroom solution and mobile teaching concept description
View UI Plus 發布 1.3.1 版本,增强 TypeScript 使用體驗
162. Find peak - binary search
String类
Alibaba cloud microservices (III) sentinel open source flow control fuse degradation component