2016年4月22日 星期五

ds18b20溫度感測器

詳細教學可參考阿簡生物筆記
利用防水的溫度感測計可進行有關熱量變化的實驗耶,會考後讓9年級玩玩。

下載函式庫

OneWire(https://goo.gl/DMRdxi)

Arduino-Temperature-Control-Library

解壓縮後分別放到Arduinosketchbook下的libraries目錄裡。

DS18B20
藍線或黃線接D2
紅線接5V
黑線或灰接GND
還要在紅線藍線之間再加一個4.7k的電阻








  // 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");
  // After we got the temperatures, we can print them here.
  // We use the function ByIndex, and as an example get the temperature from the first sensor only.
 // Serial.print("Temperature for the device 1 (index 0) is: ");
  Serial.println(sensors.getTempCByIndex(0));  

}

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  //Serial.println("Dallas Temperature IC Control Library Demo");
  Serial.println("CLEARDATA");
  Serial.println("LABEL,Time,Timer,Temperature,val,");
  // Start up the library
  sensors.begin();
}
/*
 * Main function, get and show the temperature
 */
void loop(void)
{
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println(sensors.getTempCByIndex(0));
  Serial.print("DATA,TIME");
  Serial.print(",");
  Serial.print("TIMER");
  Serial.print(",");
  Serial.println(sensors.getTempCByIndex(0));
  delay(100);
}

ds18b20並聯8支(第9支就會出現負數)應該是極限
放進溫水中
將2支改放入熱水
抽離也可測氣溫
PLX-DAQ收集數據




沒有留言:

張貼留言