Stabilization of values

Hi,

I am measuring temperature with NTC10k thermistor and writting it on LCD. I am reading values of sensor for 10 times and than calculating average for better accuracy. I am writing this value to LCD with delay of one second.

I noticed that in some occasions temperature is jumping up and down (for example 35 and 36) every second. I would like to eliminate this jumping because it's very annoying.

Since I am already calculating average and writing values to LCD every second my qustion is, what approach should I use to eliminate this jumping.

It's impossible to guess what you're doing. Please post your entire sketch, inside code tags.

More averaging and slower refresh rate.. Or (if using floats) don't refresh if the difference is too small :stuck_out_tongue:

It's more likely due to truncation, but again, why guess? His examples look like integers. That's a red flag.

Instead of

int sum = 0;
for (int i = 0; i < N_SAMPLE; i++) // where N_SAMPLE <= 32
{
  sum += analogRead (sensorPin);
}
int avg = sum / N_SAMPLES;

try

int sum = N_SAMPLES / 2;  // pre-round result
for (int i = 0; i < N_SAMPLES; i++) // where N_SAMPLE <= 32
{
  sum += analogRead (sensorPin);
}
int avg = sum / N_SAMPLES;

Or, just post your code, so that we can look over it.

Below is part of my code. I am using float and than round to get it to int.

void getTemp()
{  
    const float BETA = 3950.0;     
    const float T0 = 298.15;  
    const float Ra = 10000.0;
    
    int samplesA1[10];
    int rawA1, roundNTC;
    byte counter;
    float tempNTC, rNTC;
  
    
    for (counter=0; counter<10; counter++) 
    {
      samplesA1[counter] = analogRead(A1);
    }
    
    rawA1 = 0;    
      
    for (counter=0; counter< 10; counter++) 
    {
      rawA1 += samplesA1[counter];
    }
      
    rawA1 /= 10;
    
    rNTC = (1000.0 / (1023.0 / rawA1 - 1.0));
    tempNTC = ((1.0 / (1.0 / T0 + (1.0 / BETA) * log(rNTC / Ra))) - 273.5);
    
    roundNTC = round(tempNTC);   
}

I don't understand the reason for the array of readings - do you use the values elsewhere?

AWOL:
I don't understand the reason for the array of readings - do you use the values elsewhere?

Before that I was making bubble sort. I took 10 samples, arrange them from min to max, took away the biggest and the smallest value and than calculated average of the values in array from 1 to 8 (so without 0 and 9).

But it doesn't help, temperature is still jumping from time to time.

But it doesn't help, temperature is still jumping from time to time.

It's probably "jumping" from 35.99 to 36.01. Determine what it is ACTUALLY doing, by printing the float value, not the rounded integer value.

PaulS:
It's probably "jumping" from 35.99 to 36.01. Determine what it is ACTUALLY doing, by printing the float value, not the rounded integer value.

I wrote algorithm for fixing the output. Values are updated if change occurs for more than 3 times with delay of 1 second.

 if ((roundNTC - tempNTC >= 1) || (roundNTC - tempNTC <= -1))
 {
   if (currentTime - fixTime >= 1000)
   {
     flag++;
     fixTime = currentTime;
   }
 }
 else
 {
   fixTime = currentTime;
 }
 
 if (flag >= 3)
 {
   tempNTC = roundNTC;
   flag = 0;
 }