LM35 readings all over the place!

I've been working on this for a couple of weeks. I avoid asking for help because I learn by digging and digging. I must give up on this one.

I ordered ten LM35s from ebay and realize they could be faulty. But I think that's wishful thinking.

Threads I read online suggest that noise is the problem. I think this goes beyond any kind of noise but I have tried several USB cables.

The problem is that my readings are all over the place. I think the picture I'm posting tells the whole story.

Any help will be greatly appreciated.

LM35.PNG

There have been problems with fake LM35s.

It seems, from the jumping values, that the chip is oscillating.
Is the LM35 near the Arduino, or connected with long wires.
Did you try a 100n ceramic decoupling cap (VCC to ground), close to the LM35.

If it works, use better code that uses 1.1volt Aref and averaging.
Here's an example I wrote.
Leo..

// LM35 temp sensor output connected to analogue input A0
unsigned int total = 0; // A/D readings
float tempC; // Celcius
float tempF; // Fahrenheit

void setup() {
  analogReference(INTERNAL); // use the internal ~1.1volt reference | change to (INTERNAL1V1) for a Mega
  Serial.begin(9600);
}

void loop() {
  // read the sensor
  for (int x = 0; x < 64; x++) { // 64(max) analogue readings for averaging
    total = total + analogRead(A0); // add each value
  }
  // temp conversion
  tempC = total * 0.001632; // value to tempC >>> change last two or three digits slightly to calibrate temp <<<
  tempF = tempC * 1.8 + 32; // Celcius to Fahrenheit

  Serial.print("The temperature is  ");
  Serial.print(tempC, 1); // one decimal place
  Serial.print(" Celcius  ");
  Serial.print(tempF, 0); // no decimal places
  Serial.println(" Fahrenheit");

  total = 0; // reset total
  delay(500); // slows readings
}
1 Like

Thanks for the reply. It's encouraging to know it may be my ebay sensors. Not yet familiar with INTERNAL. Do I still wire the LM35 to the 5v when using the INTERNAL?

LM35 only inches away from Arduino. Are you suggesting I move it further away?

I'm assuming the component you suggested is a cap.

Could you provide a schematic? Thank you.

Tried your code. Values still all over the place.

I hope to hear more from you.

BillByrd:
Not yet familiar with INTERNAL. Do I still wire the LM35 to the 5v when using the INTERNAL?

LM35 only inches away from Arduino. Are you suggesting I move it further away?

I'm assuming the component you suggested is a cap.

Could you provide a schematic? Thank you.

Tried your code. Values still all over the place.

  1. Yes. power and output is the same.

That sensor outputs 0-1volt with temps from 0-100°C.
If you measure that with default Aref (~5volt), then 1volt gives an A/D value of 1024/~5 = ~205.
That's ~2 A/D values per °C, so a resolution of ~0.5°C.

If you lower Aref (the ruler that measures) to ~1.1volt, then the max A/D value of 1023 is reached at ~1.1volt.
1024 A/D values spread over a temp range of 0-100°C, or ~10 A/D values per °C. About five times better.

  1. No. Close should be fine.

  2. 100n ceramic capacitors are essential parts.

  3. You provide the diagram, the code, and a real picture. We check for mistakes.

  4. If there is something wrong with the sensor or the wiring/breadboard, then code won't fix it.

Leo..

Try a 1k resistor between LM35 output and analog input pin, that's worked for me before.
Also, give this sketch a try.

 LM35 thermometer, no floats, no delays

  http://www.ti.com/lit/gpn/lm35
*/


const byte sampleBin = 8,
           aInPin = A4;

const int8_t fudge = 90; // adjust for calibration 

const int kAref = 1090, // analog ref voltage * 1000
          kSampleBin = sampleBin * 1000,
          fin = 2000;
int tempC,
    tempF;
    
uint32_t temp,
         start;

