“温度传感器 - DS18B20”的版本间的差异
来自YFRobotwiki
| (未显示1个用户的6个中间版本) | |||
| 第45行: | 第45行: | ||
<pre> | <pre> | ||
| + | |||
/**************************************** | /**************************************** | ||
| − | * DS18B20 | + | * DS18B20 Temperature measurement |
| − | * | + | * serial print the Temperature of DS18B20 |
| + | |||
| + | * http://www.yfrobot.com | ||
*****************************************/ | *****************************************/ | ||
| − | #include <OneWire.h> | + | #include <OneWire.h> |
#include <DallasTemperature.h> | #include <DallasTemperature.h> | ||
| − | + | #define ONE_WIRE_BUS 2 // define the DS18B20 data port connection arduino D2 IO | |
| − | #define ONE_WIRE_BUS 2 | + | |
| − | + | OneWire oneWire(ONE_WIRE_BUS); // Initialization single bus device | |
| − | OneWire oneWire(ONE_WIRE_BUS); | + | |
DallasTemperature sensors(&oneWire); | DallasTemperature sensors(&oneWire); | ||
| 第63行: | 第64行: | ||
void setup(void) | void setup(void) | ||
{ | { | ||
| − | + | Serial.begin(9600); // Set the baud rate | |
| − | Serial.begin(9600); | + | |
Serial.println("Dallas Temperature IC Control Library Demo"); | Serial.println("Dallas Temperature IC Control Library Demo"); | ||
| − | |||
sensors.begin(); | sensors.begin(); | ||
} | } | ||
| 第75行: | 第74行: | ||
Serial.print("Requesting temperatures..."); | Serial.print("Requesting temperatures..."); | ||
| − | sensors.requestTemperatures(); // | + | sensors.requestTemperatures(); // Send commands to take temperature |
Serial.println("DONE"); | Serial.println("DONE"); | ||
| 第82行: | 第81行: | ||
} | } | ||
| + | |||
</pre> | </pre> | ||
| + | 库文件DallasTemperature: [http://wiki.yfrobot.com/DS18B20/lib/DallasTemperature.zip DallasTemperature] [https://eyun.baidu.com/s/3bBWOEE 备用地址] | ||
| − | + | 库文件OneWire:[http://file.yfrobot.com/wiki/DS18B20/lib/OneWire.zip OneWire] [https://eyun.baidu.com/s/3cNcrPc 备用地址] | |
| − | + | 程序下载地址:[http://file.yfrobot.com/wiki/DS18B20/DS18B20.ino DS18B20.ino] [https://eyun.baidu.com/s/3mhQ5zKW 备用地址] | |
| − | + | ||
| − | + | ||
| − | [ | + | |
| 第98行: | 第96行: | ||
===参考资料=== | ===参考资料=== | ||
<br> | <br> | ||
| − | * [http:// | + | * [http://file.yfrobot.com.cn/datasheet/DS18B20%20datasheet.pdf datasheet] [https://eyun.baidu.com/s/3skJ9HN3 备用地址] |
| − | * [http:// | + | * [http://file.yfrobot.com.cn/datasheet/DS18B20%E4%B8%AD%E6%96%87%E6%89%8B%E5%86%8C.pdf DS18B20中文手册] [https://eyun.baidu.com/s/3o8FSugi 备用地址] |
| − | * [http:// | + | * [http://file.yfrobot.com.cn/wiki/DS18B20/%E5%8D%95%E6%80%BB%E7%BA%BF%E7%AE%80%E4%BB%8B.pdf 单总线简介] [https://eyun.baidu.com/s/3jI5RaMq 备用地址] |
| + | <br> | ||
---- | ---- | ||
2025年2月8日 (六) 10:21的最后版本
产品简介
温度传感器 - DS18B20模块是基于DS18B20数字温度传感器设计的模块,可用来对环境温度进行检测;DS18B20数字温度传感器是美国 DALLAS 公司生产的一总线数字温度传感器。
其测温范围-55℃~+125℃,固有测温分辨率 0.5℃,支持多点组网功能,多个DS18B20可以并联在唯一的三线上,实现多点测温,测量结果以 9~12位数字量方式串行传送。
规格参数
- 供电电压:DC3.3~5V
- 精度:±0.5℃
- 测量温度范围:-55℃ ~ 125℃
- 安装孔径:3MM
- 模块尺寸:28*21*9.4MM (长*宽*高)
- 孔间距:15MM
- 模块重量:2.2g
引脚说明
- 1. G -- Gnd(地)
- 2. V -- Vcc(电源+5V)
- 3. S -- Sign(信号)
应用示例
- 电路连接示意图
- DS18B20模块的 G、V、S分别连接 Arduino UNO的GND、VCC(+5V)、D2引脚。
- 示例代码
/****************************************
* DS18B20 Temperature measurement
* serial print the Temperature of DS18B20
* http://www.yfrobot.com
*****************************************/
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2 // define the DS18B20 data port connection arduino D2 IO
OneWire oneWire(ONE_WIRE_BUS); // Initialization single bus device
DallasTemperature sensors(&oneWire);
void setup(void)
{
Serial.begin(9600); // Set the baud rate
Serial.println("Dallas Temperature IC Control Library Demo");
sensors.begin();
}
void loop(void)
{
Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send commands to take temperature
Serial.println("DONE");
Serial.print("Temperature for the device 1 (index 0) is: ");
Serial.println(sensors.getTempCByIndex(0));
}
库文件DallasTemperature: DallasTemperature 备用地址
程序下载地址:DS18B20.ino 备用地址
参考资料
更多建议和问题欢迎反馈至 YFRobot论坛
购买方式:YFRobot 电子工作室
