The Classroom

The LM335 Temperature Sensor

Daniel Koch

Issue 27, October 2019

This article includes additional downloadable resources.
Please log in to access.

Log in

Measuring temperature in your project can be made easy using the tiny LM335 sensor.

In this issue of The Classroom, we take a look at the geometry of the LM335, what makes it work, and how you can use it. We’ll also explore a demonstration circuit that you can take inspiration from. As usual, downloading a copy of the manufacturer’s datasheet is helpful because it contains a great deal more diagrams than we can hope to replicate.

On the subject of datasheets, they are generally produced by the original design team, and then provided to other manufacturers as part of production licensing. If you look closely at the first page of the LM335 datasheet from Texas Instruments, you may notice that it is word-for-word the same as the datasheet from National Semiconductor.

This means that, while we consulted TI's datasheet, you can likely work with whichever datasheet you find first.

WHY USE THE LM335?

The LM335 is set apart from most other temperature sensors available to the maker. Sure, if you’re an engineer with commercial ordering access, then there is not much you can’t get hold of. If you're a maker, however, you might be more used to NTC thermistors, thermocouples, and pre-made micro-controller modules. Most of these devices have some sort of response curve or slope. The combination of this means that a user has to figure out what voltage or current corresponds with a certain temperature, or what part of the response line is relevant to their set of circumstances. There is often little certainty of this for the maker.

The LM335, on the other hand, is truly linear within its operating range, but more importantly, its output is defined.

A QUICK LESSON ON NUMBER LINES

Temperature scales are number lines. The Kelvin and Celsius scales share the same sized unit of measure (unlike Fahrenheit), but the Kelvin scale starts at Absolute Zero, the coldest temperature currently known to science, where all movement of matter stops. Celsius, on the other hand, is the one most of us are familiar with, where undisturbed water freezes completely at 0° and boils (at one atmosphere of air pressure) at 100°.

So when displayed as a mathematically conventional number line, the Celsius scale has 0° somewhere toward the middle, negative numbers on the left, and positive numbers on the right. The Kelvin scale starts at 0° and has positive numbers to the right. But the size of the unit, the degree, is the same for both scales. The difference is that there is a 273° gap between the two zero points, as you can see in the diagram.

To put that in context, water freezes at 0°C and 273°K, and boils at 100°C and 373°K. Stay with us, this does have a point.

The output voltage from the LM335 is 10mV per Kelvin over the specified range of the LM335. At 0°C, the device has an output of 273 x 10mV = 2730mV, or 2.73V. At 25°C, the ISO ambient temperature standard, the corresponding number in Kelvin is 273 + 25 = 298. The voltage output is 298 x 10mV, giving us 2.98V.

This means that the voltage at the output can be read to give a meaningful, calibrated number that can be used by a block of code, or by eye. Even a simple voltmeter would work as a thermometer display, as long as you think in Kelvin or remember to subtract 273 from the number, and ignore the decimal point in both cases. You could also replace the dial card if you are using an analogue meter. This is what sets the LM335 apart from most of the usual slew of temperature sensors available to the maker.

GETTING TO KNOW THE LM335

The LM335 precision temperature sensor is built into a TO92 package. Other packages are available but are unlikely to be encountered by makers. Part numbers for the TO92 package include a ‘Z’ suffix. So, a device marked ‘335Z’ is just a 335, while ‘335AZ’ would be a 335A in a TO92 package. The ‘A’ version is a higher-accuracy, lower-tolerance version.

When looking at the flat face, the left-hand pin is the adjustment, marked ‘adj’ on schematics; the middle is the positive input, marked ‘+’ on schematics; and the right-hand pin is the negative output, marked ‘-’ on schematics. There is no defined ‘ground’ connection because the LM335 can be used in different configurations. In the majority of applications, however, the ‘+’ terminal is connected via a resistor to the supply voltage, the ‘-’ terminal is connected to ground, and the sensed output is taken from the junction between the supply resistor and the ‘+’ input, as in the simplified schematic.

The schematic symbol of the LM335 shows an adjustable zener diode, but the functional block diagram (which you can find in the datasheet) reveals that in fact there is no zener diode. There is, instead, a network of transistors, resistors, and capacitors which make the IC function as though it were a specialised zener diode. A zener diode normally has a fixed breakdown voltage. When reverse-biased (connected with the cathode more positive than the anode) it conducts but has a fixed voltage drop according to its specification.

The LM335’s internal network of components does the same, but the voltage drop is dependent on temperature, and is linear in its response. The temperature defines the voltage drop, rather than a relationship between components such as in the case of a resistor voltage divider. Depicting the IC with a zener diode makes sense.

This also reveals why the LM335 is used with a resistor and connected to ground, like a voltage divider would be, as above in the simplified sensor. Because the voltage drop changes, and the resistor is able to limit the current through the device to safe levels, the junction can be read like a voltage divider. It is just that this one is temperature-dependent and highly accurate.

CALIBRATING

In some applications, users may wish to calibrate their LM335 sensor. This is achieved using the calibrated circuit here. It uses a trimpot with its wiper connected to the ‘adj’ pin of the IC. There is some maths presented in the datasheet, which is valid for both calibrated and uncalibrated temperatures:

VOUTT = VOUTT0 × T/TO

In this formula,

VOUTT is the output for an unknown temperature

VOUTT0 is the output for a known temperature

T is the unknown temperature

TO is the known temperature.

In all cases, temperatures are in Kelvin. The neat thing with the LM335 is that its error is a slope error, which means the position of its linear response is shifted by the adjust pin. Getting it right for a known temperature means that the output is correct at all other temperatures within the range.

