difference in readings from temperature sensor (between LM35 and TMP36)

Hi,

I was setting up a simple temperature reading using the sensor, I've both LM35 and TMP36
as first thing I've to say that for LM35 I accidentally set the pin in reverse order and when I realized it was a bit overheated

this is the code I use

#include <Board_Identify.h>

void setup()
{
  Serial.begin(9600); //set serial baud at 9600
  pinMode(A2,INPUT); //set analogue A4 as input
  Serial.print(F("Board Type: "));
  Serial.println(BoardIdentify::type); 
  Serial.print(F("Board Make: "));
  Serial.println(BoardIdentify::make); 
  Serial.print(F("Board Model: "));
  Serial.println(BoardIdentify::model); 
  Serial.print(F("Board MCU: "));
  Serial.println(BoardIdentify::mcu); 

}

void loop()
{
  float calcVolt, calcCelsius;
  int sampleValue = analogRead(A2); // Sample the value of A2

  Serial.print(sampleValue); //print the sampled value in the serial monitor
  Serial.print("\t");//tab
  calcVolt = float(sampleValue) * 0.0049; //calculate the voltage
  Serial.print(calcVolt);//print the voltage value
  Serial.print("V\t");
  calcCelsius = (calcVolt-.5)*100; //calculate Celsius
  Serial.print(calcCelsius);//print Celsius degree temperature
  Serial.print("C");
  Serial.print("\t");//tab
  cel2Fahr(calcCelsius);//convert in Fahrenheit
  delay(2000);             
              
}
  
  void cel2Fahr(float celsius){
    Serial.print((celsius*1.8)+32);//convert in Fahreneit
    Serial.println("F");
                }

There are the results with TMP36
Board Type: 2
Board Make: Arduino
Board Model: Arduino/Genuino Uno
Board MCU: ATmega328P
145 0.71V 21.05C 69.89F
144 0.71V 20.56C 69.01F
144 0.71V 20.56C 69.01F
143 0.70V 20.07C 68.13F
144 0.71V 20.56C 69.01F
144 0.71V 20.56C 69.01F
144 0.71V 20.56C 69.01F
145 0.71V 21.05C 69.89F
143 0.70V 20.07C 68.13F

These with LM35
Board Type: 2
Board Make: Arduino
Board Model: Arduino/Genuino Uno
Board MCU: ATmega328P
48 0.24V -26.48C -15.66F
47 0.23V -26.97C -16.55F
47 0.23V -26.97C -16.55F
47 0.23V -26.97C -16.55F
47 0.23V -26.97C -16.55F
47 0.23V -26.97C -16.55F
47 0.23V -26.97C -16.55F
47 0.23V -26.97C -16.55F
47 0.23V -26.97C -16.55F
46 0.23V -27.46C -17.43F

The breadboard set is the same, I just change the sensor

I would ask if there is something wrong I'm doing in the code, so if it should be changed for the different sensors, or if the LM35 is just damaged

Thank you all for the patience of going through a long post
(details of the board are print in the Serial monitor output)

I don't believe that the Arduino code can be used interchangeably with those two sensors. Study the examples more carefully.

for LM35 I accidentally set the pin in reverse order and when I realized it was a bit overheated

For certain it was damaged. It may still do something, but you should not trust it. We all make those mistakes, so don't worry, just get a new one.

For the TMP36:

calcCelsius = (calcVolt-.5)*100; //calculate Celsius

For the LM35:

calcCelsius = calcVolt * 100; // leave out the "- .5"

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.