Copy/Paste the code below. 

Then compile and upload it to your metro

/*
 * CIRC10: Temperature 
 * for use with both the Metro and Metro Express
 * 
 * by Brent Rubell for Adafruit Industries.    Support Open Source, buy Adafruit!
 */
 
#define ANALOGREFVOLTAGE 5.555
 
//TMP36 Pin 
int temperaturePin = A0;
 
void setup() {
  // Start the Serial connection
  Serial.begin(9600);  
}
 
void loop() {
 float temperature = 0;
 
 temperature = getVoltage(temperaturePin);
 Serial.println(temperature);
    
 // Convert to degrees C
 temperature = (temperature - .5) * 100;    
 Serial.println(temperature);
                                                            
 delay(1000);                                     
}
 
float getVoltage(int pin) { 
  
  return(float(analogRead(pin))* float(ANALOGREFVOLTAGE/1023.000));  
}

Using the Arduino Serial Monitor

Click on the magnifying glass icon on the toolbar of the Arduino IDE. You should see the serial monitor pop up and start printing out numbers. 

Not Working?

Nothing Seems to Happen

This program has no outward indication it is working. To see the results you must open the Arduino IDE's serial monitor.

Gibberish is Displayed

This happens because the serial monitor is receiving data at a different speed than expected. To fix this, click the pull-down box that reads "*** baud" and change it to "9600 baud".

Temperature Value is Unchanging

Try pinching the sensor with your fingers to heat it up or pressing a bag of ice against it to cool it down.

This guide was first published on Aug 18, 2017. It was last updated on Aug 18, 2017.
This page (Code) was last updated on Jul 03, 2020.