LM35CAZ TO-92 Temperature sensor, weird readings?

Hello everyone,
I'm somewhat new to arduino, been playing with it for a couple weeks now and working on building my first project that will be put to pratical use. What I'm building is a temperature sensor for my truck since I don't have an outside temperature display in it :slight_smile:

I ordered a couple of temp sensors from here:
https://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?langId=-1&productId=1468828&catalogId=10001&storeId=10001&krypto=9x3mj8umRTom0c3DLMNz0qFt1vE4yb2XEiH8QmS%2Fj5zJj6SsYWEyagtE9oUB5UUxmXu6IHyY9J5u ryZd5zywy837CnQXRI3X&ddkey=http:StoreCatalogDrillDownView

At first I couldn't figure out how the temperature was being reported from this thing. It says in the data sheet (https://www.jameco.com/Jameco/Products/ProdDS/1468828.pdf) that it's calibrated directly in celsius. Well I thought that meant I didn't have to do the conversions to the reading like I do with the LM35 sensor that came with the arduino kit that I bought to begin with. That didn't seem to work out correctly though, so I went with the same method that I used with the LM35 that came with the kit and thought it was working, however it was returning the numbers in negatives. I thought maybe it was just a polarity issue but wiring the sensor the other way around results in it getting very hot very fast. So I just converted the negative to a positive and then went to test it. But when I went into another room in the house that was noticeably colder, the reading increased by ~3 degrees on the sensor.

Leading me to believe that perhaps the sensor is really really far off and the negative numbers were it saying the temperature was below 0... With the temperatures it's reading and judging from another thermometer nearby, it would mean this sensor is off by a little more than 90 degrees. Reading ~-18.5f in a room that is ~76f.

I dunno, I would consider it being a bad sensor but I bought two of them and they both exhibit the same behavior. With approximately the same temperature difference. I find it hard to believe that two sensors would both off by about the same amount especially when this far off. So I'm assuming I'm simply not calculating something correctly somewhere. Anyone have any ideas?

Here is the code I'm using atm for testing:

int tempPin=0;
void setup()
{
     Serial.begin(9600);
}

void loop()
{
    float thisTemp=getVoltage(tempPin);
    thisTemp=(thisTemp - .5) * 100;
    thisTemp=(thisTemp * 1.8) + 32;   //Convert to farenheit
    Serial.println(thisTemp);
}

float getVoltage(int pin)
{
     return (analogRead(pin) * .004882814);
}

Why are you subtracting 0.5 ? I think that's the source of the problem.

Do you have the resistor in place - see page 2 - https://www.jameco.com/Jameco/Products/ProdDS/1468828.pdf -

The -0.5 * 100 = -50 * 1.8 = -90 + 32 = 58 degrees F off

76 - 18 == 58 so dc42 is right .

dc42:
Why are you subtracting 0.5 ? I think that's the source of the problem.

Because that is what was done in the example application that came with the kit, and as I said I was trying to follow that since my initial results without modifying the returned number at all was returning very weird numbers.

http://www.oomlout.com/a/products/ardx/circ-10

It might not be correct I was just trying to get it to work properly.

robtillaart:
Do you have the resistor in place - see page 2 - https://www.jameco.com/Jameco/Products/ProdDS/1468828.pdf -

The -0.5 * 100 = -50 * 1.8 = -90 + 32 = 58 degrees F off

76 - 18 == 58 so dc42 is right .

I'm not sure how I'm supposed to wire a resistor into this. According to that Full-Range diagram on page 2, it shows R1 with a negative voltage connected to the Vout. But that doesn't realy make any sense to me, I don't know how to do a negative voltage for one, and for two I don't understand how that would effect the reading. As I said, I'm somewhat new so I'm still learning a lot of this stuff.

So what this thing is actually returning is a fraction of 1 of representing the centigrade temperature? Like .28 = 28 degrees c?

