Too much variations in temperature?

Hi all,

I was using the temperature sensor supplied by the Arduino starter kit (I believe it's the TMP36) to log temperature measurements every 5 seconds of the ambient environment. I keep getting these variations in temperature, can anyone explain the temperature swings? Note, these are in Celsius, so 4C difference in about 9F difference. Any ideas?

2013-07-05 04:59:55 8.11
2013-07-05 05:00:00 10.06
2013-07-05 05:00:05 12.99
2013-07-05 05:00:10 10.06
2013-07-05 05:00:15 8.59
2013-07-05 05:00:20 9.57

I just have the sensor on the breadboard, power it through the Arduino, and read its voltage. Nothing more.

float voltage = (sensorVal/1024.0) * 5.0;
Serial.print(", degrees C: ");
float temperature = (voltage - 0.5) * 100;

I get the same variations in 1 second intervals too. Is this normal/to be expected? Seems off to me, but I'm a newbie to hardware/electronics (I like it though :slight_smile: )

Thanks.

PS: Eventually I'll want to also measure humidity and build a rudimentary basic wireless weather monitor (just for fun and learning)

Is your room quite cold? Normal room temperature is over 20°C.

Might be a bad connection.

johnwasser:
Is your room quite cold? Normal room temperature is over 20°C.

Might be a bad connection.

Good point :slight_smile:

I actually had the windows open over night, I wanted to graph the temperature changes in this room over a 24 hour period (new to "physical computing" so I'm just playing around with the equipment at this point). The temps are accurate overall, the odd thing are the 4C/9F changes in 5 seconds .. ie noise.

I can write code to average 3 readings at a time I guess to help smooth this out, I'm just curious why this happens and/or if this is normal.

If there's a breeze you will get rapid fluctuations since breezes stir the air (warm air high in room, cool air lower
in room).

But firstly try testing the sensor in a known constant/slowly varying temperature environment if your can (if its a probe
place it in a glass of water)

MarkT:
If there's a breeze you will get rapid fluctuations since breezes stir the air (warm air high in room, cool air lower
in room).

But firstly try testing the sensor in a known constant/slowly varying temperature environment if your can (if its a probe
place it in a glass of water)

I'll try to put it into a more controlled environment and see if it still fluctuates (my guess is yes, but I'd be happy to be wrong :slight_smile: I'll report back here.

I get the same variations in 1 second intervals too. Is this normal/to be expected?

I would say no, it sounds like you have noise on the line.
You can try a 0.1uaf cap across the analogue input.

MarkT:
If there's a breeze you will get rapid fluctuations since breezes stir the air (warm air high in room, cool air lower
in room).

But firstly try testing the sensor in a known constant/slowly varying temperature environment if your can (if its a probe
place it in a glass of water)

The unit was in a room with the windows closed for several hours, still got fluctuations of about 4C, it must be some sort of noise.

Grumpy_Mike:

I get the same variations in 1 second intervals too. Is this normal/to be expected?

I would say no, it sounds like you have noise on the line.
You can try a 0.1uaf cap across the analogue input.

Agree with your assessment of noise, that's the conclusion I have reached too.

Could you explain how this capacitor would help/work? I'm a newbie still with the electronic side of things (though quite comfortable with the software side).

Hi Levon,

Before we go too far, we should probably see your code to make sure it's doing what you think it's doing. Copy it and paste it in a reply, select the code and then select the # icon above to put it in a code block.

What you are seeing might be the result of a code error.

Pat.

patduino:
Hi Levon,

Before we go too far, we should probably see your code to make sure it's doing what you think it's doing. Copy it and paste it in a reply, select the code and then select the # icon above to put it in a code block.

What you are seeing might be the result of a code error.

Pat.

Fair enough Pat, seems like a good complete troubleshooting approach .. here it is

const int sensorPin = A0;
long count = 1;
const int SECONDS = 5; // update every X seconds

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


