Calibrating a tmp36

Hey there,

I have a tmp36 interfaced to a Duemilanove. I’m sending the tempF to the serialPort and I’m not sure that it is very accurate.

Is there a way to calibrate this?

#include <LED.h>

int sensorPin = 0; 
int greenPin = 2;
int redPin = 3;


//the analog pin the TMP36's Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures

void setup()
{
  LED.create(greenPin);
  LED.create(redPin);
  //LED.create(2);
  Serial.begin(9600);  //Start the serial connection with the computer                     
}
 
void loop()
{ 
 int reading = analogRead(sensorPin);  
 float voltage = reading * 5.0 / 1024; 
 
 Serial.println(voltage);
 
 float temperatureC = (voltage - 0.5) * 100 ;  
 //converting from 10 mv per degree wit 500 mV offset to degrees ((volatge - 500mV) times 100)
 //convert to Fahrenheight
 float tempF = (temperatureC * 9 / 5) + 32;
 Serial.print(tempF); Serial.println(" degress F");
 
 if(tempF > 70 && tempF < 80 ){
   LED.on(greenPin);
   LED.off(redPin);
 }
 if(tempF < 70 | tempF > 80){
   LED.on(redPin);
   LED.off(greenPin);
 }
  
  delay(1000);  
}

at a glance

(temperatureC * 9 / 5) + 32;

perhaps should be

(temperatureC * 9.0 / 5.0) + 32.0;

and so forth, for other constants.

me myself, I’d avoid using floating point. Scale up by 1000 or so, using a 32 bit int with an implied decimal point. when displaying/printing, divide to print whole number part, and get fractional part with a modulo or some such operator. Floating point costs a lot of memory.

Thanks!