Maybe the one that came with the kit has the .5 mV offset so that it can handle negative temperatures correctly without the negative voltage? I thought I read somewhere on this sensor that the negative voltage wasn't required but according to that diagram it looks like it is if I want to read temperatures below +2 c (and it does get colder than freezing where I live at times so I need to be able to read as low as -10 degrees c.

If someone could help me with how to wire the negative, and explain to me why it is necessary and how it works that would be awesome. I don't want to simply get it working, I want to understand what it's doing an why it's needed.

EDIT:
Guess if I read a little better I might be able to help myself more. Just rereading the stuff from the kit, and it even says there that it has a 500 mv offset in order to read below freezing temperatures. That is why the -.5 was throwing it off, so that make sense, but I still don't understand the negative voltage on this one in order to be able to reading freezing temps.

Everything I'm reading about negative voltage is talking about a shared ground / twisted pair. But if I try to wire anything like that on my arduino board that would be feed power directly into the ground wire and cause a short. I don't understand this and can't find anything that explains it well enough.

I tried simply putting the ground wire onto the signal wire through a 330 ohm resistor, and if I test voltage ground to the signal wire, I'm showing a -.25 voltage... is this correct? I'm guessing not based on all the stuff I'm reading, plus I don't even know what size resistor I'm supposed to be using. Looks like a 200 ohm is used in some of their typical applications, but none of their typical applications show a circuit as simple as I'm trying to do.

EDIT:

Ok well I confirmed that that most likely isn't correct. I stuck it in the freezer wired like that and it bottom out at 32 degrees f, I'm pretty sure the freezer is colder than freezing and it was just incapable of reading a negative temperature the way it's wired. I simply do not understand how I'm supposed to wire this negative voltage without creating a short in the circuit... Wish I knew where a chat room was for this kind of stuff lol, it's not fun trying to get something to work and having to wait for replies! :wink:

The 0.5v offset is for the TMP36 sensor. The LM35 sensor doesn't have the 0.5v offset, but can only measure temperatures of 2C and above when connected directly to an Arduino. So if you have the LM35 sensor, you need to remove the "- 0.5" from your calculation.

Ok, well I found this: 555 Negative Voltage Generator

So that I could create a negative voltage. Confirmed it using my multimeter at -3.6v.

However putting that negative voltage through a 10k resistor and then onto the Vout line (before the signal cable) still doesn't work. It still bottoms out at 32 degrees farenheit being returned.

EDIT:

Another update, tried with a 330 Ohm resistor as well and same results. I think I might need something like a 72 ohm resistor though if it needs 50 uA of power there, not sure if thats what it needs or not but looking closer at the datasheet, that might be what it's saying.

EDIT2:
Perhaps the problem with the negative voltage is the capacitors I used. I'm not sure. Was just checking it, as soon as it starts pulling a load on the negative voltage, the negative voltage drops down to -.5. So when it reads that -.5 * .004882814 = -.002441407 * 100 = -.24. So it's basically saying it is slightly below freezing. Even if it stayed at -3.6 volts it would only be -1.75 c as the reading, I don't understand how this negative voltage is supposed to let it properly display negative temperatures.

Well, I think I found the problem.

Reading another forum, it's stated that arduino analog inputs cannot read a negative voltage. So I have to wire it a different way (Figure 7 in the previously linked data sheet for the temp sensor), and use a different formula to determine the actual temperature. But I can't find anywhere that specifies what the new formula is. Apparently it has something to do with an offset like the TMP36 sensor, but the offset is variable and read through the negative (ground) pin.

I will play around with it some more today, got to go get some stuff at radioshack if they have it, but if anyone else has any ideas please let me know!

EDIT:
I went ahead and used some stuff I have here for testing, I don't have the 18 resistor so I used a 10k and a 7.3k in series, and I don't have the diodes it called for but used two that I do have, and it does seem to be working. By using the same calculations and just doing getVoltage(0) - getVoltage(1) (see earlier code for the function, but it's just analogRead(pin) * .004882814) seems to have done the trick.

I may change the function to return the voltage without the *.004882814 and do that after substracting them from each other as that may be a little more accurate, not sure what the precision on floats is in arduino.