temperature data that fluctuates rapidly

Hi all
I have a simple piece of code that reads pin A0 then some simple math then output to the serial monitor, however the data moves up and down by a few degrees. When I measure the output with a multimeter and the serial monitor OFF, the output is quite stable, some movement is expected as the AD595 is a sensitive device. With the meter still connected I switch the serial monitor on and I see an increase of a couple of degrees or so and see the instability again.
Do I need to fiddle with an ADC or perform some kind of smoothing? Or do I need some thing electronic? Could use some help with this please, here is the code I am using:-

float temp ;

 void setup(){

Serial.begin(9600);
}
 void loop()
{

int raw = analogRead(A0);

float Vout = raw * (5 / 1023.0);

temp = (Vout) / 0.01;

Serial.println(temp);

delay(500);
}

Stable readings depend on two things.

#1 The AD595’s output voltage.
#2 Default 5volt Aref voltage.

#2 might be the biggest problem.

What is the temp range you’re after.

Does 300C give ~3volts, as in the datasheet.

You could drop the AD595’s output voltage to <=1.1volt.
And read sensor voltage with the internal 1.1volt Aref enabled.
Once you have stable readings, you can improve it with smoothing.

Here’s an example I wrote for the TMP35 with LCD.
Maybe you can adapt it for your sensor.
Leo…

// TMP35 temp sensor connected to Analogue input A1, 3.3volt and ground
// or LM35 temp sensor connected to A1, 5volt and ground
// temp range ~2C to ~105C
// display on serial monitor and/or LCD
// for a TMP36 (-40C to ~55C), change line 45 to:   tempC = total * Aref * 0.1 / numReadings - 50.0;
//
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // your LCD pins could be different
byte ledPin = 10; // backlight pin
const byte numReadings = 25; // number of readings for smoothing (max 64)
int readings[numReadings]; // readings from the analog input
byte index = 0; // index of the current reading
unsigned int total = 0; // running total
int inputPin = A1; // the pin that the TMP35 is connected to
float Aref = 1.0759; // change this value to the actual Aref voltage of ---YOUR--- Arduino (1.0 - 1.2), or adjust to get accurate readings
float tempC; // Celcius
float tempF; // Fahrenheit

void setup() {
  //analogWrite(ledPin, 200); // optional dimming
  analogReference(INTERNAL); // use the internal ~1.1volt reference | change (INTERNAL) to (INTERNAL1V1) for a Mega
  Serial.begin(115200); // ---set serial monitor to this value---
  lcd.begin(16, 2); // shield with 2x16 characters
  lcd.print("Thermometer"); // info text
  lcd.setCursor(0, 1); // second row
  lcd.print("0-100 Celcius");
  for (index = 0; index < numReadings; index++) { // fill the array for faster startup
    readings[index] = analogRead(inputPin);
    total = total + readings[index];
  }
  index = 0; // reset
  delay(2000); // info display time
}

