Go Down

### Topic: Too much variations in temperature? (Read 5480 times)previous topic - next topic

#### levon

##### Jul 05, 2013, 03:23 pm
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 )

Thanks.

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

#### johnwasser

#1
##### Jul 05, 2013, 08:05 pm
Is your room quite cold?  Normal room temperature is over 20°C.

Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

#### levon

#2
##### Jul 05, 2013, 08:20 pm

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

Good point :-)

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.

#### MarkT

#3
##### Jul 05, 2013, 10:53 pm
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 will NOT respond to personal messages, I WILL delete them, use the forum please ]

#### levon

#4
##### Jul 05, 2013, 10:58 pm

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   I'll report back here.

#### Grumpy_Mike

#5
##### Jul 05, 2013, 11:12 pm
Quote
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.

#### levon

#6
##### Jul 06, 2013, 07:01 am

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.

#### levon

#7
##### Jul 06, 2013, 07:03 am

Quote
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).

#### patduino

#8
##### Jul 06, 2013, 07:07 am
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.
There are 10 types of people in the world, those who understand binary, and those that don't.

#### levon

#9
##### Jul 06, 2013, 07:12 am

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

Code: [Select]
`const int sensorPin = A0;long count = 1;const int SECONDS = 5; // update every X secondsvoid 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++;}`

#### Grumpy_Mike

#10
##### Jul 06, 2013, 07:17 am
Quote
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.

#### levon

#11
##### Jul 06, 2013, 07:19 am

Quote
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.

#### patduino

#12
##### Jul 06, 2013, 07:57 pm
Quote
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...]
There are 10 types of people in the world, those who understand binary, and those that don't.

#### 68tjs

#13
##### Jul 06, 2013, 08:26 pm
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.

#### levon

#14
##### Jul 07, 2013, 03:39 am

Quote
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.

Go Up