void loop()
{
  int sensorVal = analogRead(sensorPin);
  Serial.print("\ncount: ");
  Serial.print(count);

  Serial.print("  Sensor Vals: ");
  Serial.print(sensorVal);

  float voltage = (sensorVal/1024.0) * 5.0;

  Serial.print(", Voltage: ");
  Serial.print(voltage);
  Serial.print(", degrees C: ");
  float temperature = (voltage - 0.5) * 100;
  Serial.print(temperature);

  delay(1000 * SECONDS);
  count++;
}

Could you explain how this capacitor would help/work? I'm a newbie still with the electronic side of things (though quite comfortable with the software side).

A capicitor looks like a low impedance to noise but a high impedance to the signal you want. It shorts out the noise.

Grumpy_Mike:

Could you explain how this capacitor would help/work? I'm a newbie still with the electronic side of things (though quite comfortable with the software side).

A capicitor looks like a low impedance to noise but a high impedance to the signal you want. It shorts out the noise.

Thanks .. I'll read up on this some more, but I get the basic idea.

Do you think this is a better approach than to say average 3 measurements taken in quick succession instead? I.e., one solution uses hardware, the other software ... just wondering which would be a better/more accepted way to deal with this type of problem.

average 3 measurements taken in quick succession

I've handsome good luck with that, so you might want to try it.

I also had a similar problem running the circuit from the USB port power. I recall that things got better when I also connected my wall wart. [faint memory...]

It is best to remove the defect with a capacitor rather than hide it with an averaging.
What is your board ? Uno or Mega?

If it is a UNO you can solder a 100 nF capacitor directly on the support of micro-controller.
On my UNO board the improvement was obvious.
Only capacitor at the bottom is helpful.
The second one, to the right, is difficult to sold and does not bring much improvement.

If it is a Mega board nothing is possible with SMD ATMega2560

Edit : the pin which is decoupled is Aref.

Forum12.png

patduino:

average 3 measurements taken in quick succession

I've handsome good luck with that, so you might want to try it.

I also had a similar problem running the circuit from the USB port power. I recall that things got better when I also connected my wall wart. [faint memory...]

The standard deviation definitely goes down as I take more measurements at once to average, 3-5 seems to be the sweet spot.

I do have a wall-wart, I may give that a try too .. at this point I'm just exploring and learning about the various tools I have at my disposal.

68tjs:
It is best to remove the defect with a capacitor rather than hide it with an averaging.
What is your board ? Uno or Mega?

Edit : the pin which is decoupled is Aref.

I have a UNO, thanks for the info. At this point I'm not confident enough to make the modification to the board you suggest, but I've stored this away for future reference.

Can I put this capacitor somewhere in the circuit on the breadboard .. all my circuits for now are on breadboards as I learn my way around this. Could I put this between the output of the sensor and the analog input on the board?

Thanks.

take 2 readings, discard the first one

float trash=analogRead(0);
float realone=analogRead(0);
Serial.print(realone);

there is also something in the datasheet for the atmega328p on getting better precision from the adc. and... 10.4 Adc noise reduction mode, page 39.

Could I put this between the output of the sensor and the analog input on the board?

No put it from the analogue input to ground.

take 2 readings, discard the first one

This is only useful when looking at two or more analogue inputs of high impedance. With only one input it is not going to do anything for you.

Can I put this capacitor somewhere in the circuit on the breadboard

No.
Aref is connected dirrectly to the heart of the ADC.
If Aref is noisy, measurement will be noisy.

The decoupling of Aref in entrance of the board does not work because after the decoupling capacitor Aref track is too long and acts as an antenna. This is a design error of UNO board and probably Mega
You must bypass the interference signals with a soldered capacitor as close as possible to the microcontroller.

The Mega 2560 has an internal voltage reference that cuts down on noise:

  //Set analog reference to 2.56 volts internal
  analogReference(INTERNAL2V56);

I also use a capacitor between ground and my analog pin.

I think you should use the digital DS18B20 one wire sensors.