Reading LM335Z Sensor

I've been playing around with a LM335Z sensor and I'm having problems converting its voltage output to Celsius, this is my current setup: http://i43.tinypic.com/wvy4b7.png *Note: There is a 2k Ohm resistor between the +5v and the VIN pin of the sensor.

Here is an example of the readings if I use a hair dryer or something on the sensor attempting to heat it up:

Raw Temp: 214, DegC: 20
Raw Temp: 213, DegC: 20
Raw Temp: 212, DegC: 20
Raw Temp: 212, DegC: 20
Raw Temp: 212, DegC: 20
Raw Temp: 211, DegC: 20
Raw Temp: 211, DegC: 20
Raw Temp: 210, DegC: 20
Raw Temp: 210, DegC: 20
Raw Temp: 210, DegC: 20
Raw Temp: 209, DegC: 20
Raw Temp: 208, DegC: 20
Raw Temp: 207, DegC: 20
Raw Temp: 207, DegC: 20
Raw Temp: 207, DegC: 20
Raw Temp: 205, DegC: 20
Raw Temp: 205, DegC: 20
Raw Temp: 204, DegC: 19

As the Sensor heats up the analog pin reading is dropping instead of rising :S

Here is the code I'm using:

int degC = 0;
int tmpVal = 0;

void setup( ) {
  Serial.begin( 9600 );
}

void loop( ) {
  degC = analogRead( 0 );
  tmpVal = ( ( degC / 1024.0 ) / 10 ) * 1000; 
  
  Serial.print( "Raw Temp: " );
  Serial.print( degC );
  Serial.print( ", DegC: " );
  Serial.println( tmpVal );
  
  delay( 1000 );
}

Anyone know how to properly read from a LM335Z temp sensor and convert it to Celsius?

Did you mean a LM35Z?

  1. Use analogReference(INTERNAL)

  2. Put a 'float' in front of your inside brackets, and/or make sure you multiply before divide in integer maths.

When I used the LM35 for my scrolling temperature panel, I used this:
temp = float(analogRead(temPin)+analogRead(temPin)) / 1.86; // conv to .1oC to get Centigrade. Note the use of a double analogRead to even out any noise on the input.

[/code]

The sensor I'm using is http://www.national.com/mpf/LM/LM335.html the LM335Z one, it outputs in Kelvin.

And I still can't seem to get proper readings from the sensor :frowning:

You have miswired it a little bit. Move the red wire down one space so that it is on the same pin of the LM335Z as the black wire. The pin you have the red wire on now is an adjustment pin, not an output pin. The "output" is the analog voltage at the center pin.

I see...

The 2v+ output means you cannot use the 'INTERNAL' 1.1v reference, and the 'DEFAULT' sensitivity is about 10mV, so expect to be 1 or 2 degrees off. For the 5-v reference to work, you MUST use a regulated supply and cannot use the USB derived supply.

The basic equation should be:
tempVal= float(degC/204.6) - 273 // oK to oC

Give it a try and let me know.

temp=

Alright I've moved the analog wire down to the same pin as vin pin and changed the code to:

tmpVal = float( degC / 204.6 ) - 273;

But now the output is:

Raw Temp: 466, DegC: -270
Raw Temp: 466, DegC: -270
Raw Temp: 467, DegC: -270
Raw Temp: 466, DegC: -270
Raw Temp: 466, DegC: -270
Raw Temp: 467, DegC: -270
Raw Temp: 466, DegC: -270
Raw Temp: 466, DegC: -270
Raw Temp: 466, DegC: -270
Raw Temp: 467, DegC: -270
Raw Temp: 467, DegC: -270
Raw Temp: 466, DegC: -270

Right now the sensor should be reading around 20 C.

No, that equation is not right. The sensor should be ~3V at room temperature, or an A/D code of 614 assuming 5V reference and 10-bit result. Your raw 466 result is not that far off, given the accuracy of everything. See how it changes with temperature.

You should be getting a reading of 600 from degC, and the equation should read:

tmpVal = float( degC / 2.046 ) - 273

Alright ive updated the code again and the results are still no good :frowning:

Raw Temp: 466, DegC: -45
Raw Temp: 466, DegC: -45
Raw Temp: 466, DegC: -45
Raw Temp: 466, DegC: -45
Raw Temp: 466, DegC: -45
Raw Temp: 466, DegC: -45
Raw Temp: 466, DegC: -45
Raw Temp: 466, DegC: -45
Raw Temp: 466, DegC: -45
Raw Temp: 466, DegC: -45
Raw Temp: 466, DegC: -45
Raw Temp: 467, DegC: -44
Raw Temp: 466, DegC: -45
Raw Temp: 466, DegC: -45

Also when heating the sensor the Raw Temp goes down as it gets hotter, making DegC rise -45 to -84 etc...

Check your circuit again. A reading of 466 on the analog port indicates only 2.3-volts, which equates to 230K. You should be getting numbers in the 600's.

Have you tried warming/cooling the sensor to see if the output varies?