void setup()
{
  Serial.begin(9600);
  analogReference(INTERNAL);
  analogRead(aInPin);
  for(int i = 0;i < sampleBin;i++)
    temp += analogRead(aInPin);
}
void loop()
{
  if(millis() - start > fin){
    start = millis();
    temp -= (temp / sampleBin);
    temp += analogRead(aInPin);
    tempC = temp * kAref / (kSampleBin + fudge);
    tempF = (tempC * 18 + 3200) / 10;
    Serial.print(analogRead(aInPin));
    Serial.print("\t");
    Serial.print(temp);
    Serial.print("\t");
    prntTempC();
    prntTempF();
    Serial.println();
  }
}
    
void prntTempC(){
  Serial.print(tempC / 10);
  Serial.print(".");
  Serial.print(tempC % 10);
  Serial.print("\t");
}
void prntTempF(){  
  Serial.print(tempF / 10);
  Serial.print(".");
  Serial.print(tempF % 10);
  Serial.print("\t");
}

outsider:
Try a 1k resistor between LM35 output and analog input pin, that's worked for me before.

Yep, seen that before but never needed it.
Page 14 of the TI datasheet mentions a 2k resistor inline or RC damper for capacitive loads.
Leo..

Tried all your suggestions. No change whatsoever. Ordered some LM36s from SparkFun. I'm assuming they sell the good stuff. Thanks

An LM36 has a different temp range and needs different code.
If it's a TMP36, you can supply it from the more stable 3.3volt pin.
Example code below. Temp range of this is about -40C to +55C.
Leo..

// TMP36 temp sensor output connected to analogue input A0
unsigned int total = 0; // A/D readings
float tempC; // Celcius
float tempF; // Fahrenheit

void setup() {
  analogReference(INTERNAL); // use the internal ~1.1volt reference | change to (INTERNAL1V1) for a Mega
  Serial.begin(9600);
}

void loop() {
  // read the sensor
  for (int x = 0; x < 64; x++) { // 64(max) analogue readings for averaging
    total = total + analogRead(A0); // add each value
  }
  // temp conversion
  tempC = total * 0.001632 - 50.0; // value to tempC >>> change last two or three digits slightly to calibrate temp <<<
  tempF = tempC * 1.8 + 32; // Celcius to Fahrenheit

  Serial.print("The temperature is  ");
  Serial.print(tempC, 1); // one decimal place
  Serial.print(" Celcius  ");
  Serial.print(tempF, 0); // no decimal places
  Serial.println(" Fahrenheit");

  total = 0; // reset total
  delay(500); // slows readings
}

Wawa:
Yep, seen that before but never needed it.
Page 14 of the TI datasheet mentions a 2k resistor inline or RC damper for capacitive loads.
Leo..

Try different value.
With LM35 optimum value with 50m Cat 5 cable was 4,7 k
You can also use this schematic with Cat 5 cable (best solution) :

LM35_adaptation.png

tests (with 9 m ) :

EUREKA!

The LM36s arrived a few minutes ago and I popped them into the breadboard immediately. Several of you pointed out that the 36 is not the same as the 35. Yes, I knew that. I was trying to stay with one of the popular retail/hobbyist sources thinking that quality would be more important to them.

And the 36 was the only offering in the LM family from SparkFun or Adafruit. I never cared in the first place about the scale. I didn't matter to me if it was Fahrenheit or Celsius or kelvin or Scoville.

The only thing that mattered to me was some legitimate measure of heat that was stable and affected by finger touch or hair dryer or whatever. I'm glad to say that the SparkFun LM36s did just that. So clearly, the ebay LM35s were crap.

You can save a lot of money on ebay. I'll continue to shop for my goodies there. One just needs to sort out the good vendors from the bad. Thanks for all the help from everyone.

One little thing-- multimetering the pinout with 5v and ground on the other 2 pins is suppose to meter out about 0.75v. The best I can do is about 0.63v with accompanying unrealistic room temp readings. I can work with that. Just glad to have something that consistently reports values.