Posts Tagged ‘temperature’

LM335 – Calibration

July 24, 2012 Leave a comment

After attempting to hook up an LCD to display the temperature and getting readings of above 90°F inside a well air conditioned room, I decided that attempts to determine the accuracy of the LM335A sensor were in order. (LM335A datasheet here .PDF) I will be attempting multiple calibrating procedures, but the easiest and most basic one should be the boiling point, which is most frequently used for calibrating kitchen thermometers.

I was going to check the accuracy of the sensor using the know temperature of freezing (32°F or 0°C) and boiling water (212°F or 100°C), but seeing as electricity and water don’t mix very well I needed some way to protect the sensor and the Arduino.

There was no way I was going to do these tests with the sensor on a breadboard so I had to hook it up to a cable. To prevent signal degradation due to noise caused by electromagnetic interference, which the datasheet specifically warns about, I decided to use the shortest cable I could find. The cable came from a disposable pulse-oximetry sensor, which happened to be well shielded (bonus!).

The Setup:

I stripped the cable and soldered it into the same configuration that was on the breadboard. One end of the cable was attached to the sensor, and the other to the breadboard via headers (whose plastic melted and loosened up the pins, rendering the header much less useful).

The sensor end of my cable required special consideration as it would be immersed in both boiling and freezing water. I needed a waterproof way to contain the sensor without decreasing thermal conductivity, using something that wouldn’t melt at 100°C. To do this I fit the sensor within a disposable thermometer probe cover whose tip I filled with thermal grease. An alternative would have been to use heat shrink tubing, as recommended in the datasheet.

Before going into the extremes I decided to compare readings against the outdoor temperature at my location. I pulled up the temperature from and sat the sensor probe against the mesh of an open window. The results were rather surprising:

(Note: the temperature was two hours old when this picture was taken, in which time the temperature had rose. The temperature was 4°F more three hours later.)

Could it be that the LM335A was already acceptably calibrated? It appeared to be within the +/- 1°C (+/- 1.8°F) uncalibrated temperature error at 25°C (77°F) specified in the datasheet. The only way to find out was to continue with the tests.

For the freezing temperature test the setup is seemingly simple; get a bunch of ice and put it in water. The problem is that the temperature will not be exactly accurate to freezing, and the elevation, and atmospheric pressure could alter our results, but for my purpose it was good enough:

Interesting, so it would appear that my sensor was giving me a reading that was too low for the expected temperature of freezing water. While expecting 0°C (32°F), we got -2°C (29°F), so we are low by about 2°C in this test.

Next test is boiling temperature, again the elevation plays a part, as does atmospheric pressure. (Fun Fact: In Denver, Colorado, which is at an elevation of about one mile, water boils at approximately 95 °C.) One important thing to know is that there are different stages of “boiling”, which I found out after performing this test. Unfortunately, it seems that I may have never reached the true boiling point of water. I was using a small sauce pan, and was unable to achieve a rolling boil of required, so these results may have been less useful:

Even though these results may be too low, and less useful, they were still relatively close to the expected value. While expecting 100°C (212°F), we got 97°C (206°F), so we are low by about 3°C in this test.

Interestingly, the most useful and entertaining result came from my attempting to obtain a sublingual temperature. Human body temperature, as it turns out, is a relatively stable and reliable source for temperature calibration; varying by only a few degrees from person to person and through the day.

The normal core body temperature of a healthy, resting adult human being is stated to be at 98.6 degrees fahrenheit or 37.0 degrees celsius. Though the body temperature measured on an individual can vary, a healthy human body can maintain a fairly consistent body temperature that is around the mark of 37.0 degrees celsius.

The normal range of human body temperature varies due to an individuals metabolism rate, the higher (faster) it is the higher the normal body temperature or the slower the metabolic rate the lower the normal body temperature. Other factors that might affect the body temperature of an individual may be the time of day or the part of the body in which the temperature is measured at. The body temperature is lower in the morning, due to the rest the body received, and higher at night after a day of muscular activity and after food intake.


The typical oral temperature measurement is slightly cooler, at 36.8° +/- 0.4°C (98.2° +/- 0.7°F), which means the oral temperature results of 33°C (92°F) meant my sensor was still off by about 3.8°C (6.2°F), . Seeing as average body temperature varies by about a degree, I would say that this method would be sufficient for achieving around +/- 1°C (1.8°F) calibration in a pinch.

All in all, I can definitively say that this sensor is reading 1 – 2°C (1.8 – 3.6°F) low through the range of 0 – 100°C. While I did not calibrate the sensor yet (that will be in part two of this post, which will come eventually) I ended up learning a whole lot about taking measurements, comparing expected vs actual values, looking for variables that could modify my results unexpectedly and setting up tests.