So the easiest way to calibrate the device is to use a known temperature and match the output. However, getting an accurate enough reference temperature will be the hard bit. Most thermometers have less accuracy as is, unless you spend lots on a professional grade model. Getting a temperature from, say, boiling water or ice, depends on other factors such as atmospheric pressure or purity of the water, respectively. We are fortunate enough to have an accurate thermocouple-based thermometer here for testing, and used that to match ambient air temperature.

For those without such a test instrument, the best way to calibrate is probably going to be with a medical thermometer. These are available from chemist shops, and are quite accurate within the temperature range they are intended to be used, which is within a few degrees of regular body temperature. They are affordable because they are made to be accurate only within this range.

We suggest using warm water with the tip of the LM335 dipped in it beside the thermometer (see the next section about waterproofing sensors). This will be more consistent than trying to use your finger tips or any other bodily source of warmth. Remember, the reading on the LM335 is in the Kelvin scale, so add 273 to whatever your Celsius thermometer displays.

USING THE LM335

The LM335 has a forward current limit of 10mA, but 5mA is preferred. The datasheet also lists the impedance as less than 1Ω. This is where the resistor often depicted with the LM335 comes into play. It provides the limited current, as anything over 10mA will destroy the device, and even currents over 5mA for sustained periods will cause harm. The datasheets recommend an operating current of 1mA for highest accuracy. 400μA is the stated minimum current.

Traditionally, an op-amp has been used as a comparator to make the LM335 into a temperature switch. Diagrams for that are to be found in the datasheets and can be used in conjunction with the classroom article on comparators in DIYODE issue 25. However, the real value for the maker in the LM335 is the numerical output. An accurate sensor with a comparator switch is great, and you can use trimpots to calibrate such a circuit against a known source, but using the LM335 as a sensor will feed a usable number directly into code for Arduino, Raspberry Pi, or other programmables, in a way few other sensors can. Reading an analogue pin will yield a usable result straight away, and the voltage is in the usable range with no further need for scaling or buffering.

The LM335 itself can be attached to a cable and mounted away from the circuit that uses it. The datasheets again are thorough in providing data about how long a cable run in a given gauge needs to be before a 1° loss is arrived at. Even for 24AWG wire, which is rather fine, this figure is over one hundred metres. If you use reasonable gauge wire and keep lengths no longer than needed, less than a couple of metres, you can ignore this factor.

Take care that your wire order remains consistent, as mixing it up could easily destroy the LM335. Make sure you carefully insulate connections from each other on the three pins of the device.

On that note, the sensor will need to be waterproofed for the sake of its metal legs and the connections to them. Choose a material that does not insulate thermally.

The datasheets recommend glue-lined heatshrink for this task. Some of these products are thinner than others, and this would affect how thermally insulative the heatshrink becomes when the glue is set.

You may wish to physically mount your sensor instead of leaving it dangling. A short length of copper bar is ideal. The sensor needs to be in firm contact with the surface, so using a pair of bolts with another small length of metal will clamp it securely.

Hands On:

LM335 Test Circuit

Parts Required:Jaycar
1 x LM335Z Temperature SensorZL3336
1 × Arduino Compatible UNOXC4410
1 × 4.7k 0.5W Resistor*RR0588
1 × 50kΩ TrimpotRT4364

* Quantity shown, may be sold in packs. You’ll also need a breadboard and prototyping hardware.

With a resistor, a trimpot, and the LM335, we will build the calibration circuit from above, connected to a microcontroller to read the output. We used an Arduino Uno and used the serial out function to display the ambient temperature on a computer monitor. Follow the schematic or Fritizing diagram, and your circuit will work fine.

We have chosen the resistor value to work the LM335 from 5V so that we can use the Uno’s supply. This results in a 4.7kΩ resistor, and a 50kΩ trimpot for adjustment.

The code for the Uno was quickly compiled, and as such, will likely need some finesse. With the code, we took a reading every second from the sensor. After calibration against our thermocouple thermometer, we moved it around, powered by a USB battery bank.

OUR OBSERVATIONS

Our own experiment sounds simple, but it wasn’t - most of our readings did not match expectation. We tested by putting the sensor (removed from the board) in the freezer, inserting again with tweezers, and reading it. We aimed a heat gun at it. We let it sit at room temperature. The readings were several degrees higher than expected every time.

Elsewhere in the office is a multimeter that is identical to our workbench one. After some experimenting with both multimeters, an old lab supply with voltage displays (themselves of unknown accuracy), and some resistor loads over the same power supply, we concluded that one multimeter read 80mV above the other.

This corresponds to 8° of variation, which accounted for what we were seeing in the serial monitor. Unfortunately, this can be an issue even in some expensive meters, and many commercial thermometers also have several degrees of inaccuracy, until you start to pay over $100 for a dedicated device.

The same can be said for the infrared non-contact thermometers. These have another caveat, being that they read a conical range. Don’t be fooled by the laser in the centre, that’s just the centre of the area. Ours is a fairly expensive one and still has a minimum read area of a 13mm diameter circle. This is far bigger than the LM335, and therefore reads some of the background as well.

After we determined this, we calibrated with the thermocouple thermometer. It was after this that we experienced success.

IN CONCLUSION

The LM335 is a versatile and accurate device that, with some calibration, will suit makers and programmers wishing to gain an accurate, defined temperature measurement. Although getting it to perform in the 10-bit environment took some fiddling, this is not out of line with any sensor with such fine resolution. We hope you have success with it and come up with some amazing applications.