Problems with LM35 Temp Sensors with long leads

Hello all,

Im trying to use an Arduino essentially as a "thermostat" to measure 4 temperatures and control when an AC fan turns on/off.
Please see attached circuit diagrams and Arduino code that I am using. I had success (after several hours of tweaking and troubleshooting using this info from this forum) wiring and testing all the equipment here on my kitchen table. All of the temperature sensors (LM35) were wired and producing steady and accurate temperatures and my relay circuit was also working and controlling my 120 V AC fan.

The problems however, started after I installed all of the components in their permanent place. The temperature sensors and the 120 V fan are located in the attic of my house. The computer and Arduino Leonardo used to power the system was to be located in the laundry room directly below the attic. I used a standard 25 ft CAT5 cable to connect the circuitry in the laundry room to the circuitry in the attic above.

The circuitry for the relay circuit to control the fan worked fine. I was able to turn the fan on/off from the computer no problem. The code I provided does not have the relay control implemented because I have that working and that is not my issue.

The issue is with the readings from the temperature sensors. They are all over the place and inconsistent. As you can note in my diagram, the leads for the temperature sensors are from 5-20 ft long and when I first used them (mock-up on the kitchen table) I was also getting crazy fluctuations and noisy results. Thats when I read on this forum that a resistor connecting Vout to ground would stabilize the readings and thats exactly what happened when I did so. So I thought I had the long lead issue solved. But as I mentioned this was not the case after everything has now been installed.

So here are a few of my thoughts/questions that Im hoping people can help me with:

  1. Was using CAT5 cable appropriate in this application? My calculations for the voltage drop associated with the long leads show that it shouldn't be a problem.

The LM35 temp sensors only draw 60 micro amps of current from the +5V supply. So even with a total current draw of 240 uA and even if you assume the wire length is 50 ft (my longest length from Arduino to the sensor is 45 ft) I calculated a 0.3 mV drop. The LM35 data sheet says it will operate from +4V to 30 V supply and I'm supply pretty much exactly 5 V.

Also Vout of the temp sensors will range from 0mV to 500mV (Assume 50 degrees C is the warmest they will get) and data sheet says the output current is 10 mA. I still only calculate a 10 mV drop which is yes a lot if the temperatures are low 0-5 deg C but the normal operating temp range is from 15 to 40 deg C so its not really significant. Also I don't really care if Im off by 2 or 3 degrees I just need ball park but I need consistent readings.

  1. I know nothing about how the resistors are used to stabilize the readings. I have no idea why it worked when I tested on my kitchen table and now no longer works. Can anyone explain how the resistors stabilize readings and did I choose the right resistor of 10k Ohms.

  2. When I use my multimeter to check Vout and get pretty consistent readings, but then my readings on the computer are all over the place. I did read online that this can happen if your switching analog pins and reading the values to fast which is why I put in my code a read the pin, wait 20 milliseconds and read the same pin again and use the second reading as the real one. Again this helped when I first did my testing but now doesn't help. I also tried making the delay longer and didn't help.

Sorry for the long story but reading these forums, people tend to ask for lots of details as it can help find the problem and find a solution.

Thanks for any input in advance. Hope everyone is having a happy holidays.

tempsketch.ino (1.5 KB)

Hi, with long lead lengths you are probably picking up interference from the AC mains wiring in the house.
I see no bypassing, so use 0.1uF capacitors across your 5V and gnd lines at the arduino end and the attic end.
Also 0.1uF cap between each of the LM35 outputs and gnd, again at the arduino end and the attic end.
I presume you have checked the power rails down the sides of your protoboard, some types break the rails halfway along the board, so no continuity for 5V and gnd.
Try waiting longer between readings to, try 500mS between each analog read, its only room temps your are reading so even every minute would be sufficient.

Tom..Hope this helps... :slight_smile:

See page 9 of the datasheet at http://www.ti.com/lit/ds/symlink/lm35.pdf for what you need to do in situations like this (driving a capacitive load - such as a long cable - from the LM35).

