Arduino Forum

Forum 2005-2010 (read only) => Hardware => Interfacing => Topic started by: lnxrkthkr on Feb 11, 2009, 10:33 am

Title: Using a LM335Z
Post by: lnxrkthkr on Feb 11, 2009, 10:33 am
Hello,

Born again electronics guy here. Got my arduino a couple of days ago
and have done a lot of blinking leds lately :) Moving on to temp sensing.
I got a LM335Z (datasheet (http://www.datasheetcatalog.org/datasheet2/0/01g1j31dx93i4k0k0qag4l8914py.pdf)) and wondering
if anyone have used this sensor? Here is how I have connected the sensor:

(http://www.postimage.org/Pq1QJKnA.jpg) (http://www.postimage.org/image.php?v=Pq1QJKnA)

I get a constant analogRead value of about ~1000 which probably
is very wrong.. Do my wiring look ok?

I'm trying to figure out how to convert the readings (when ok) to
a "human" value.. I should get 10mV per Kelvin but how do I map
the "a/d" value to voltage again to find out the temperature?

Edit:
Voltage = analogRead(X)*5.0/1024.0; if using 5V as ref...

Anyone using this sensor and could post an example?

Cheers, LnxRktHkr
Title: Re: Using a LM335Z
Post by: matthewsg on Feb 11, 2009, 02:01 pm
Two examples here. As small part of my MRMP controller code. The first small and fast and the second, commented out, has a range checking schema.
Both return the temp in degrees C x10. In general, floating point is rarely required and should be avoided.


Code: [Select]
// TTTTTTTTTTTTTTTTTTTT Temperature 2.2 TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
// TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT


int tempOnPin(int pin,int offset,int slope)
{
 return ((((analogRead(pin) * 10) - offset) * 100) / slope);
}
/*

#define BitsPerDegree 215       // Slope  2.15
// #define Bits0Degrees 5490       // Offset. 10 x the bits at zero degrees in WATER.
#define Bits0DegreesAir 5650    // Offset. 10 x the bits at zero degrees AIR temp.
// When self heating is an issue for air temp make this lower.

#define MaxTempError 2000       // Used to set upper and lower before error value passes
#define MinTempError -500
#define TempError -32000        // Used by functions to determine if sensor shorted or open


// Read the temperature LM335 sensor 2k2 and 5v
int tempOnPin(int pin,int offset,int slope)
{    

long temp;

temp = analogRead(pin);   // read the value from the sensor


temp = ((((temp * 10) - offset) * 100) / slope);      //  10 x the degrees c on pin returned

if ((temp > MaxTempError) || (temp < MinTempError))   // between Max and Min or error
{
return (TempError) ;     // Used by calling routine to determine if sensor is shorted or open
}
else
{
return (int(temp));

}
}

*/


Title: Re: Using a LM335Z
Post by: lnxrkthkr on Feb 11, 2009, 02:44 pm
Hello George,

Thanks for your reply!
Do you think the wiring is ok?
Also, what are the "offset" and "slope" arguments for?

Sorry for my ignorance...
Title: Re: Using a LM335Z
Post by: patgadget on Feb 11, 2009, 06:55 pm
Hi,
i just check the datasheet, and there is no relation to VO and VI, so i have a hard time figuring wich pin you connect to what?
You should have 10mV/Kelvin that aroud 2.93Volts at room temp (20deg Celcius)
if you have around 0.6-0.7 volt that is probally that you wire the zener in reverse.
Title: Re: Using a LM335Z
Post by: lnxrkthkr on Feb 11, 2009, 07:33 pm
ops, sorry

PIN3 = V+
PIN2 = V-
PIN1 = ADJ

I get almost 5v on the V+ pin...

// LnxRktHkr
Title: Re: Using a LM335Z
Post by: matthewsg on Feb 11, 2009, 09:08 pm
Quote
Do you think the wiring is ok?

Yes. Although I use a more common 2k2 resistor.

Quote
Also, what are the "offset" and "slope" arguments for?


Offset. 10 x the bits at zero degrees in WATER or AIR
Simply imerse your sensor in melting ice water to determine the offset bits in water. Alternatively, use a known-good thermometer, and adjust the offset until the output matches.


Slope. If you plotted the degrees vs bits on a graph, the slope (angle) would be 2.15 Knowing the slope and the bits, you can computer the degrees.

Hope that helps.

Title: Re: Using a LM335Z
Post by: lnxrkthkr on Feb 11, 2009, 09:16 pm
That helps, thank you! Now I got something to continue testing with..