Introduction: Using the LM335 Temperature Sensor

Picture of Using the LM335 Temperature Sensor

The LM335 is an easy to use, relatively precise temperature sensor. It is great for things like temperature loggers and temperature controllers. This sensor is much easier to use than thermocouples, because it does not require any additional interface circuitry. It is also easier than thermistors or other resistive temperature sensors, since it requires no calibration, and has a linear response.

When connected the sensor acts much like a Zener diode. Regardless what current is flowing through it, it will drop the same amount of voltage. The voltage at the output will be 10 millivolts per kelvin temperature. This means at a comfortable room temperature it will output about 2.93 V. This is close enough to the middle of our measurement range of 0-5V to allow a wide range of measurement with the arduino.

For this instructable you will need:

  • An LM335 sensor, in the TO-92 form factor (as shown)
  • A breadboard
  • An arduino
  • Some jumper wires
  • A 1 kiloohm resistor

Step 1: Connecting the Sensor 1

Picture of Connecting the Sensor 1

The pinout shown is the bottom view. The ADJ pin is for calibration, and can safely be left disconnected. We can do any calibration using the arduino sketch. Put the sensor in the breadboard as shown. Flat side toward you.

Step 2: Connecting the Sensor 2

Picture of Connecting the Sensor 2

Now connect a resistor to the center lead of the sensor, and run it to the other side of the breadboard. Connect the resistor to the 5V pin of your arduino.

Step 3: Connecting the Sensor 3

Picture of Connecting the Sensor 3

Connect a wire from the Analog 0 (A0) pin of your arduino, to the center lead of the sensor.

Step 4: Connecting the Sensor 3

Picture of Connecting the Sensor 3

Finally, connect the GND pin of your arduino to the right pin of the sensor.

Step 5: Measure Your Supply Voltage

If you are using an external power supply you probably have 5 V nearly exactly. If, on the other hand, you are powering your arduino from usb, you probably have a little bit less. Since the supply voltage is the reference for the ADC, you will need this to calibrate your measurements. Using a multimeter, find the voltage between the 5V and GND pin of your arduino, and write it down. I got 4.92.

Step 6: The Arduino Sketch

To read the temperature you now need to get the value of A0 using analogRead(0). This will give you a value between 0 and 1024. 1024 will represent the supply voltage. Below is an example sketch to read the LM335. You can download this code here. I split off the class I used here as an arduino library. If you want to use it you can download it here. Once you have that file, unzip it and copy it you your arduino/libraries directory. You can then import it into any sketch you like.

 class LM335<br>{
  float cal;
  int pin;
  public:
  LM335(float mCal, int mPin);
  float measureV();
  float measureK();
  float measureC();
  float measureF();
  float measureRankine();
};
LM335::LM335(float mCal, int mPin)
{
  cal = mCal;
  pin = mPin;
}
float LM335::measureV()
{
  float retVal = (float) analogRead(pin);
  retVal = (retVal*cal)/1024.0;
  return retVal;
}
float LM335::measureK()
{
  return measureV()/0.01;//10mV/k
}
float LM335::measureC()
{
  return (measureV()/0.01)-273.15;
}
float LM335::measureF()
{
  return (((measureV()/0.01)-273.15)*1.8)+32;
}
float LM335::measureRankine()
{
  return measureF() + 458.67;
}
LM335 mTemp(4.92, 0);//supply volts, analog pin
void setup()
{
  Serial.begin(38400);
}
void loop()
{
  Serial.print(mTemp.measureV());
  Serial.println(" volts");
  Serial.println("Temperatures: ");
  Serial.print("Kelvin: ");
  Serial.println(mTemp.measureK());
  Serial.print("Fahrenheit: ");
  Serial.println(mTemp.measureF());
  Serial.print("Celsius: ");
  Serial.println(mTemp.measureC());
  Serial.print("Rankine: ");
  Serial.println(mTemp.measureRankine());
  delay(1000);
}

Step 7: Upload and Run the Sketch

Once you hit upload, you can open the serial monitor. The output should look something like this:

Temperatures:  
Kelvin: 292.13 Fahrenheit: 66.16 Celsius: 18.98 Rankine: 524.83 2.92 volts Temperatures: Kelvin: 292.13 Fahrenheit: 66.16 Celsius: 18.49 Rankine: 524.83 2.92 volts Temperatures: Kelvin: 292.13 Fahrenheit: 66.16 Celsius: 18.98 Rankine: 523.96 2.92 volts Temperatures: Kelvin: 291.64 Fahrenheit: 66.16 Celsius: 18.98 Rankine: 524.83

Now you know how to measure temperatures with an arduino.

Comments

RickJ1 (author)2017-08-07

Thank you for this project. I have worked with the LM335Z several times now and I had never considered making a class for the gizmo. Great leap of intellect. Made my code simpler and clearer for my current client. Again, thanks.

mocivnik (author)2017-05-24

Thanks for this tutorial first, it helped me a lot!

But beacuse I cannot use the sensor on Analog pin A0 (already used), could you kindly tell me, which line I have to correct, so I can put it on Analog pin A1?

-Thanks again!

Graham Mantel (author)2015-11-24

This is great sketch, and works well ,---Thanks

DanielR34 (author)2015-11-17

The serial monitor still showing constantly value 14, I have no idea why :/

tomatoskins (author)2015-03-02

I remember using these in my sensors class a few years back. So much fun!

I have an alcohol sensor I can do one on next. I also want to show stepper motors and rc servos controlled from a phone over bluetooth. Is there something you think I should do?

The great thing about this site is you can share almost anything that you can make. I love everything about the arduino so anything that you make, people will look at.

About This Instructable

42,189views

49favorites

License:

Add instructable to: