LM335z temperature sensor only ever displaying 1022.

I am trying to use an LM335z temperature sensor (pretty much the same as an LM335) but for some reason it only displays 1022 on the serial monitor when I read it with an analog pin, I would expect it to display 200 or 500 or something but the whole day it's been stuck on 1022. It would also be helpful if you could tell me the calculation necessary to convert the voltage to temperature.

Thanks.

There's probably something wrong with your code or how you wire it up. Or something.

We are not telepathic, if you don't show us what you have any help is guess work.

Please, before you do anything else please take a moment to read General guidance and
How to use this forum

Post your code and schematic in the manner specified, then someone might be able to help.

Thank you.

This is simply my code, it shouldn't be relevant because of it's simplicity but that's it:

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

void loop() {
Serial.println(analogRead(A0));
}

For the schematic style thing, I have used the image below as reference. In the output pin, I have taken 5V (from the rails on my breadboard which I think might possibly interfere a bit) and another wire leading to the analog output, and for the ground pin I have taken the wire across to ground; I saw all this in a few tutorials and diagrams.

This is how you should wire it:

And make sure you have it connected properly.

Sorry I'm a bit of a noob when it comes to reading schematic like those can you tell me how to wire that in relativity to the image I put up?

The first few pages of the datasheet show the pinout and have that circuit, its not difficult to relate the two:
http://www.ti.com/lit/ds/snis160e/snis160e.pdf?&ts=1589291842378 Note the ADJ pin is optional.

Phoenix,
I realise you are new to electronics and micro-controllers but I cannot believe you are not familiar with the pointy things we call 'pencil' and the flat white stuff we call 'paper'. The idea of a schematic is you push the pointy end of the pencil around on the paper and make some kind of representation of how you have things wired up. Doesn't have to be neat, just has to accurately show where the wires go. When you have done that take a photo and upload so we can see.

You don't have to provide the information we ask for of course, equally we don't have to help you.

Maybe you should give this a read, there is much more to the code than you have.

Wire it as shown in the link above. The code looks like this:

/*
 * Rui Santos
 * Complete Project Details https://RandomNerdTutorials.com
 */
 
const int sensorPin = A0; 
float sensorValue;
float voltageOut;

float temperatureC;
float temperatureF;

// uncomment if using LM335
//float temperatureK;

void setup() {
  pinMode(sensorPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  sensorValue = analogRead(sensorPin);
  voltageOut = (sensorValue * 5000) / 1024;
  
  // calculate temperature for LM35 (LM35DZ)
  temperatureC = voltageOut / 10;
  temperatureF = (temperatureC * 1.8) + 32;

  // calculate temperature for LM335
  //temperatureK = voltageOut / 10;
  //temperatureC = temperatureK - 273;
  //temperatureF = (temperatureC * 1.8) + 32;

  // calculate temperature for LM34
  //temperatureF = voltageOut / 10;
  //temperatureC = (temperatureF - 32.0)*(5.0/9.0);

  Serial.print("Temperature(ºC): ");
  Serial.print(temperatureC);
  Serial.print("  Temperature(ºF): ");
  Serial.print(temperatureF);
  Serial.print("  Voltage(mV): ");
  Serial.println(voltageOut);
  delay(1000);
}

Note the part about:
"The following code reads the temperature from the LM35 sensor and displays the readings in the Serial Monitor. This code is also compatible with LM335 and LM34 – you just need to uncomment some lines in the code to use the right sensor".

Ron

PerryBebbington:
Phoenix,
I realise you are new to electronics and micro-controllers but I cannot believe you are not familiar with the pointy things we call 'pencil' and the flat white stuff we call 'paper'. The idea of a schematic is you push the pointy end of the pencil around on the paper and make some kind of representation of how you have things wired up. Doesn't have to be neat, just has to accurately show where the wires go. When you have done that take a photo and upload so we can see.

You don't have to provide the information we ask for of course, equally we don't have to help you.

All wonderful things begin with a pencil and paper but over the years I learned a big eraser can also be important. :slight_smile:

Ron

Here’s a good page:

https://web.mit.edu/rec/www/workshop/lm335.html

Over the years I learned a big eraser can also be important

:o

@Ron_Blain.
The code you linked to in post#7 is written by someone who didn't understand.
It's potentially unstable (VCC as Aref) and has a low temp resolution (~1/5 of the A/D used).
Should not use that sketch as an example.

Better LM335/TMP36 code uses the internal 1.1volt Aref.
That turns the Arduino in an absolute/voltage A/D (not ratiometric), more suited for these voltage output sensor.
And in increases resolution 5x, so you can actually use one decimal place that makes sense.
Leo..

I wasn't able to take a photo because my phone is broken, and I find it interesting that you assumed that I don't know what paper and pencils are, I thought you said you aren't telepathic.

Goodbye.

Wawa:
@Ron_Blain.
The code you linked to in post#7 is written by someone who didn't understand.
It's potentially unstable (VCC as Aref) and has a low temp resolution (~1/5 of the A/D used).
Should not use that sketch as an example.

Better LM335/TMP36 code uses the internal 1.1volt Aref.
That turns the Arduino in an absolute/voltage A/D (not ratiometric), more suited for these voltage output sensor.
And in increases resolution 5x, so you can actually use one decimal place that makes sense.
Leo..

Wawa:
@Ron_Blain.
The code you linked to in post#7 is written by someone who didn't understand.
It's potentially unstable (VCC as Aref) and has a low temp resolution (~1/5 of the A/D used).
Should not use that sketch as an example.

Better LM335/TMP36 code uses the internal 1.1volt Aref.
That turns the Arduino in an absolute/voltage A/D (not ratiometric), more suited for these voltage output sensor.
And in increases resolution 5x, so you can actually use one decimal place that makes sense.
Leo..

Very true and no, not the best example. However, I wanted to just give the original poster something that should display something other than his/her problem. Thanks for poing that fact out though.

Ron