Pages: [1]   Go Down
Author Topic: inconsistent temperature readings (LM35DT)  (Read 651 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I have 3 LM35DTs hooked up to my arduino inputs A0-A2. When I go to read their values I get significantly different results for each sensor (example: 16, 26, 21), even though their touching each other, meaning their temperatures should be identical. Interestingly, even if I move a sensor from one input to anther, the values don't change, suggesting that it's not a variation in the sensors. Any ideas of what could be causing these issues?

Here is the code I use to read the sensors:

I just call it 3 times with a different sensor_pin value.

Code:
float readTemp(int sensor_pin){
  // set reference voltage to 1.1V
  analogReference(INTERNAL);
  // make sure it had enough time to switch
  delay(10);
  float refV = 1.1;

  // take 100 readings and get the average
  float accumulatorRaw = 0;
  for (int i = 0; i < 100; i++){
    accumulatorRaw += analogRead(sensor_pin);
  }
  float averageRaw = accumulatorRaw / float(100);
  // LM35DT sensor: 0.01V per 1 degree centigrade
  float tempValue = ((averageRaw * refV ) / 1024) / 0.01;
 
  return tempValue;
}
« Last Edit: December 09, 2012, 03:43:03 pm by waspinator » Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe you were adc'ng unconnected pins.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The temperature change when I heat up the sensors, so it would seem that they are indeed connected.
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6614
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How do you have the sensor ground pins connected? Post a photo of your setup.

For accurate results, the sensor ground pins should be connected to one of the GND pins on the Arduino, and anything else that needs to be connected to ground (apart from other sensors with analog output) should be connected to a different GND pin. This is especially important if the Arduino is controlling something that takes a lot of current. Otherwise, current flowing through the shared ground wire and connections induces a voltage across them, which affects the readings.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmm, I assumed that the ground pins on the arduino were shorted to each other. Shouldn't all grounds be connected anyway?

I followed some advice on adafruits website and it seemed to work. It seems strange since I already had a 10ms delay, and was repeating the reading 100 times, but calling my function a second time produced more accurate results.


Quote
Problems you may encounter with multiple sensors:
If, when adding more sensors, you find that the temperature is inconsistant, this indicates that the sensors are interfering with each other when switching the analog reading circuit from one pin to the other. You can fix this by doing two delayed readings and tossing out the first one

http://learn.adafruit.com/tmp36-temperature-sensor
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6614
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The point of using separate ground pins for sensors and other stuff is to avoid power supply current or output pin current flowing through a shared ground wire. The resistance and inductance of the shared ground wire will result in small voltages between one end and the other, and when you are trying to read a signal to a resolution of 5mV of better, this matters.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Pages: [1]   Go Up
Jump to: