当前位置:网站首页>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亮度调整后得以显示
边栏推荐
- 几道高频的JVM面试题
- View UI Plus 发布 1.1.0 版本,支持 SSR、支持 Nuxt、增加 TS 声明文件
- Heap sort [handwritten small root heap]
- 121道分布式面试题和答案
- 2-year experience summary, tell you how to do a good job in project management
- [rtklib 2.4.3 B34] version update introduction I
- Realization of the code for calculating the mean square error of GPS Height Fitting
- 十分鐘徹底掌握緩存擊穿、緩存穿透、緩存雪崩
- Voir ui plus version 1.3.1 pour améliorer l'expérience Typescript
- Experience summary of autumn recruitment of state-owned enterprises
猜你喜欢

What are the advantages of using SQL in Excel VBA

阿里云微服务(二) 分布式服务配置中心以及Nacos的使用场景及实现介绍

Fairygui bar subfamily (scroll bar, slider, progress bar)

Chromatic judgement bipartite graph

系统设计学习(三)Design Amazon‘s sales rank by category feature

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

One article to get UDP and TCP high-frequency interview questions!

C code implementation of robust estimation in rtklib's pntpos function (standard single point positioning spp)

TYUT太原理工大学2022数据库题库选择题总结

Common method signatures and meanings of Iterable, collection and list
随机推荐
Introduction pointer notes
The port is occupied because the service is not shut down normally
面渣逆袭:Redis连环五十二问,三万字+八十图详解。
如何保障 MySQL 和 Redis 的数据一致性?
图书管理系统小练习
TYUT太原理工大学2022软工导论考试题型大纲
Sharing ideas of on-chip transplantation based on rtklib source code
记录:Navicat Premium初次无法连接数据库MySQL之解决
[algorithm] sword finger offer2 golang interview question 4: numbers that appear only once
Database operation of tyut Taiyuan University of technology 2022 database
View UI plus released version 1.2.0 and added image, skeleton and typography components
《软件测试》习题答案:第一章
Redis介绍与使用
GNSS positioning accuracy index calculation
面试必备:聊聊分布式锁的多种实现!
[rtklib 2.4.3 B34] version update introduction I
记录:初次cmd启动MySQL拒接访问之解决
Inheritance and polymorphism (I)
Counter attack of flour dregs: redis series 52 questions, 30000 words + 80 pictures in detail.
Quickly generate illustrations