[
/*NYU ITP - Sensor Workshop - Tom Igoe (fall 2012)
 Datalogging: Manuela Donoso & Luca Shapiro

 Test code for the Temperature Sensor TMP36
 Based on the code by Adafruit:
 http://www.ladyada.net/learn/sensors/tmp36.html
*/

int tempPin = 2; // TMP-36
int tempReading = 0;
float temperatureC = 0;
float temperatureF = 0;
const int interval = 10*100; // the interval between sensor reads, in ms
long lastReadTime = 0;        // the last time you read the sensor, in ms


void setup() {
  Serial.begin(9600);
  Serial.println ("(*C) \t(*F)");
}

void loop() {
  // get the current time in ms:
  long currentTime = millis();
  if (currentTime > lastReadTime + interval) {

    // READ TEMPERATURE
    tempReading = analogRead(tempPin);

    // convert readings to voltage, using 5V battery
    float tempVoltage = tempReading * 5;
    tempVoltage /= 1024.0;

    // now print out the temperature degrees C
    temperatureC = (tempVoltage - 0.5) * 100 ;
    Serial.println("\t"); 
    Serial.print(temperatureC);

    // now convert to Fahrenheight
    temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
    Serial.print("\t"); 
    Serial.println(temperatureF); 

    // update the time of the most current reading:
    lastReadTime = millis();
  }
}

]