Help with LM335Z

Hello to all!

First of all I'm really a beginner with everything concern arduino and electronic.

I would like to try a temperature sensor: LM335Z

The components are so connected:

Analog PIN0-------------------------.
| |
|----------| 5V+ -------////-------- V+ |----------|
|-Arduino| R1 | LM335Z|
|----------| - GND ---------------------- V- |----------|

I Mean:
5V goes trougth a 2.2K resistence (R1) to the middle PIN of LM335Z. From the same path the signal goes back to arduino to analog0.
Seeing LM335Z from bottom view, the right pin is connected to ground.
ADJ pin of LM335Z is not connected.

Now, I've used the LM335A library from arduino playground site (url library: http://greenrobotics.net/files/lm335a.zip) to read values from sensor.

This is the code:

#include <LM335A.h>
float raw;

LM335A InsideTemp(0); //pass the analog input pin number
void setup() {
Serial.begin(9600);
Serial.println("starting");

}

void loop() {
  delay(1000);
  //user must call ReadTemp before any valid temp data is available
  raw = analogRead(0);
  InsideTemp.ReadTemp();  
  Serial.print("Raw: ");
  Serial.print(raw);
  Serial.print("\tFahrenheit: ");
  //functions to get the temperature in various unitsfs
  Serial.print(InsideTemp.Fahrenheit());
  Serial.print("\tCelsius: ");
  Serial.print(InsideTemp.Celsius());
  Serial.print("\tKelvin: ");
  Serial.print(InsideTemp.Kelvin());
  Serial.print("\n");

}

And here the output:

Raw: 615.00    Fahrenheit: 59.59    Celsius: 27.59    Kelvin: 300.59
Raw: 614.00    Fahrenheit: 59.10    Celsius: 27.10    Kelvin: 300.10
Raw: 614.00    Fahrenheit: 59.10    Celsius: 27.10    Kelvin: 300.10
Raw: 614.00    Fahrenheit: 59.10    Celsius: 27.10    Kelvin: 300.10
Raw: 614.00    Fahrenheit: 59.10    Celsius: 27.10    Kelvin: 300.10
Raw: 616.00    Fahrenheit: 60.08    Celsius: 28.08    Kelvin: 301.08
Raw: 614.00    Fahrenheit: 59.10    Celsius: 27.10    Kelvin: 300.10
Raw: 614.00    Fahrenheit: 59.10    Celsius: 27.10    Kelvin: 300.10
Raw: 614.00    Fahrenheit: 59.10    Celsius: 27.10    Kelvin: 300.10
Raw: 615.00    Fahrenheit: 59.59    Celsius: 27.59    Kelvin: 300.59
Raw: 617.00    Fahrenheit: 60.56    Celsius: 28.56    Kelvin: 301.56
Raw: 615.00    Fahrenheit: 59.10    Celsius: 27.10    Kelvin: 300.10
Raw: 614.00    Fahrenheit: 59.10    Celsius: 27.10    Kelvin: 300.10
Raw: 615.00    Fahrenheit: 59.10    Celsius: 27.10    Kelvin: 300.10

The room temperature is about 21.5C°, also there is something wrong.
Here my questions:

  1. Is the LM335 attached correctly?
  2. Do I have to adjust the sensor? If yes, how? Please, step by step if possible, I'm really noob :slight_smile:

Thank you a lot for your help!!

Simon

The first question is whether or not the values being read change (correctly) as the sensor warms up or cool down.

yes, if i warm up the sensor, the values are increasing...
i think... not sure... its correctly connected... ive tested 2 different lm335z, same values.
at this point i think there is a kind of operation to adjust/calibrate the values.... but I dont know if and how.

any help apreciated :slight_smile:

-edit-
Note: I'm not sure it's important, BTW the arduino is powered by USB connection on PC.

This is not too surprising. The initial uncalibrated accuracy is +/-3 degrees or so from the nominal 25C, plus you have the +/-3 LSB (or so) built in to the A/D converter (which can give an error of +/-1.5-2 degrees). That your readings are 6 degrees away from room temperature (and how confident are you in that measurement?) is reasonable.

To calibrate the sensor, connect a potentiometer across the sensor, with the adjustable ("wiper") terminal connected to the adjustment terminal. Adjust the pot to read the correct voltage at a known temperature, and that should be it.

--
The Quick Shield: breakout all 28 pins to quick-connect terminals

