Currently I'm working with a MSP-EXP430F5529LP microcontroller and a LM35, because I need to built a thermometer. The results will show on a seven segment, 4 digit display. I'm using the following conversion, in order to show the temperature in Celsius:
voltage = (conversion * 3.3)/ 4095;
celsius = (((voltage - 0.5) * 100) / 10);
Problem is the reading of my own thermometer it's around 27°C and the reading I'm getting on the display it's around 53.4°C. I checked the voltage around the LM35 and the reading seems to be around 270mV, so I don't know what's wrong with the code.
I also tried with the following formula:
temp = (conversion*8.05); // 3.3/4096 it's around 8.05
tempC = (temp/10);
The previous one will give an acurrate reading at ambient temperature, but as I soon as I tried to drop it with an ice, it won't come down.
From looking at the datasheet for the LM35, it seems that it outputs a voltage that scales as 10mV per degree Centigrade.
This includes outputting a negative voltage if the temperature is below 0C. I am going to assume that you don't care about that, since I'm sure the ADC on your micro can't measure negative voltages.
I'm also assuming that the ADC on the micro has 12-bit resolution, based on your attempt to divide by 4095. So I'd guess that an input voltage of 3300mV on your ADC pin would read as 4095, and 0V on the input reads as zero.
Therefore, the formula you require is:
This can be simplified, by both absorbing the
/ 10into the multiplication, and dividing by 4096, which is just a bit-shift on most CPUs. This gives:Note that this can all be done with integer arithmetic if you're happy not to have a fractional result.