TMP-36 Strange Temperature Reading - Arduino Uno R3

Hi!

I am a newbie in the Arduino Community. I am trying to build a room temperature sensor circuit using the TMP-36GZ sensor. However, it keeps giving me the incorrect temperature (~250 deg C).

Would you mind helping me figure out which part of my setup is incorrect?

This is my code (I got it online):

#define aref_voltage 3.3
int tempPin = 1;
int tempReading;

void setup(void) {
  Serial.begin(9600);
  analogReference(3.3);
}

void loop(void) {
  tempReading = analogRead(tempPin);

  Serial.print("Temp reading = ");
  Serial.print(tempReading);

  float voltage=tempReading*aref_voltage;
  voltage /= 1024.0;

  Serial.print(" - ");
  Serial.print(voltage);Serial.println(" volts");

  float temperatureC = (voltage - 0.5)*100;
  Serial.print(temperatureC);Serial.println(" degrees C");

  delay(500);
}

I am using the 3.3V power source from the arduino, and a Capacitor 224 near the sensor (the yellow thing).

I also attached my setup and the output reading in this post.

Thank you!

The function analogReference() does not take a floating point literal as argument but a label that is converted to an integer. In your code the "3.3" literal would be converted to 3, an this may result in setting the voltage reference to the INTERNAL one of 1.1 V. The default setting would connect the reference to the 5V power supply of the microcontroller:

analogReference(DEFAULT)

To use the 3.3V as reference for the analog to digital converter you would have to tie the 3.3V pin to the AREF pin and use:

analogReference(EXTERNAL)

Try this.
Leo…

// TMP36 temp sensor output connected to analogue input A0
unsigned int total = 0; // A/D readings
float tempC; // Celcius
float tempF; // Fahrenheit

void setup() {
  analogReference(INTERNAL); // use the internal ~1.1volt reference | change to (INTERNAL1V1) for a Mega
  Serial.begin(9600);
}

void loop() {
  // read the sensor
  for (int x = 0; x < 64; x++) { // 64(max) analogue readings for averaging
    total = total + analogRead(A0); // add each value
  }
  // temp conversion
  tempC = total * 0.001632 - 50.0; // value to tempC >>> change last two or three digits slightly to calibrate temp <<<
  tempF = tempC * 1.8 + 32; // Celcius to Fahrenheit

  Serial.print("The temperature is  ");
  Serial.print(tempC, 1); // one decimal place
  Serial.print(" Celcius  ");
  Serial.print(tempF, 0); // no decimal places
  Serial.println(" Fahrenheit");

  total = 0; // reset total
  delay(500); // slows readings
}

vicpino:
To use the 3.3V as reference for the analog to digital converter you would have to tie the 3.3V pin to the AREF pin and use:

analogReference(EXTERNAL)

True and dangerous.
A direct connection between the Aref pin and the 3.3volt pin could fry Aref if you use the wrong code.
If you want to go that way, use a >5k resistor to link 3.3 to Aref.
That will lower Aref though. See the Aref page for more info.
Leo…

richard889: Hi!

I am a newbie in the Arduino Community. I am trying to build a room temperature sensor circuit using the TMP-36GZ sensor. However, it keeps giving me the incorrect temperature (~250 deg C).

Show us which pin on the arduino you are using (eg. photo) for the temperature sensor. Need to use one of the analog pins... eg pin 'A0' for analog reading, or pin 'A1' etc.

So pin 'A1' is the physical pin you find on the arduino that really has the label 'A1' on it. When using the 'analogRead' function, I think that analogRead(1) will mean read analog voltage from pin 'A1'.

So make sure you're not using 'digital' pin '1'.

Then..... after you use analogRead, the result is a 10 bit (1024 level) value..... such as 313. Which needs to be converted to a voltage. If the max voltage is 5V, then 313*(5V/1024) = 1.53 V

That voltage 1.53V will be linked to a temperature. But if the sensor doesn't have a table that gives us a temperature value that corresponds to 1.53, then we would need to find out the real temperature linked to this particular voltage value (eg.....borrow an accurate calibrated thermometer from somebody)..... and measure the temperature. This allows us to link 1.53 V to a real temperature.....such as 23.5 degree C (for example). For example, we use somebody's calibrated thermometer to measure a temperature of 23.5 degree. And our own temperature sensor is outputting 1.53 V at this time. This means that 1.53 V can then be associated with 23.5 degree.

This gives us a temperature 'reference' or starting point. And we 'could' (maybe) assume a linear temperature dependence (even if not) for the sensor's output voltage.

So the temperature could maybe be calculated as (for example):

temp = (voltage - voltage_for_known_temp)*known_temp + known_temp

or temp = (voltage - 1.53) * 23.5 + 23.5

So if voltage is 1.53, we'd get temp = 23.5 degrees C

If voltage were 1.6, we'd get temp = 25.15

That's just an example. The actual voltage curve for the sensor (as a function of temperature) might be something different..... so it'll be necessary to check out manufacturer data to get the right picture.