Go Down

Topic: inconsistent temperature readings (LM35DT) (Read 728 times) previous topic - next topic

waspinator

Dec 09, 2012, 09:08 pm Last Edit: Dec 09, 2012, 09:43 pm by waspinator Reason: 1
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: [Select]

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;
}

dhenry

Maybe you were adc'ng unconnected pins.

waspinator

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

dc42

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

waspinator

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

dc42

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

Go Up