TMP36 reading higher temperature

I just built my second Arduino project that includes simple temperature reading using TMP36. The project is identical to this site.

I also tested out the sensor by following the instruction above and got reading of 0.75 volt at room temperature.

But as soon as I put this in breadboard I get around 98 F degree but steady reading (+/- less than 1). My room should be around 79, 80. My conversion from Celsius is correct.

I'm using computer's USB for power and using 5 volt output. Is the noise or other factor that I didn't consider? Thanks.

I forgot to mention that I'm using Uno. Here is the code.

void loop() {

int reading = analogRead(tempPin1);

Serial.print("Raw : "); Serial.print(reading);

float voltage = reading * 5.0;
voltage /= 1024.0;

Serial.print(" : Volts : "); Serial.print(voltage);

float temperature1 = (voltage - 0.5) * 100;

Serial.print(" : Temp ('C): ");
Serial.print(temperature1);

float temperature2 = (temperature1 * 9.0 / 5.0) + 32.0;

Serial.print(" : ('F): ");
Serial.println(temperature2);

delay(1000);
}

Results are...
Raw : 176 : Volts : 0.86 : Temp ('C): 35.94 : ('F): 96.69
Raw : 176 : Volts : 0.86 : Temp ('C): 35.94 : ('F): 96.69
Raw : 176 : Volts : 0.86 : Temp ('C): 35.94 : ('F): 96.69
Raw : 176 : Volts : 0.86 : Temp ('C): 35.94 : ('F): 96.69
Raw : 177 : Volts : 0.86 : Temp ('C): 36.43 : ('F): 97.57
Raw : 176 : Volts : 0.86 : Temp ('C): 35.94 : ('F): 96.69

The USB power is not 5V but lower. However when the Arduino reads the analog value, it assumes that the 5V is 5.00V.
If the 5V is lower, the analogRead() returns a higher value.

A digital temperature sensor like the DS18B20 doesn't have that problem. But you need a library to read the temperature from the DS18B20.

You probably need to calibrate this. While attached to the arduino,

  1. Check the temp with another thermometer assumed to be sorta accurate.
  2. Check the voltage on the analog input pin.
  3. Check the raw number read by the analog input.
  4. Check your calculated temp.

Log about 4 of these (different temps), and see how they look.

scottiedog:
I just built my second Arduino project that includes simple temperature reading using TMP36.

I'm using computer's USB for power

You can get a few surprises out of the USB port and I don't think it is a good idea to trust it with an analogue device.

Either get a 9v supply or change to a digital sensor like the DS18B20.

You said

I also tested out the sensor by following the instruction above and got reading of 0.75 volt at room temperature.

Then the voltage changed to 0.86 at room temperature.
Why do you think that happened?

Thanks to all who replied.

Here are some readings....

Analog input is around 0.74 with Multimeter while UNO is running the loop with USB power from computer
Serial print says 0.86 via Serial monitor
Raw reading is 177 via analogRead()
Room thermometer is at 80
Calculated value in F is around 97 (36 C)

all values are approx to nearest integer value.

@jack wp, as suggested from the linked web site, I used two AA batteries and that read 0.75 at room temperature but Serial reading says around 0.86.

.75 vs .86 seems to be the problem.
The calculation should be modified. Or you can take several readings, and use the map() function to adjust it.

One thing I want to try is using 9V as suggested. But the reason I used USB was to feed the reading to computer so that I test the sensor and to log it there.

With that said, can I still use USB to collect data and use external power at the same time?

If not, what other method can I use to log data to computer? I can probably use Ethernet shield but trying to minimize additional hardware as I'm still new to arduino. I must be missing a big picture somewhere.

float voltage = reading * 5.0;
  voltage /= 1024.0;

Your calculation needs to be changed if you want a more accurate reading.

As Caltos suggests, I suspect you don't have a real 5.0 volts. What does your meter read for the 5.0 volt pin?

Jack, I figured that reading was necessary so I did one last night. The 5V is reading 3.26 V with Multimeter. I changed the value of 5.0 to 3.26 in code but that gave me wrong range value also. Can you help me adjust the formula?

Also, as suggested by others, I'll try using 9V external power. Hopefully, new calculation can adapt to that voltage also. Thanks for helping.

It is unusual that your 5V would be reading so low as 3.26. How are you getting your power?

You changed the formula, and it didn't read correctly, did it not go far enough, or did it go to far. Just for testing, you should be able to try other values in that formula to get a pretty close celebration, but for the long run, you should get your 5 volts, more accurate.

I'm getting power from USB via desktop computer. I'm however planning to use 9V power adapter.

