Copy/Paste the code below.
/* * 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)); }
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.
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".
Page last edited January 22, 2025
Text editor powered by tinymce.