Basic Temperature Sensor
Basic Sensor with SD card for tracking changes in temperature. Can be submerged in water or air.
IMPORTANT: Many temperature sensors are polarized meaning that they MUST be put into the breadboard in a specific direction. Check the manufacturer notes or google your specific sensor to avoid overloading the sensor and burning yourself.

CODE
Copy & paste into Arduino IDE
// Temperature Sensor
// Spliced together from SparkFun Inventors Kit Circuit 4B and Adafruit Breakout SD Documentation.
// SPECIAL INSTRUCTIONS FOR CODE
// There are two places in which the file name is indicated. In order to change the file name, both of those places must be edited. Replace only the word "tempa"
// Sarah Cheney Whale are We Now
#include <SPI.h>
#include <SD.h>
File myFile;
float temp;
int tempPin = 0;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(10)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
}
void loop() {
temp = analogRead(tempPin);
// read analog volt from sensor and save to variable temp
temp = temp * 0.48828125;
// convert the analog volt to its temperature equivalent
Serial.print("TEMPERATURE = ");
Serial.print(temp); // display temperature value
Serial.print("*F");
Serial.println();
delay(1000); // update sensor reading each one second
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("tempa.txt", FILE_WRITE); //change file name here, if necessary
// if the file opened okay, write to it:
if (myFile) {
myFile.println(temp);
myFile.print("TEMPERATURE = ");
myFile.print(temp); // display temperature value
myFile.print("*F");
myFile.println();
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening the file");
}
// re-open the file for reading:
myFile = SD.open("tempa.txt"); //change file name here, if needed
if (myFile) {
// close the file:
myFile.close();
} else {
//if the file didn't open, print an error:
Serial.println("error opening file");
}
}
