“温度传感器 - DS18B20”的版本间的差异
来自YFRobotwiki
(以“ LM35模块 === 产品简介 === <br> 温度传感器 - DS18B20模块是基于DS18B20数字温度传感器设计的模块,...”为内容创建页面) |
|||
| 第35行: | 第35行: | ||
:'''电路连接示意图''' | :'''电路连接示意图''' | ||
<br> | <br> | ||
| − | ::'''DS18B20模块'''的 G、V、S分别连接 '''Arduino UNO'''的GND、VCC(+5V) | + | ::'''DS18B20模块'''的 G、V、S分别连接 '''Arduino UNO'''的GND、VCC(+5V) 、D2 引脚。 |
| 第45行: | 第45行: | ||
<pre> | <pre> | ||
| − | // | + | /**************************************** |
| + | * DS18B20测温 | ||
| + | * 串口显示,DS18B20测得温度 | ||
| + | *****************************************/ | ||
| − | + | #include <OneWire.h> //调用单总线库文件 | |
| + | #include <DallasTemperature.h> | ||
| − | + | // 定义DS18B20数据口连接arduino的2号IO上 | |
| − | + | #define ONE_WIRE_BUS 2 | |
| − | + | ||
| − | void setup() { | + | // 初始连接在单总线上的单总线设备 |
| − | // | + | OneWire oneWire(ONE_WIRE_BUS); |
| − | Serial.begin(9600); | + | |
| − | } | + | DallasTemperature sensors(&oneWire); |
| + | |||
| + | void setup(void) | ||
| + | { | ||
| + | // 设置串口通信波特率 | ||
| + | Serial.begin(9600); | ||
| + | Serial.println("Dallas Temperature IC Control Library Demo"); | ||
| + | |||
| + | // 初始库 | ||
| + | sensors.begin(); | ||
| + | } | ||
| − | void loop() { | + | void loop(void) |
| − | + | { | |
| − | + | ||
| − | + | Serial.print("Requesting temperatures..."); | |
| − | + | sensors.requestTemperatures(); // 发送命令获取温度 | |
| − | + | Serial.println("DONE"); | |
| − | + | ||
| − | + | Serial.print("Temperature for the device 1 (index 0) is: "); | |
| − | + | Serial.println(sensors.getTempCByIndex(0)); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
} | } | ||
| + | |||
</pre> | </pre> | ||
| 第100行: | 第98行: | ||
===参考资料=== | ===参考资料=== | ||
<br> | <br> | ||
| − | * [http:// | + | * [http://wiki.yfrobot.com/DS18B20/DS18B20_datasheet.pdf DS18B20 datasheet] |
| − | * [http:// | + | * [http://wiki.yfrobot.com/DS18B20/DS18B20%E4%B8%AD%E6%96%87%E6%89%8B%E5%86%8C.pdf DS18B20中文 手册] |
| − | + | * [http://wiki.yfrobot.com/DS18B20/%E5%8D%95%E6%80%BB%E7%BA%BF%E7%AE%80%E4%BB%8B.pdf 单总线简介] | |
---- | ---- | ||
2016年8月13日 (六) 11:16的版本
产品简介
温度传感器 - 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测温
* 串口显示,DS18B20测得温度
*****************************************/
#include <OneWire.h> //调用单总线库文件
#include <DallasTemperature.h>
// 定义DS18B20数据口连接arduino的2号IO上
#define ONE_WIRE_BUS 2
// 初始连接在单总线上的单总线设备
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup(void)
{
// 设置串口通信波特率
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// 初始库
sensors.begin();
}
void loop(void)
{
Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // 发送命令获取温度
Serial.println("DONE");
Serial.print("Temperature for the device 1 (index 0) is: ");
Serial.println(sensors.getTempCByIndex(0));
}
程序下载地址:thermometer
- 串口监视结果
参考资料
更多建议和问题欢迎反馈至 YFRobot论坛
购买方式:YFRobot 电子工作室