I'm really sorry, but could you give me more detailed instructions on how calibrate it? :frowning: To start I have a digital precise temperature sensor that could give me exact ambient temperature (if needed). Or is enough to calibrate it software editing the code? (exactly no idea how too).
Thank's a lot (meanwhile I'm googling too ;))

If you have a precision digital temperature sensor you can use as a reference, that is good. Take its reading -- let's say it is 21C. That is 294K. You then want to adjust the potentiometer that you have connected to the LM335Z until the output of the LM335Z reads 2.94V.

The top of page 6 of the LM335Z datasheet shows how to hook up this potentiometer:

http://www.national.com/profile/snip.cgi/openDS=LM335

--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, light sensor, potentiometers, pushbuttons

Thank you!
I'll take a look to the document.
A question. There is mentioned I need a potentiometer to set the correct "offset" and calibrate the temperature.
When finished do I need to leave the potentiometer attached?
In addiction, could I calibrate it via software, calculating the offset and simply apply it?

Thank's a lot!!

Simon

Well, you need to leave the potentiometer attached if you want the product to maintain the voltage you calibrated it to. However, you could do the following:

a) Measure the uncalibrated voltage (no potentiometer)
b) Measure the calibrated voltage (with potentiometer properly adjusted)
c) Remember the difference between them and put this in your software.

Then, you can remove the potentiometer and compensate for the difference between calibrated/uncalibrated readings in software.

--
Need a custom shield? Let us design and build one for you.

I hope this approach is good too:

My room thermometer shows me 23.3C° that are 296.3Kelvin

The raw analog value read from LM335Z is 612.
This, converted in Kelvin is:
(((sensorValue / 1023) * 5) * 100) = 299.12Kelvin

Now, if:
612:299.12=x:296.3
x=296.3*612/299.12
x=606,23

offset=612-606=6.

Also, if I subtract the offset to the sensorValue I should obtain the right value.

Is this right?

Thank's a lot for the support!

Simon

That sounds right.

I forgot to mention that the "5" in your calculations (e.g., x/1023*5) is really the 5V supply to your board, which is not necessarily exactly 5V, especially when powering the board from USB as you say. You should expect some variation due to this issue, and definitely variation from computer to computer.

--
The Quick Shield: breakout all 28 pins to quick-connect terminals

The LM335s require a rock solid analogue reference voltage to give accurate readings. The aref comes from the 5v line and if its powered from a typical USB it is probably some way from 5v (typically 4.7 - 4.8 v). It will probably give better readings if you power it from the DC jack.

Thank you RuggedCircuits for the support, really appreciated!!
I'm happy to start understood how all this works even if I've a lot to learn :slight_smile:

Pluggy, thank you too for the suggestion.
Yes, arduino is powered from USB. If this is unstable, that could be thecause of my offset. Very well :slight_smile:

Another question concern the arduino:
I've tried to power it with external 12V DC adapter (arduino + ethershield). It becomes very hot after some minutes also I've choosed to stay on PC usb. I've read it's "normal" with the ethershield and 12V power.
What is the suggested power adapter for my pruposes?
When is better to increase the V of the power adapter?

Thank's!

I think for this thread I've no other question.... forthis thread :)))

Simon

What is it that becomes hot, the Arduino or Ethershield?

The "best" power adapter is 7V. It should be rated for at least the amount of current drawn by an Arduino (~30-40mA) plus the Ethershield (??? mA). The lower the voltage the better as it minimizes heat loss in the voltage regulator on the Arduino. Below 7V, however, there is a risk that you won't get a proper 5V supply voltage.

For this reason a 9V adapter is better than a 12V adapter if you don't have 7V.

--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, light sensor, potentiometers, pushbuttons

Somewhere I've read about 150mA of power used by Ethershield, hope right.
If so, than I'll search a 7V adapter, stable as possible, or instead max 9V.

Thank you so much!

Simon

Yep, the arduino's voltage regulator does get hot with 12V and an ethernet shield. I have an old phone charger that kicks out about 8.5 volts on load, its quite happy with that.

Thank's a lot to all for suggestions.
I'll check the issues with power adapter in these days.
Meanwhile I've another question concern the themperature sensor.
All works well, but on arduino I have 1 sensor and 1 led. If I turn the led on, I think the sensor is receiving minor power and so the valure obtained is different. If I turn the led off, the value goes back to right value again. Will this solved with a good power adapter?

Thank's!

Simon

Hi again.
Could someone help me in my issue and doubt how described befor?
Thank's again for the precious help!

Simon