How to calibrate sensor TMP36 for first time use?

Hello Everyone,

I have just started with Arduino (and with microcontroller programming in general) yesterday..

Have bought the Arduino Starter Kit that comes with an UNO card and many useful components and sensors.

In brief, I am through my third experiment with Arduino (following the book here to get a bit of practice) which involves the use of TMP36 to measure and display room temperature measured by sensor.

Using the formula suggested by the book for converting voltage into Celsius degrees ( temperature = (voltage - .5)*100) the temperature measured fluctuates between -18 and -20 which is obviously an error...

I have searched forums for indication on how to perform a calibration of this sensor, in the hope it can help and since it is vaguely mentioned in the book, but I have honestly come out of those readings with more confusion than before.

Is there anyone out there available to give some hints and some how-to reference?

Thanks in advance.

A new Arduino-lover

Luca

For informed help, please read and follow the directions in the "How to use this forum" post.

Err.. I have searched google and read a few seemingly related threads in this forum, without finding the answer to my query... therefore this post.

Thanks..

Just for reference, below is the code I am using, with 5V connection to Arduino board and A0 analog pin used for the sensor TMP36.

I have tried with another TMP36 sensor and results are still shown the same way :-(, so I guess that at least means the sensor itself is not faulty..

const int sensorPin = A0;
const float baselineTemp = 20.0;

void setup() {
 // put your setup code here, to run once:

Serial.begin(9600);

for(int pinNumber = 2; pinNumber<5; pinNumber++) {

 pinMode(pinNumber, OUTPUT);
 digitalWrite(pinNumber, LOW);
}

}

void loop() {
 // put your main code here, to run repeatedly:

int sensorVal = analogRead(sensorPin);
Serial.print("Sensor Value: ");
Serial.print(sensorVal);

float voltage = (sensorVal/1024.0) * 5.0;
Serial.print(", Volts: ");
Serial.print(voltage);
Serial.print(", degrees C: ");

float temperature = (voltage - .5) * 100;
Serial.println(temperature);

if(temperature < baselineTemp) {
 digitalWrite(2, LOW);
 digitalWrite(3, LOW);
 digitalWrite(4, LOW);
} else if(temperature >= baselineTemp+2 && temperature < baselineTemp+4) {
 digitalWrite(2, HIGH);
 digitalWrite(3, LOW);
 digitalWrite(4, LOW);
} else if(temperature >= baselineTemp+4 && temperature < baselineTemp+6) {
 digitalWrite(2, HIGH);
 digitalWrite(3, HIGH);
 digitalWrite(4, LOW);
} else if(temperature >= baselineTemp+6) {
 digitalWrite(2, HIGH);
 digitalWrite(3, HIGH);
 digitalWrite(4, HIGH);
}

delay(2000);

}

I have reviewed it multiple times and cannot seem to find the error.

Also, the physical setup of the circuit looks OK...

Any ideas?

Thanks
Luca

Is it too much trouble to follow directions? Use code tags.

jremington:
Is it too much trouble to follow directions? Use code tags.

Thanks, very helpful directions! :slight_smile:

code tags implemented. :slight_smile:

I don't see anything wrong with the code, so there is probably something wrong with your setup.

Please post a circuit diagram (hand drawn, not Fritzing diagram) and a photo of your setup.