Sounds like I need to calibrate by adjusting the value. But with external power of 9V, I should be ok without calibration, right?

But with external power of 9V, I should be ok without calibration, right?

Well, that is not a given. I would have assume the 5v by USB via desktop computer would have been lots closer to 5 volts.
You need to hook it up and check all the voltages, to verify they are pretty accurate, then if so, "it should be ok".

Thanks. I'll report back.

Ok, so I'm using USB to output serial value (for reporting purpose) and 9V (300mA) transformer.

Values are now more closer to actual room temperature.

Raw : 154 : Volts : 0.75 : Temp ('C): 25.20 : ('F): 77.35
Raw : 154 : Volts : 0.75 : Temp ('C): 25.20 : ('F): 77.35
Raw : 154 : Volts : 0.75 : Temp ('C): 25.20 : ('F): 77.35
Raw : 153 : Volts : 0.75 : Temp ('C): 24.71 : ('F): 76.47
Raw : 154 : Volts : 0.75 : Temp ('C): 25.20 : ('F): 77.35
Raw : 154 : Volts : 0.75 : Temp ('C): 25.20 : ('F): 77.35
Raw : 154 : Volts : 0.75 : Temp ('C): 25.20 : ('F): 77.35

It was reporting around 96 F with USB power.

Now, I figure something out. Earlier using USB power alone, I used USB hub. Now I'm using direct USB to the desktop and results are...

Raw : 158 : Volts : 0.77 : Temp ('C): 27.15 : ('F): 80.87
Raw : 158 : Volts : 0.77 : Temp ('C): 27.15 : ('F): 80.87
Raw : 158 : Volts : 0.77 : Temp ('C): 27.15 : ('F): 80.87
Raw : 158 : Volts : 0.77 : Temp ('C): 27.15 : ('F): 80.87
Raw : 158 : Volts : 0.77 : Temp ('C): 27.15 : ('F): 80.87
Raw : 159 : Volts : 0.78 : Temp ('C): 27.64 : ('F): 81.75
Raw : 158 : Volts : 0.77 : Temp ('C): 27.15 : ('F): 80.87

That's now accurate because my room thermometer is at 80. My problem solved by using direct USB rather than USB hub. Thanks to all.

You may find that the reading varies depending on what the computer is doing. You should never use 5v usb power as a voltage reference. I suggest you use the 3.3v pin as the reference instead. Read about the analogReference function.

I know this thread is very old, but having got to the bottom of the TMP36 inaccuracy problems, I wanted to share in the widest possible way.

Its not your calculations! Your multimeter, is probably fixing the problem because the TMP36 needs a load resistor. 1k from Vout to GND and it will be transformed into a reliable and (fairly) accurate sensor. Dr. Monk's DIY Electronics Blog: Accurate and Reliable Readings from a TMP36

Caltoa:
The USB power is not 5V but lower. However when the Arduino reads the analog value, it assumes that the 5V is 5.00V.
If the 5V is lower, the analogRead() returns a higher value.

A digital temperature sensor like the DS18B20 doesn't have that problem. But you need a library to read the temperature from the DS18B20.

Can anyone please expand on the first paragraph here, or point me in the direction of an explanation? Why would the USB power not be 5V, but be lower? Thanks

Using the code from the link and adjusting for my Arduino 5.0 volts which is a 4.811 volt ref the code as used in the instructable works fine and is within +/- 1.0 Degree C and converts to Deg F. just fine. When posting code please use code tags because it makes your code easier to follow. Anyway using A0 in and my own Vref here is what works.

//TMP36 Pin Variables
int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures

/* setup() - this function runs once when you turn your Arduino on. We initialize the serial connection with the computer
*/
void setup()
{
Serial.begin(9600); //Start the serial connection with the computer
//to view the result open the serial monitor
}

void loop() // run over and over again
{
//getting the voltage reading from the temperature sensor
int reading = analogRead(sensorPin);

// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = reading * 4.811 / 1024; // My V Ref

// print out the voltage
Serial.print(voltage); Serial.println(" volts");

// 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.print(temperatureC); Serial.println(" degress C");

// now convert to Fahrenheight
float temperatureF = (temperatureC * 9 / 5) + 32;
Serial.print(temperatureF); Serial.println(" degress F");

delay(1000); //waiting a second
}

On a USB note? The USB voltage is what it is to put it simply. I measure the 5 V pin on my board. That is what it is and when using a 5 volt ref in my code I adjust it accordingly. I normally use a 9 ~12 VDC external supply but still measure my Arduino 5 V pin which is then the onboard 5 volt reg output.

Sorry, initially I never caught this was an old thread. :frowning:

Ron