Strange reading from TMP36 sensor?

Hi all,
In my troubleshooting I now have a TMP36 sensor setup in the most basic circuit on a breadboard. The TMP36 is connected to an Arduino Nano via GND, A0, and 3.3v

When I test this connection with the multimeter at both the TMP36 pin and the jumper cable at A0 on the arduino I am getting 720mV reading... which is perfect! (720 - 500) / 10 = 22C which is the exact temperature of the room I am in.

However, when I run the Arduino and check the serial monitor (running the below abridged code)

#define TMP36  A0
int reading = 0;

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

void loop() {
	reading = analogRead(TMP36);
	Serial.println(reading);
}

I am getting a reading output of ~662 ???

Without even plugging that into the mV formula (3300/1024) you can tell the number is wildly inaccurate, giving a value of over 1.9v (1900mV).

Does anyone have any idea why this is happening or what I could do to fix it? Thanks in advance all

Maybe try the correct formula?
662 / 1024 x 1.1 = 711mV

:hushed: Please where did you get this formula from? Every single page I have found online says that the formula for deriving mV from the analog reading is either (5000/1024) for 5v input and (3000/1024) for 3.3v input on TMP36 sensors???

You're using the internal 1.1V reference

Well I certainly feel foolish now, but also slightly betrayed by adafruits guide

Thanks for the lightning fast reply

Adafruit use the external reference, but you're using internal.
I don't think it's misleading, just incomplete.

1 Like

I guess I need to learn to slow down and read - I didn't even catch that I had wrote INTERNAL instead of EXTERNAL

Try my "no floats, no delays" sketch for Nano and LM35 / TMP36, measure voltage between GND and AREF pin, multiply by 100 and enter in variable hAref on line 8, fine tune with calValue on line 7.
EDIT: Fixed typo in function "antiDither", my fault :frowning_face:

/*
 LM35, TMP36 thermometer, no floats, no delays
*/
const bool t36 = true; // set false for LM35, true for TMP36
const byte numSamples = 8, // number of samples for smoothing
           aInPin = A7; // analog input pin
const int calValue = 0, // adjust for calibration, +/- 1 tenth degree C
          hAref = 109, // analog ref voltage * 100
                       // measured with accurate DMM
          hnumSamples = numSamples * 100,
          tEnd = 3000; // update time in mS
int val,
    tempC,
    tempF;
uint32_t total,  // sum of samples
         tStart; // timer start
byte cnt = 10;
        
const char header[] = "\nRaw    Total   Temp C  Temp F";
         
void setup()
{
  Serial.begin(9600);
  analogReference(INTERNAL); // use 1.1V internal ref
  analogRead(aInPin);
  for(int i = 0;i < numSamples;i++) // for smoothing, fill total
    total += analogRead(aInPin);   // with numSamples * current
                                   // reading
}
void loop()
{
  if(millis() - tStart > tEnd)
  {
    tStart = millis(); // reset timer
    if(++cnt >= 10)
    {
      Serial.println(header); // every 10 lines
      cnt = 0;
    }
    val = analogRead(aInPin);
    total -= (total / numSamples); // make room for new reading
    total += val; // add new reading
    tempC = total * hAref / hnumSamples + calValue;
    if(t36)
      tempC -= 500;
    tempC = antiDither(tempC);
    tempF = tempC * 9 / 5 + 320;
    Serial.print(val);
    Serial.print("\t");
    Serial.print(total); // sum of samples
    Serial.print("\t");
    prntTemp(tempC);
    prntTemp(tempF);
    Serial.println();
  }
}
void prntTemp(int temp)
{
  Serial.print(temp / 10); // whole degrees
  Serial.print(".");
  Serial.print(temp % 10); // tenths
  Serial.print("\t");
}
int antiDither(int newVal) // prevents +1 <-> -1 dither
{                       
  static int val = 0, oldVal = 0;
  if(newVal != val && newVal != oldVal)
  {
    oldVal = val;
    val = newVal;
  }
  return val;
}
1 Like

3 posts were split to a new topic: TMP 36 problems here

Thanks!
I solved my problem.

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