I’ve done a number of project that involve using an LM35 sensor and each time that sensor seems to go bad (Vout holds to 5v). My first project involved using it outdoors so I thought it couldn’t handle wet environments. My latest project has the sensor in my computer case and it still has this problem. Clearly there’s something I’m doing wrong. I’ve verified the pins are correct, so that’s not it. Sometimes I get the correct reading but it will return to hanging high after a few moments of giving me the right value. I also know none of the connections are floating as I can ground all three and see 0 as the readout.
Does anything below stick out as a possible cause of this problem:
Design:
-Arduino Mega
-Vin = 5v via io pins
-Vout = analog pins 0-2 (three sensor)
-Wiring: Vcc,Vout,GND twisted together
-Wire Length: 1-2ft.
-In computer case with one next to PSU and another close to a fan
uint16_t val;
digitalWrite(TEMP_PWR_A, HIGH);
digitalWrite(TEMP_PWR_B, HIGH);
delayMicroseconds(100);
val = analogRead(TEMP_OUT_P) * 500 / 1024;
val = val > 99 ? 99 : val;
gSysCtrlData._dTempReading.mPanel = val;
val = analogRead(TEMP_OUT_CA) * 500 / 1024;
val = val > 99 ? 99 : val;
gSysCtrlData._dTempReading.mCaseA = val;
val = analogRead(TEMP_OUT_CB) * 500 / 1024;
val = val > 99 ? 99 : val;
gSysCtrlData._dTempReading.mCaseB = val;
//I've also tested it with it always on (switch below lines to HIGH)
digitalWrite(TEMP_PWR_A, LOW);
digitalWrite(TEMP_PWR_B, LOW);
Not with this recent attempt, but I doubt it’s the ADC on the arduino that giving me bad readings. As for always ON, I’ve tried that already. One thing to note, if I leave the computer off for a day or so, the reading will start off fine for about an hour before hanging high.
Does anyone know if have the 3 wires twisted together pose an issue or the fact it’s in a computer case next to fans and hard drives cause any interference?
Mr.UNOwen:
One thing to note, if I leave the computer off for a day or so, the reading will start off fine for about an hour before hanging high.
That it works fine for a while and then quits … is odd. Unless you had no fan or no HDD activity during that hour, I don’t see how they could be involved. I might suggest a “cold” solder joint or some other temp related cause but I can’t see that occurring in 4 separate instances.
So the above circuit helps, but anything past 30c fails with the sensor hanging high. My solution ends up being a simple resistor voltage divider with two 10k resistors. At the moment it’s doing the job using aligator clips, I’ll let you know if it all works after I solder it all togeth. Also I tested it with the shortest cable, hopefully it still works with the longest cable.
Have you checked the output with a DVM like the other poster asked?
I sold a product that used the LM34 (or 35, I forget) for years and I never saw this problem. IIRC, it drove a filter capacitor of 0.01uF just fine, the response was just slower.
One thing that sticks in my mind is that the OP is powering the LM35 from a GPIO pin declared as an output, so he can switch it on and off. Given the tiny current draw of the device, the extra tens of ohms I’d expect for an output resistance shouldn’t matter. But when it comes to driving even (IMO) small capacitive loads ??? Perhaps there’s some odd relationship that’s not obvious. I might implore the OP to use the 5V regulated output of the Arduino as the supply, just as a test … and see if that makes any difference.
lyndon: If DVM stands for digital volt meter, then I have in the past, curently I have a cheap multimeter which doesn’t seem that reliable for voltage reading which I just use to test for shorts and continueity. Has any of your tests involved having the three wires twisted to the point the cable starts to form knots and is 2 to 3 feet long (FYI I used a drill)?
Mee_n_Mac: The issue with directly attaching it to 5v rather than an io pin is that after a week or so of continuous use it would permantly hang to 5v with no sign of recovery after detaching it for a while. Again I suspect it’s the wiring and not a normal behavior of the LM35 (or I managed to buy a cheap batch 5 times in a row, I do go for the least costing).
Anyway, the voltage dividing approach seems to work. I’ve had no issue with it so far. I’ll keep it going for a week before concluding if this approach worked. Mee_n_Mac thanks for the diagram, I wouldn’t of gotten to my solution without that advise. Thanks for the help everyone. In a week I’ll post a reply that either concludes this thread with a successful fix or we’ll be back to drawing board and by then I’ll have decent multimeter.
Good news, looks like the voltage divider design did the job. There was one brief moment where it did hang high, but I found that the ground pin came off. So I’d say it’s a success. Thanks for everyone’s help and I hope this thread helps anyone else that comes across my issue.
I know its late in the game, however I just built my sensors today, and got the exact same error. turned out that I needed to put the LM35 in correctly…was backwards initially. turning so the power was feeding into it on the supply side and ground was on the ground side made everything good. Its hard to believe the amount of information i found on this problem, and the fixes that people were dreaming up. One guy got five of them and when all of them gave the same reading of 1023 he went and bought more (which fixed the problem???). one i could see being problematic, but all five? i suspect he put the new batch in correctly.
my sensors are being used on a DAEnetIP1 board with 12v supply to the LM35. the schematic is here: