Inconsistent sensor values

Reading an LM35 with default Aref and powering other devices (display) from the 5volt pin can result in jumping temp readings. Switching Aref to internal will fix that.

You must give the LM35 it's own ground wire.
Sharing ground with the display or breadboard won't do.

Internal 1.1volt Aref gives more stable readings and a higher 0.1C resolution.
Try this test sketch, Ignore the TMP36 lines.
Leo..

// LM35_TMP36 temp
// works on 5volt and 3.3volt Arduinos
// connect LM35 to 5volt A0 and ground
// or connect TPM36 to 3.3volt A0 and ground
// calibrate temp by changing the last digit(s) of "0.1039"

const byte tempPin = A0;
float calibration = 0.1039;
float tempC; // Celcius
float tempF; // Fahrenheit

void setup() {
  Serial.begin(9600);
  analogReference(INTERNAL); // use internal 1.1volt Aref
}

void loop() {
  tempC = analogRead(tempPin) * calibration; // use this line for an LM35
  //tempC = (analogRead(tempPin) * calibration) - 50.0; // use this line for a TMP36
  tempF = tempC * 1.8 + 32.0; // C to F
  Serial.print("Temperature is  ");
  Serial.print(tempC, 1); // one decimal place is all you get with a 10-bit A/D
  Serial.print(" Celcius  ");
  Serial.print(tempF, 1);
  Serial.println(" Fahrenheit");

  delay(1000); // use a non-blocking delay when combined with other code
}

AI advises to create an average of values. That seems to me the best. When changing AREF, the extent of the sensor is likely to change, or it would be necessary to create further wiring. But I am glad for notifying this. Thank you for your answers.

Try this sketch with "smoothing".

/*
 LM35, TMP36 thermometer, no floats, no delays
*/
const bool t36 = false; // set false for LM35, true for TMP36
const byte numSamples = 8, // number of samples for smoothing
           aInPin = A0; // analog input pin
const int calValue = 0, // adjust for calibration, +/-0.1 degree
          hAref = 110, // 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;
} 

jim-p

tomlib

1d

post #13

The TM1637 is a 4 digit 7 seg LED display. Trying another probably won't solve your problem.

Are you using a soldrless breadboard with long jumper wires?

Since you have a 10 bit ADC, having the readings fluctuare 0.5 degrees could be normal for your set-up.

Please provide details about your hardware set-up

As I said a breadboard with long wires can cause extra noise pickup.
It can also cause intermittent connection as you are now seeing.

It is with default Aref. But with 1.1volt internal Aref you can increase that to a 0.1C readout.
Oversampling (post@23) could further stabilise that.

The downside with 1.1volt Aref is the reduced temp range of about +55C.
Four digits would only makre sense for a Fahrenheit display (~130.9F max)
Celcius would only fill three digits sensibly.
Leo..