Allfoodbusiness: How To Calibrate Thermometers (This is an excellent guide for thermometer calibration that I will be using in my next post.)

Physics Fact Book: Temperature of a Healthy Human

Wiki: Shielded Cable

Understanding Cable Shielding (.PDF)


LM335 – Measuring Temperature

July 12, 2012 Leave a comment

I recently ordered a whole bunch of components, sensors and parts off of Mouser, one of which was the LM335A temperature sensor.

The LM335A is part of the LM135 series, which are precision, easily-calibrated, integrated circuit temperature sensors. It operates as a 2-terminal zener, and has a breakdown voltage directly proportional to absolute temperature at +10 mV/°K. With less than 1 Ohm dynamic impedance the device operates over a current range of 400 mA to 5 mA with virtually no change in performance. When calibrated at 25°C the LM135 has typically less than 1°C error over a 100°C temperature range. Unlike other sensors the LM135 has a linear output.

All this and more information about the sensor can be acquired in the datasheet here.

The important parts to know are that it works like a zener diode with a breakdown voltage that is proportional to the temperature. A 10 mV increase correlated to a 1°K increase in temperature. Calibration of the sensor can be done via a potentiometer connecting output to ground. At this time I will be using the sensor uncalibrated, which will give a temperature error of +/- 1 – 3°C, I may attempt to calibrate it at a later date using the known temperatures of boiling/freezing water.




  • 2.2k Ohm resistor
  • LM335A

To use the sensor I set up this circuit on my protoshield:

5V is supplied to the (+) pin of the sensor through a 2.2k resistor, and GND is connected to the (-) pin. Analog 0 of the Arduino is also connected to the (+) pin.  This forms a circuit known as a voltage divider, and is a linear circuit that produces an output voltage that is a fraction of the input voltage. In my case, the voltage out changes as the break down voltage changes in the sensor, and is representative of the temperature.

Note: To calculate the resistor used in this circuit you would have to take into consideration the voltage drop of the sensor, which I don’t quite understand at this point so I will be saving this comment from SparkFun user “superbrad” for later use:

I believe the issue that most of you are having is that you are neglecting to take into account the ~3V drop of the LM335 into account. It is a diode, which needs to be included in the resistor calculation.
Ohm’s law: V = IR. But if you’re running on 5V, don’t use V = 5V! The diode blocks ~3V, so V = (5V – 3V) = 2V.
Solving for R where V = 2V and I = 1mA (R = V/I = 2V/.001A), you should find that a 2Kohm resistor at 5V is appropriate.
Best of luck.

Another thing to keep in mind is that since we are working with such a low voltage signal, it is important to keep the sensor close to the Arduino or the signal will be degraded and inaccurate. So I wouldn’t advise stringing up the sensor on a 20″ wire cable unless you use some kind of shielding or filtering/amplification like that which is demonstrated in the datasheet.


To get the sensor to start giving us data we tell the Arduino to do this:

int sensePin = 14; // Pin A0
float sensorValue = 0; //Set the sensor value as a floating number
void setup()
 pinMode(sensePin, INPUT);
void loop() 
 int sensorValue = analogRead(sensePin); //reads voltage on Pin A0
 Serial.println(sensorValue); //returns voltage on a 0 - 1023 scale (0 - 5 Volts)

And we get a response in the serial logger of something like this:

Now, this isn’t quite useful to us as it isn’t in the °C or °F temperature format we are used to so we have to convert what the sensor is spitting out to a human readable number. First thing we can do is convert the number to Kelvin, as we know that every 10 mV change in the output is equivalent to 1°K

float kelvinValue = (((sensorValue / 1023.0) * 5.0) * 100.0); // convert sensorValue to Kelvin

This is better, but we aren’t doing any science (yet) so we don’t want Kelvin, we want Celsius or Fahrenheit.

float celsiusValue = kelvinValue - 273.0; // convert Kelvin to Celsius
float fahrenheitValue = (celsiusValue) * (9.0/5.0) + 32.0; // convert Celsius to Fahrenheit

Now we can finally have the Arduino return the temperature of its environment in Celsius or Fahrenheit! Wooohoo! Here are the results with a little added formatting flair:

Click here to go to the completed sketch with formatting on pastebin. (updated Jul-14-2012)

Now that we have the ability to roughly (since our sensor is still uncalibrated) sense the temperature of the environment we can make all kinds of things! Computer fan controllers, green house temperature monitoring, self-regulating homebrewing fridges are projects that we are ready to take on.