找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 369|回复: 0
打印 上一主题 下一主题
收起左侧

18B20测量温度

[复制链接]
跳转到指定楼层
楼主
  1. /*
  2. 【Arduino】37种传感器模块系列实验(39)
  3. 实验三十九:DS18B20单总线数字温度传感器模块
  4. */

  5. #include <OneWire.h>
  6. #include <DallasTemperature.h>

  7. #define ONE_WIRE_BUS 3

  8. OneWire oneWire(ONE_WIRE_BUS);

  9. DallasTemperature sensors(&oneWire);

  10. void setup(void)
  11. {
  12.   Serial.begin(9600);
  13.   Serial.println("Dallas Temperature IC Control Library Demo");

  14.   sensors.begin();
  15. }

  16. void loop(void)
  17. {
  18.   Serial.print(" Requesting temperatures...");
  19.   sensors.requestTemperatures();
  20.   Serial.println("DONE");

  21.   Serial.print("Temperature for Device 1 is: ");
  22.   Serial.print(sensors.getTempCByIndex(0));  
  23.   
  24.   delay(500);
  25. }
复制代码
⸮Dallas Temperature IC Control Library Demo
Requesting temperatures...DONE
Temperature for Device 1 is: 22.31 Requesting temperatures...DONE
Temperature for Device 1 is: 22.37 Requesting temperatures...DONE
Temperature for Device 1 is: 22.31 Requesting temperatures...DONE
Temperature for Device 1 is: 22.31 Requesting temperatures...DONE
Temperature for Device 1 is: 22.37 Requesting temperatures...DONE
Temperature for Device 1 is: 22.37 Requesting temperatures...DONE
Temperature for Device 1 is: 22.37 Requesting temperatures...DONE



950.jpg (491.75 KB, 下载次数: 0)

950.jpg
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表