TMP36 Temp sensor displays wrong values

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
valicon
 
Posts: 15
Joined: Tue Jul 23, 2013 10:24 pm

TMP36 Temp sensor displays wrong values

Post by valicon »

Hi All,

I connected my TMP36 to my Arduino and no matter what I try or the code I use it tells me it is 100-150 degrees in my house or it displays negative values. I tried several code samples on line and the latest that I have tried is below. I know it has to be the code(?). Any help would be great. Thanks

Code: Select all

/*
An open-source LM35DZ Temperature Sensor for Arduino. This project will be enhanced on a regular basis
(cc) by Daniel Spillere Andrade , http://www.danielandrade.net
http://creativecommons.org/license/cc-gpl
*/

int sensorPin = 0; // analog pin
int tempc = 0,tempf=0; // temperature variables
int samples[8]; // variables to make a better precision
int maxi = -100,mini = 100; // to start max/min temperature

#define BANDGAPREF 14   // special indicator that we want to measure the bandgap

void setup()
{
  Serial.begin(9600); // start serial communication
}

void loop()
{
int refReading = analogRead(BANDGAPREF);  
  
  
  // now calculate our power supply voltage from the known 1.05 volt reading
  float supplyvoltage = (1.05 * 1024) / refReading;
  
  
  //getting the voltage reading from the temperature sensor
  int reading = analogRead(sensorPin);  

  // converting that reading to voltage
  float voltage = reading * supplyvoltage / 1024; 
 
  // print out the voltage
  
 
  // now print out the temperature
  float temperatureC = (voltage - 0.5) * 100 ;   //converting from 10 mv per degree wit 500 mV offset
                                               //to degrees ((volatge - 500mV) times 100)
  
//  Serial.println(refReading);
  //Serial.print(temperatureF); Serial.println(" degress F");
  /*
  Serial.print(supplyvoltage); //Serial.println("V power supply");
  Serial.print(voltage); Serial.print(" volts ");
  Serial.print(temperatureC); Serial.println(" degrees C");*/
  if (temperatureC!=maxi)
  {
    maxi=temperatureC;
    Serial.print(reading); Serial.print(" reading, ");
      Serial.print(supplyvoltage); Serial.print(" V power supply, ");
  Serial.print(voltage); Serial.print(" volts, ");
  Serial.print(temperatureC); Serial.println(" degrees C");
  }
 
  delay(1000);                                     //waiting a second
}
Last edited by adafruit_support_mike on Tue Oct 22, 2013 1:24 am, edited 1 time in total.
Reason: Moderator - added CODE tags

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: TMP36 Temp sensor displays wrong values

Post by adafruit_support_mike »

The code you posted uses the `AnalogRead(14)` construct to use the microcontroller's built-in bandgap voltage as a reference for the later sensor readings. IIRC, that doesn't work any more.

The offical way to do it is to call:

Code: Select all

    analogReference( INTERNAL );
Give that a try and see if you get better readings.

valicon
 
Posts: 15
Joined: Tue Jul 23, 2013 10:24 pm

Re: TMP36 Temp sensor displays wrong values

Post by valicon »

Thanks for the reply. Actually I changed the code to the code found in Lady A's tutorial and of course it worked flawlessly! One other question, if I waned to display the temperture and maybe a few other pieces of data from other sensors on the following LCD, what would I need additional in terms of parts? Also how do I keep the temperture steady? To display on the screen these data values what connections need to be made on the arduino uno? Thanks, any help would be great, still learning this stuff!

LCD
http://www.adafruit.com/products/661

User avatar
adafruit_support_bill
 
Posts: 88144
Joined: Sat Feb 07, 2009 10:11 am

Re: TMP36 Temp sensor displays wrong values

Post by adafruit_support_bill »

if I waned to display the temperture and maybe a few other pieces of data from other sensors on the following LCD, what would I need additional in terms of parts?
That display is 5v compatible, so all you need to connect it to your Arduino is some wire :) (Although a breadboard will be handy for testing).
what connections need to be made on the arduino uno?
Wiring instructions are here: http://learn.adafruit.com/monochrome-ol ... ed-display
Also how do I keep the temperture steady?
What temperature are you measuring and how are you controlling it? See this tutorial for an example of temperature control using PID: http://learn.adafruit.com/sous-vide-pow ... /sous-vide

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”