// Project 13 - Serial Temperature Sensor
int potPin = 0;
float temperature = 0;
void setup()
{
Serial.begin(9600);
Serial.println("LM35 Thermometer ");
analogReference(INTERNAL);
}
void printTenths(int value) {
// prints a value of 123 as 12.3
Serial.print(value / 10);
Serial.print(".");
Serial.println(value % 10);
}
void loop() {
int span = 20;
int aRead = 0;
for (int i = 0; i < span; i++) {
aRead = aRead+analogRead(potPin);
}
aRead = aRead / 20;
temperature = ((100*1.1*aRead)/1024)*10;
// convert voltage to temperature
Serial.print("Analog in reading: ");
Serial.print(long(aRead));
// print temperature value on serial monitor
Serial.print(" - Calculated Temp: ");
printTenths(long(temperature));
delay(500);
}
There is a datasheet for this chip at http://www.st.com/stonline/books/pdf/docs/2158.pdf. There are some fancy things you can do to get super accuracy out of it, but for most purposes it seems that you just hook V- to ground, V+ to a current-limited supply (say, +5V through a 1K or 2K resistor), then read the temperature (10 mV per degree Kelvin) at ADJ.