Go Down

### Topic: Help reading temperature from LM335Z (Read 1 time)previous topic - next topic

#### fergofrog

##### Sep 26, 2010, 10:57 am
I'm having some troubles reading the correct temperature from a LM335Z Temperature IC. The code I'm using is:
Code: [Select]
`const int analogInPin = 0;void setup() {  Serial.begin(9600); }void loop() {  float raw = analogRead(analogInPin);  float kelvin = (raw / 1023.0) * 500.0;  float celcius = kelvin - 273.15;  Serial.print("Raw: ");  Serial.print(raw);  Serial.print(", ");  Serial.print("Kelvin: ");  Serial.print(kelvin);  Serial.print(", ");  Serial.print("Celcius: ");  Serial.print(celcius);  Serial.println("");  delay(1000);                     }`

The kind of results I'm getting are:
Code: [Select]
`Raw: 738.00, Kelvin: 360.70, Celcius: 87.55Raw: 739.00, Kelvin: 361.19, Celcius: 88.04Raw: 739.00, Kelvin: 361.19, Celcius: 88.04Raw: 740.00, Kelvin: 361.68, Celcius: 88.53Raw: 739.00, Kelvin: 361.19, Celcius: 88.04Raw: 739.00, Kelvin: 361.19, Celcius: 88.04`
These results are a little off the maximum uncalibrated temperature error of 9°C (it's about 22°C here), and I am getting a similar result from another LM355Z (I have two).

#### mowcius

#1
##### Sep 26, 2010, 12:39 pm
From the datasheet:
Quote
Vout(T) = Vout(To) x T/To

T = unknown temp
To = reference temp

Take an ice cube and whack it on the sensor. Then you know it's 0C.

Then measure the voltage - just use the arduino analog input.

You then have To and Vout(To). By then measuring the voltage at other temperatures you can compare it to that reference

Always use the datasheet and calibrate temperature sensors yourself.

The 5V pin on the arduino always varies a little bit from board to board so calibration is required to get it accurate.

I'm not sure why what you were getting was so off but it doesn't really matter

Mowcius

Go Up