利用防水的溫度感測計可進行有關熱量變化的實驗耶,會考後讓9年級玩玩。
下載函式庫
OneWire(https://goo.gl/DMRdxi)
Arduino-Temperature-Control-Library
解壓縮後分別放到Arduino的sketchbook下的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));
}
藍線或黃線接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);
}
沒有留言:
張貼留言