1 Like

Joshua, LM35 is a very good and reliable sensor, but it's like hell when you have a noisy enviroment or power supply. In extreme conditions, to take temp readings 20 meters away in a datacenter, I have used an opamp to feed current instead of voltage to a very low impedance input in the sensor, and that worked without a single noise pick up for years.
But there's a few tricks you may try first. First step, as TomGeorge suggested, I would put 0.1uF capacitors at the arduino end. But also I would lower the impedance of the input so noise voltage will be smaller. That can be done putting a resistor from the wire to ground at the arduino end of the sensor cable, only. Since LM35 can feed a max of 10 mA, let's say that you don't want to stress the sensor and only want to take 2mA max, that's at 50 degrees, and sensor voltage is at 50° = 50°C * 10 mV / °C = 500 mV. Then the resistor to use is 0.5V / 0.002A = 250 ohms, or the next nromalized value, 270.
And also, using cat5 cabling, you can use wires this way:

  • White-Blue pair for positive and ground
  • White-Orange pair for signal and ground. You may connect ground only on one end

This way, most of the noise would cancel. Also, using a 0.1uF cap from positive to ground at the sensor end would help. Good luck!

Hi everyone. I am also facing exactly the same problem as by Joshua.But in mine case I am pretty much sure that there is no source of electrical interference nearby inducing noise to output voltage from LM35 .I found very valuable suggestion made by gentelmen here to the above issue but due to my very limited knowledge in the above filed I am not able to realise it properly.So I request you guys to provide any sketch of circuit rectification or any other simpler method available.

Have a look here : http://forum.arduino.cc/index.php?topic=293078.msg2047788#new
Answer #2

you will find a solution tested until 50 meters.

I'm having the same problem, but my wires are 2m long.
Would an operational amplifier used as buffer attached to the output pin help?

The datasheet shows a 100n capacitor directly across the supply pins of the sensor.
And a 750ohm resistor in series with the output (near the sensor).
I would add a 100n capacitor from A-in to ground (near the Arduino).
Leo..

Weird thing about LM35s, I was working with one mounted on a breadboard with a jumper wire less than 1 inch to a Nano's A5 pin, the ADC counts were jittering all over, from 200 to 260, I put a 100nF cap from A5 to GND and that brought the jitter down to about +/- 15 so I tried a 1k resistor in series with the LM35 output and A5, that dropped the dither down to +/- 1 every 4 to 5 seconds. Have not tried it with other boards or sensors but it sure worked in that case.

Code could further improve stability.
This uses the more stable 1.1volt Aref and averaging.
Leo..

// LM35 temp sensor connected to 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
}

Gerry01:
Joshua, LM35 is a very good and reliable sensor, but it's like hell when you have a noisy enviroment or power supply. In extreme conditions, to take temp readings 20 meters away in a datacenter, I have used an opamp to feed current instead of voltage to a very low impedance input in the sensor, and that worked without a single noise pick up for years.
But there's a few tricks you may try first. First step, as TomGeorge suggested, I would put 0.1uF capacitors at the arduino end. But also I would lower the impedance of the input so noise voltage will be smaller. That can be done putting a resistor from the wire to ground at the arduino end of the sensor cable, only. Since LM35 can feed a max of 10 mA, let's say that you don't want to stress the sensor and only want to take 2mA max, that's at 50 degrees, and sensor voltage is at 50° = 50°C * 10 mV / °C = 500 mV. Then the resistor to use is 0.5V / 0.002A = 250 ohms, or the next nromalized value, 270.
And also, using cat5 cabling, you can use wires this way:

  • White-Blue pair for positive and ground
  • White-Orange pair for signal and ground. You may connect ground only on one end

This way, most of the noise would cancel. Also, using a 0.1uF cap from positive to ground at the sensor end would help. Good luck!

Great reply! You got my first karma point!