I just bought a starter kit and I just started to use the temperature sensor TMP36. It is working properly as expected but I don't understand why we need to substract 0.5V to the reading to convert it to Celcius degrees. I read the documentation for the sensor but I don't get it. I suppose it is written somewhere in the documentation but I can't figure it out.
The TMP36 sensor already outputs 0.5volt at zero degrees C.
Or, said in another way, the sensor must be -50C for 0volt output.
Your code can use the voltage offset or the temperature offset.
"better" TMP36 code then in most starter kits attached.
Leo..
const byte tempPin = A0; // connect TPM36 to 3.3volt A0 and (not-shared) ground
float calibration = 0.1039; // calibrate temp by changing the last digit(s) of "0.1039"
float tempC;
void setup() {
Serial.begin(9600);
analogReference(INTERNAL); // use the stable internal 1.1volt Aref
}
void loop() {
tempC = (analogRead(tempPin) * calibration) - 50.0;
Serial.print("Temperature: ");
Serial.print(tempC, 1); // one meaningful decimal place is all you get
Serial.println(" C");
delay(1000); // use a non-blocking delay when combined with other code
}
I am using a 5V supply for the sensor and I understand I could use 3.3V as supply voltage.
I see 750mV@25degC and 10mV/degC in the documentation and also that there is an offset voltage of 0.5V.
If I need to substrct 0.5V (and multiply by 100) to get the temperature in Celcius, does it mean I won't be able to read a temperature below 0degC even if I see on page 3 that the "Linear Operating Temperature Range" is -40degC to +125degC?
prodonshape:
I am using a 5V supply for the sensor and I understand I could use 3.3V as supply voltage.
Yes, The TMP36 can work on a 3.3volt supply, which is usually a bit 'cleaner' on 5volt Arduinos.
Make sure you give the TMP36 it's own ground return (not shared on a breadboard), because any ground voltage/noise will appear in the temp readout.
prodonshape:
If I need to substrct 0.5V (and multiply by 100) to get the temperature in Celcius
Better to subtract 50 degrees C instead of 0.5volt, as I do in the example code.
You're not making a voltmeter, so you should code in A/D values and temps.
prodonshape:
I won't be able to read a temperature below 0degC even if I see on page 3 that the "Linear Operating Temperature Range" is -40degC to +125degC?
Yes, you can read below 0C, because of that 50C offset.
The code I gave you has a range between about -40C and +55C.
The +55C restriction is because I have used the (more stable) 1.1volt Aref.
A higher Aref means you can measure higher temps, but it also means a lower resolution.
Standard 5volt Aref code has ~0.5C temp steps. The code I gave you has ~0.1C steps.
(5/1024 = ~5mV, 1.1/1024 = ~1mV).
Leo..
I'm a beginner but your comments are definitely helping me a lot! I will have a closer look at your code and try it later. I know there is a project in the starter kit which allow to calibrate a sensor. It will probably teach me to change the range a sensor operates. I will also read on Aref which I don't know yet what it is.