Go Down

### Topic: Using a LM335Z (Read 1 time)previous topic - next topic

#### lnxrkthkr

##### Feb 11, 2009, 10:33 amLast Edit: Feb 11, 2009, 12:03 pm by lnxrkthkr Reason: 1
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) and wondering
if anyone have used this sensor? Here is how I have connected the sensor:

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

#### George Matthews

#1
##### 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// TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTint 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)); } } */`

#### lnxrkthkr

#2
##### Feb 11, 2009, 02:44 pm
Hello George,

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

Sorry for my ignorance...

#3
##### 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.
Montreal

#### lnxrkthkr

#4
##### Feb 11, 2009, 07:33 pm
ops, sorry

PIN3 = V+
PIN2 = V-

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

// LnxRktHkr

#### George Matthews

#5
##### 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.

#### lnxrkthkr

#6
##### Feb 11, 2009, 09:16 pm
That helps, thank you! Now I got something to continue testing with..

Go Up

Please enter a valid email to subscribe