void loop() {
  total = total - readings[index]; // subtract the last reading
  readings[index] = analogRead(inputPin); // one unused reading to clear ghost charge
  readings[index] = analogRead(inputPin); // read from the sensor
  total = total + readings[index]; // add the reading to the total
  index = index + 1; // advance to the next position in the array
  if (index >= numReadings) // if we're at the end of the array
    index = 0; // wrap around to the beginning

  // convert value to temp
  tempC = total * Aref * 0.1 / numReadings; // value to celcius conversion
  tempF = tempC * 1.8 + 32; // Celcius to Fahrenheit conversion

  // print to LCD
  if (total == 1023 * numReadings) { // if overflow
    lcd.clear();
    lcd.print("---TOO HOT---");
  }
  else {
    lcd.clear();
    lcd.print(tempC, 2); // two decimal places
    lcd.setCursor(6, 0); // position 6, first row
    lcd.print("Celcius");
    lcd.setCursor(0, 1); // second row
    lcd.print(tempF, 1); // one decimal place
    lcd.setCursor(6, 1); // position 6, second row
    lcd.print("Fahrenheit");
  }

  // print to serial monitor
  Serial.print("Raw average = ");
  Serial.print(total / numReadings);
  if (total == 1023 * numReadings) {
    Serial.println("  ----too hot----");
  }
  else {
    Serial.print("   The temperature is  ");
    Serial.print(tempC, 2);
    Serial.print(" Celcius  ");
    Serial.print(tempF, 1);
    Serial.println(" Fahrenheit");
  }

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

Wawa:
Stable readings depend on two things.

#1 The AD595’s output voltage.
#2 Default 5volt Aref voltage.

#2 might be the biggest problem.

What is the temp range you’re after.

Does 300C give ~3volts, as in the datasheet.

You could drop the AD595’s output voltage to <=1.1volt.
And read sensor voltage with the internal 1.1volt Aref enabled.
Once you have stable readings, you can improve it with smoothing.
https://www.arduino.cc/en/Tutorial/Smoothing

Here’s an example I wrote for the TMP35 with LCD.
Maybe you can adapt it for your sensor.
Leo…

// TMP35 temp sensor connected to Analogue input A1, 3.3volt and ground

// or LM35 temp sensor connected to A1, 5volt and ground
// temp range ~2C to ~105C
// display on serial monitor and/or LCD
// for a TMP36 (-40C to ~55C), change line 45 to:   tempC = total * Aref * 0.1 / numReadings - 50.0;
//
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // your LCD pins could be different
byte ledPin = 10; // backlight pin
const byte numReadings = 25; // number of readings for smoothing (max 64)
int readings[numReadings]; // readings from the analog input
byte index = 0; // index of the current reading
unsigned int total = 0; // running total
int inputPin = A1; // the pin that the TMP35 is connected to
float Aref = 1.0759; // change this value to the actual Aref voltage of —YOUR— Arduino (1.0 - 1.2), or adjust to get accurate readings
float tempC; // Celcius
float tempF; // Fahrenheit

void setup() {
 //analogWrite(ledPin, 200); // optional dimming
 analogReference(INTERNAL); // use the internal ~1.1volt reference | change (INTERNAL) to (INTERNAL1V1) for a Mega
 Serial.begin(115200); // —set serial monitor to this value—
 lcd.begin(16, 2); // shield with 2x16 characters
 lcd.print(“Thermometer”); // info text
 lcd.setCursor(0, 1); // second row
 lcd.print(“0-100 Celcius”);
 for (index = 0; index < numReadings; index++) { // fill the array for faster startup
   readings[index] = analogRead(inputPin);
   total = total + readings[index];
 }
 index = 0; // reset
 delay(2000); // info display time
}

void loop() {
 total = total - readings[index]; // subtract the last reading
 readings[index] = analogRead(inputPin); // one unused reading to clear ghost charge
 readings[index] = analogRead(inputPin); // read from the sensor
 total = total + readings[index]; // add the reading to the total
 index = index + 1; // advance to the next position in the array
 if (index >= numReadings) // if we’re at the end of the array
   index = 0; // wrap around to the beginning

// convert value to temp
 tempC = total * Aref * 0.1 / numReadings; // value to celcius conversion
 tempF = tempC * 1.8 + 32; // Celcius to Fahrenheit conversion

// print to LCD
 if (total == 1023 * numReadings) { // if overflow
   lcd.clear();
   lcd.print("—TOO HOT—");
 }
 else {
   lcd.clear();
   lcd.print(tempC, 2); // two decimal places
   lcd.setCursor(6, 0); // position 6, first row
   lcd.print(“Celcius”);
   lcd.setCursor(0, 1); // second row
   lcd.print(tempF, 1); // one decimal place
   lcd.setCursor(6, 1); // position 6, second row
   lcd.print(“Fahrenheit”);
 }

// print to serial monitor
 Serial.print(“Raw average = “);
 Serial.print(total / numReadings);
 if (total == 1023 * numReadings) {
   Serial.println(”  ----too hot----”);
 }
 else {
   Serial.print("   The temperature is  “);
   Serial.print(tempC, 2);
   Serial.print(” Celcius  “);
   Serial.print(tempF, 1);
   Serial.println(” Fahrenheit");
 }

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



[firstly thanks for your reply. The range I am looking for is ambient to 650C it's for a tandoor, I think I understand what your saying in principle and am going to try, but am still wet behind the ears with no sign of drying up any day soon! and yes with just my multimeter attached the reading is stable allowing for air currents and at 300c I do get 3v. Any more thoughts will be gratefully received/quote]

andymouse:

Wawa:
Stable readings depend on two things.

#1 The AD595’s output voltage.
#2 Default 5volt Aref voltage.

#2 might be the biggest problem.

What is the temp range you’re after.

Does 300C give ~3volts, as in the datasheet.

You could drop the AD595’s output voltage to <=1.1volt.
And read sensor voltage with the internal 1.1volt Aref enabled.
Once you have stable readings, you can improve it with smoothing.
https://www.arduino.cc/en/Tutorial/Smoothing

Here’s an example I wrote for the TMP35 with LCD.
Maybe you can adapt it for your sensor.
Leo…

// TMP35 temp sensor connected to Analogue input A1, 3.3volt and ground

// or LM35 temp sensor connected to A1, 5volt and ground
// temp range ~2C to ~105C
// display on serial monitor and/or LCD
// for a TMP36 (-40C to ~55C), change line 45 to:  tempC = total * Aref * 0.1 / numReadings - 50.0;
//
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // your LCD pins could be different
byte ledPin = 10; // backlight pin
const byte numReadings = 25; // number of readings for smoothing (max 64)
int readings[numReadings]; // readings from the analog input
byte index = 0; // index of the current reading
unsigned int total = 0; // running total
int inputPin = A1; // the pin that the TMP35 is connected to
float Aref = 1.0759; // change this value to the actual Aref voltage of —YOUR— Arduino (1.0 - 1.2), or adjust to get accurate readings
float tempC; // Celcius
float tempF; // Fahrenheit

void setup() {
  //analogWrite(ledPin, 200); // optional dimming
  analogReference(INTERNAL); // use the internal ~1.1volt reference | change (INTERNAL) to (INTERNAL1V1) for a Mega
  Serial.begin(115200); // —set serial monitor to this value—
  lcd.begin(16, 2); // shield with 2x16 characters
  lcd.print(“Thermometer”); // info text
  lcd.setCursor(0, 1); // second row
  lcd.print(“0-100 Celcius”);
  for (index = 0; index < numReadings; index++) { // fill the array for faster startup
    readings[index] = analogRead(inputPin);
    total = total + readings[index];
  }
  index = 0; // reset
  delay(2000); // info display time
}

void loop() {
  total = total - readings[index]; // subtract the last reading
  readings[index] = analogRead(inputPin); // one unused reading to clear ghost charge
  readings[index] = analogRead(inputPin); // read from the sensor
  total = total + readings[index]; // add the reading to the total
  index = index + 1; // advance to the next position in the array
  if (index >= numReadings) // if we’re at the end of the array
    index = 0; // wrap around to the beginning

// convert value to temp
  tempC = total * Aref * 0.1 / numReadings; // value to celcius conversion
  tempF = tempC * 1.8 + 32; // Celcius to Fahrenheit conversion

// print to LCD
  if (total == 1023 * numReadings) { // if overflow
    lcd.clear();
    lcd.print("—TOO HOT—");
  }
  else {
    lcd.clear();
    lcd.print(tempC, 2); // two decimal places
    lcd.setCursor(6, 0); // position 6, first row
    lcd.print(“Celcius”);
    lcd.setCursor(0, 1); // second row
    lcd.print(tempF, 1); // one decimal place
    lcd.setCursor(6, 1); // position 6, second row
    lcd.print(“Fahrenheit”);
  }

// print to serial monitor
  Serial.print(“Raw average = “);
  Serial.print(total / numReadings);
  if (total == 1023 * numReadings) {
    Serial.println(”  ----too hot----”);
  }
  else {
    Serial.print("  The temperature is  “);
    Serial.print(tempC, 2);
    Serial.print(” Celcius  “);
    Serial.print(tempF, 1);
    Serial.println(” Fahrenheit");
  }

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



[firstly thanks for your reply. The range I am looking for is ambient to 650C it's for a tandoor, I think I understand what your saying in principle and am going to try, but am still wet behind the ears with no sign of drying up any day soon! and yes with just my multimeter attached the reading is stable allowing for air currents and at 300c I do get 3v. Any more thoughts will be gratefully received/quote]

[Am I using the forum correctly ?
Andy/quote]

Just post in the Quick reply field if you only want to answer without quoting.

Did you already enter "AD595" in the search field on top of this page.
Here's just one link I found there.

Many more.
Leo..

Very interesting thanks ! didn't try that. see I am that wet behind the ears with no sign of drying up any day soon