2015年12月1日

水溫感測器arduino

它要用兩個函數需下載到/usr/share/arduino/libraries/
OneWire.h的下載點:
http://playground.arduino.cc/Learning/OneWire
http://www.pjrc.com/teensy/arduino_libraries/OneWire.zip

DallasTemperature.h的下載點
https://github.com/milesburton/Arduino-Temperature-Control-Library

下載後解壓縮至 /usr/share/arduino/libraries 資料夾中
我修改
http://www.motoduino.com/products-english/?layout=edit&id=53
網站做法,使用數位腳位3,加上了如果溫度高於28度,會作動作(蜂鳴器響),每隔1秒偵測一次
開啟arduino ide
貼上下列內容

#include <OneWire.h>
#include <DallasTemperature.h>
 // Data wire is plugged into port 2 on the Arduino

#define ONE_WIRE_BUS 3

 // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)

OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.

DallasTemperature sensors(&oneWire);

void setup(void)

{
   // start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");
  pinMode( 11 , OUTPUT);
  // Start up the library
  sensors.begin();
}

void loop(void)

{
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");

  Serial.print("Temperature for the device 1 (index 0) is: ");
  Serial.println(sensors.getTempCByIndex(0));

   if (( ( (sensors.getTempCByIndex(0)) ) > ( 28 ) )) 
 {    //digitalWrite( 11 , HIGH );      

 tone(9, 250);

 }else{       

noTone(9) ;//    digitalWrite( 11 , LOW ); 

 }
  delay(1000);
}
張貼留言