Temperature Sensor Not Reading Correctly


I have the TMP36 temperature sensor (Temperature Sensor - TMP36 - SEN-10988 - SparkFun Electronics) and I have it on my analog 0 (A0) pin. Now I have tried multiple ways to convert my temperature from analog signal to an actual temperature reading.

I have 3.3V as my supply from the UNO all I have is the temp sensor with power to 3.3V , GND to GND of the Uno and my emitter to A0 , I've tried A2 as well and I get the same results. I'm getting negative temperature when it should be about 16 C.

The code I'm using is below, any insight or direction would be greatly appreciated !

EDIT: With my multimeter from the emitter (PIN2) of the TMP36, I get .72V consistently. I checked that it's also getting 3.3V, but my analog read comes back as "145" when I think it should be around "230". Unless I did my calculation wrong, thought this might help.

int tempPin = A0;
void setup(){

void loop(){
    int tempRead = analogRead(tempPin);
    Serial.print("Temp Sensor Bits: "); Serial.print(tempRead);
    float tempVolt = (float(tempRead) / 1024)*3.3; 
    Serial.print("Temp in Volts: "); Serial.print(tempVolt);
    float tempCelsius = (tempVolt * 100)-50;
    Serial.print("Temp: "); Serial.println(tempCelsius);


I changed my code from this line:

float tempVolt = (float(tempRead) / 1024)*3.3;

To this line:

float tempVolt = (float(tempRead) / 1024)*5.0;

and I now see the proper volts reading on my serial monitor that was displayed on my multimeter. But I don't understand why I would do this? Doesn't the new line assume I am using 5V power supply, when I am powering my temperature sensor with 3.3V?


You are coding this in a room of only 16 degrees ? That's cold !

You use "float(tempRead)", is that Java style programming ?
In normal 'c', you can cast an integer to float with "(float) tempread".

I suggest to use integers where you use integers, and float where you have floats. I even would like to use "100.0" and "50.0", just to indicate that everything is done with float numbers.

Can you try this:

    // read the raw ADC value of 0...1023
    int tempRead = analogRead(tempPin);
    // print the raw ADC value, in integer.
    Serial.print("Temp raw ADC: "); 

    // The raw ADC value is converted to a float.
    // Everything is from now on calculated with float.
    float tempVolt = (float) tempRead / 1024.0 * 3.3; 
    Serial.print(", Temp in Volts: ");
    float tempCelsius = (tempVolt * 100.0) - 50.0;
    Serial.print(", Temp: "); 

Can you make a photo of the connected sensor. Did you accidently exchange a pin or two ?
Tutorial : Using a Temp Sensor | TMP36 Temperature Sensor | Adafruit Learning System

Thank you so much getting back to me Peter_n, I'm going to try the code and if all else fails, I will send the picture. I am getting a little desperate so really appreciate your reply.

I probably even open another thread about a differential pressure sensor that doesn't seem to 1. want to work or 2. adjust it's values when changes (but that's another issue and I'm pretty it's in my code with map and constrain)

BUT one thing at a time, I'll try this code and let you know how it goes. :smiley:

Hey Peter_n ,

Tried the code, and I'm producing results that I did previously. I get negative temperature values. I posted a picture of the code and the results side by side, also here is a picture of my hardware setup.

Any ideas?

Could you set the baudrate in your sketch to 115200 ?

Everything seems okay, but I can't see to which pin the +V pin is connected.
When you are using +5V to the TMP36, the raw ADC value of 136 is for 16 degrees. You already wrote about that, and I really think that you have used the +5V for the TMP36.

Do you have a very bad and not-calibrated multimeter ?
Or is the Arduino running at USB power from a laptop ? Perhaps the 5V is a lot less than 5.0V.
To avoid trouble of the USB power, you could try a power supply to the DC power barrel jack of 7.5 to 12V.

Thanks for the speedy reply!

My Arduino is powered from a USB in my laptop, and I'm just using the 3.3V pin on the UNO to power my TMP36. Which is why in the code I did:

float tempVolt = (float) tempRead / 1024.0 * 3.3; ,

but this produced the negative results that you saw in the picture. I checked and I getting a consistent 3.3V , I have the other side of my bread powered with 5V, which the TMP36 doesn't have any connection with other than the common ground.

When I switch 3.3 to 5 in the code above, it seems to be working. And I get the results that I attached below. If these results are correct, awesome, but that just means it's freezing in here; which would make some sense. But it's still powered by 3.3V.

It doesn't make sense at all. Perhaps the TMP36 is damaged. The output is unreliable, so I would not continue with it. You can wrap some plastic around it and put it in icy-water and boiling water, just to see what it is doing. Can you get a new TMP36, or perhaps a new Arduino board, or test it on another computer, a desktop computer ? Some laptops have low and weak usb power.

You could also use a simple diode and measure the forward voltage and calculate the temperature. The Uno has to be set to internal reference of 1.1V for that. I get 2 or 3 degrees accuracy with a single diode.

The DS18B20 is a digital temperature sensor, it has not those troubles with voltages. That could be the next step. The DS18B20 (temperature) and the BMP085 or BMP180 (barometer) are very cheap and very good sensors.

So I guess the most recent picture I posted was accurate according to the bits? I'll go to my local electronics store now and get a new temp sensor. I'll let you know in a couple hours how it goes.

EDIT : I forgot I had a temp sensor in my arduino starter kit. I'm going to see it works with the code you posted and powered with 3.3V. I'll post again in a minute.

Hey Peter_n,

You were right on both accounts, faulty sensor kept reading 17 degrees and a faulty multimeter which kept reading the wrong voltage off of the middle pin.

New sensor, different volt meter, both the voltage on the Serial monitor and the multimeter match giving me 14 C !

Thanks again for all the help, I feel silly and bad that I wasted time, but glad to know things are working.


I'm glad it is working :slight_smile:
It's not a waste of time, because it is working now. It just the way things go sometimes. What a weird coincidence that a faulty sensor would give a reasonable temperature if it would have been 5V !

Yea that actuall is very strange, and you are right things like do happen and I am glad it's working :smiley: