极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 15205|回复: 5

关于温度传感器的问题 求教!!!

[复制链接]
发表于 2012-2-23 23:27:24 | 显示全部楼层 |阅读模式
  1. #include <OneWire.h>  
  2. #include <DallasTemperature.h>  
  3. // Data wire is plugged into port 10 on the Arduino  
  4. #define ONE_WIRE_BUS 10
  5. int buzzer=7;//设置控制蜂鸣器的数字IO脚
  6. // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)  
  7. OneWire oneWire(ONE_WIRE_BUS);  
  8. // Pass our oneWire reference to Dallas Temperature.  
  9. DallasTemperature sensors(&oneWire);

  10. void setup(void)  
  11. {  
  12.   
  13. // start serial port  
  14. Serial.begin(9600);  
  15. Serial.println("Dallas Temperature IC Control Library Demo");  
  16. // Start up the library                                                                                                                                                                     
  17. sensors.begin();  
  18. }  
  19. void loop(void)  

  20. {  
  21. // call sensors.requestTemperatures() to issue a global temperature  
  22. // request to all devices on the bus  
  23. Serial.print("Requesting temperatures...");  
  24. sensors.requestTemperatures(); // Send the command to get temperatures  
  25. Serial.println("DONE");  
  26. Serial.print("Temperature for the device 1 (index 0) is: ");  
  27. Serial.println(sensors.getTempCByIndex(0));
  28. if(sensors.getTempCByIndex(0)<25)
  29. {
  30.       digitalWrite(buzzer,HIGH);//发声音
  31.       delay(1);//延时1ms
  32. }
  33. }
复制代码
其中的最后一段if我自己加上去的(凭空想象乱写写的) 我想取出sensors.getTempCByIndex(0)的值 如果小于25度的时候就报警 不知道咋写 HOHO
回复

使用道具 举报

发表于 2012-2-24 01:20:10 | 显示全部楼层
你先用发光二极管来代替报警器吧?
回复 支持 反对

使用道具 举报

发表于 2012-2-26 01:28:08 | 显示全部楼层
  1. if(sensors.getTempCByIndex(0)<25)
  2. {
  3.       digitalWrite(buzzer,HIGH);//发声音
  4.       delay(500);//1ms太短了,500ms比较合适
  5.       digitalWrite(buzzer,LOW);//关闭声音
  6. }
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-2-26 17:55:57 | 显示全部楼层
嗯 我先试试 板凳的代码  谢谢各位
回复 支持 反对

使用道具 举报

发表于 2012-2-27 21:14:01 | 显示全部楼层
嚯嚯 参考参考
回复 支持 反对

使用道具 举报

发表于 2012-3-5 09:41:43 | 显示全部楼层
学习中。看帖要回帖!
回复 支持 反对

使用道具 举报

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

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-29 13:35 , Processed in 0.061997 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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