I've been playing around with the
LM335A temperature sensor. I chose it over the one-wire sensors strictly due to cost - it's only $1.50. The first project was connecting it to the arduino and converting the output into a valid temperature. I used a 2.2K resistor and connected it using the simple temperature sensor schematic in the datasheet. My first results were a little screwy - I knew it was not 700 kelvin in my office. Turns out I was reading the sensor wrong, I was expecting the raw value to be the temp in kelvin but it is not. You have to do a conversion.
The analog to digital converter in the
Arduino basically divides the reference voltage (5 volts) into 1024 "steps" from 0-1023. This is the number that you get when you read from an analog pin. To convert this number into the voltage you need to do a little math - input value / 1023 * 5. That's the input value, divided by the max value, and multiplied by the reference voltage. Simple, but it took some time to track that tidbit down.
To convert the voltage into kelvin for the LM335A you simply multiply by 100. The LM335A outputs 10mv for each unit kelvin, so 296 kelvin is 2.96 volts. Simple. To convert to celsius subtract 273. So degrees celsius = kelvin - 273. To convert to farenheit multiply the celsius temp by 1.8 and add 32.
At the moment my code simply reads the value from analog pin 0, does the conversions, and outputs the results to the serial port.
// temp probe
// Jonathan Smith 2009
// simple program that reads the value from a LM335A, converts to
// kelvin, celcius, and farenheit, and outputs the result.
int TempPIN = 0; // analog pin LM335A is connected to
int LedPIN = 13; // in case we want to flash an LED
float TempVAL = 0; // holds the temp val, we need this to be a float
void setup(){
Serial.begin(9600); // set baud rate
}
void loop(){
TempVAL = analogRead(TempPIN); // get value from LM335A
Serial.print("Raw Value: ");
Serial.println(TempVAL);
Serial.print("Kelvin: ");
TempVAL = (((TempVAL / 1023) * 5) * 100); // convert value to kelvin
Serial.println(TempVAL);
Serial.print("Celsius: ");
TempVAL = (TempVAL - 273); // convert value to celsius
Serial.println(TempVAL);
Serial.print("Farenheit: ");
TempVAL = (TempVAL * 1.8 + 32); // convert value to farenheit
Serial.println(TempVAL);
delay(1000);
}
For phase 2 I built the simple adjustment circuit in the data sheet using a 330 ohm resistor and a 10K ohm potentiometer. I used a cheap radio shack trimmer/potentiometer, I'd recommend a better trimmer, it's hard to adjust the values precisely on the radio shack one. Using a larger resistor would probably have helped as well, like the 2.2K ohm I was originally using.
Even though it's less than ideal, I slapped the circuit together on a scrap of project board. I was tired of building the circuit and tearing it back down on a breadboard, this way I have a temperature module ready to plug in whenever I want it.

This has been a very simple project, but useful. In addition to a functional temperature sensor, I also have a better idea how to interface sensors using the analog ports. Next up is a light-level sensor using a CdS photocell. I'm also trying to get my hands on a pre-paid cell phone that I can use to send SMS messages, the ultimate goal is to build a environmental data logging device that will record several different types of data including temperature and location (from a GPS unit) and log it to an SD card and transmit it to a twitter account via SMS. I may have to move up to an arduino mega, eventually, but at the moment I am building and testing one sub-system at a time, so my little Diecimila has been sufficient.