 LM35 Temp Sensor Equation

Hi Everyone:

I'm really new at Arduino so, please pardon my ignorance in this question.

I've been working on a simple circuit and using the Arduino with an LM35 temp sensor. The code works just fine to provide me the correct temperature output but, I really don't understand the equation that is used with the ADC.

When I take a voltage reading on the sensor at approximately 20 degrees C, the voltage output from the sensor is about 204mV. The equation: temp * 0.48828125 provides me the 20 degrees C. However, when I do the math and multiply the 204mV x the 0.48828125 is will not provide an answer of 20 degrees C.

Would someone please explain how the LM35 works with the ADC, relative to the calculations? My numbers don't jive and I really want to understand how the LM35 output relates to the equation and ADC to provide the 20 degrees C temp that is on the Serial Monitor.

Thanks in advance for helping a real newbee!

204mV on the analogue pin gives an A/D value of 0.204/5 * 1024 = ~42 (assuming 5volt Arduino).
"temp * 0.48828125" should be "A/D value * 0.48828125", which is 20.4C.
But.. A/D value is an integer, and can only be 41 or 42 in this case.
Calculating to 20.0C or 20.5C.
An average (bad) resolution of ~0.5C per step of the A/D.
Therefore it's better (for two reasons actually) to use the internal 1.1volt Aref.
That gives a ~5 times better resoluting from the A/D, so a temp resolution of 0.1C is possible.
And it makes the A/D independent of the potentially unstable 5volt rail.
Example code attached.
Leo..

// connect LM35 to 5volt A0 and ground
// calibrate temp by changing the last digit(s) of "0.1039"

const byte tempPin = A0;
float calibration = 0.1039;
float tempC; // Celcius
float tempF; // Fahrenheit

void setup() {
Serial.begin(9600);
analogReference(INTERNAL); // use internal 1.1volt Aref
// change INTERNAL to INTERNAL1V1 for a Mega
}

void loop() {
tempC = analogRead(tempPin) * calibration; // get temp

tempF = tempC * 1.8 + 32.0; // C to F
Serial.print("Temperature is  ");
Serial.print(tempC, 1); // one decimal place resolution is all you get
Serial.print(" Celcius  ");
Serial.print(tempF, 1);
Serial.println(" Fahrenheit");

delay(1000); // use a non-blocking delay when combined with other code
}

Now the question: why that "0.1039".

100*(Aref/1024.0) = 0.1039

100 "10mV/degree sensor steps" in a volt.
And my 1.1volt Aref was about 1.064volt.
Different for every Arduino, but stable.
That's why you should calibrate your thermometer.
Leo..

1. LM35 data sheet says the following:
The sensor has no offset, and it generates 10 mV signal for each 0C temperature change. That means that:
(1) At 200C temperature, the sensor will produce an output signal of 200 mV.
(2) At 500C temperature, the sensor will produce an output signal of 500 mV.

2. Now, we have the following response points for LM35 sensor:

A(20, 0.200)
B(50, 0.500)
C(T, V)              //the unknown point -- at T[sup]0C[/sup] temperature, the sensor produces V volt signal.

3. From the response points of Step-2, we can find the following equation using the principals of co-ordinate geometry:

T = 100*V

4. Assume voltage at VREF-pin of the 10-bit ADC of the MCU is 1.1V. This is known as Full Scale (FS) of the ADC. Now, we have –

(1) When input voltage to ADC is 1.1V (FS), the ADC gives all 1s at its output which is 1111111111(1023)

(2) When input voltage to ADC is V volt, the ADC gives at its output a bit pattern whose value is (1023/1.1)*V

(3) The value of the ‘output bit pattern’ of the ADC can be brought into the variable x by executing the following instruction:

int x = analogRead(A0);    //assume that signal of LM35 is connected at A0-pin of UNO

5. Now, the equation of Step-3 can be written as –

==> T = 100*V

6. Let us see how much temperature reading the UNO will produce when the LM35 produces a signal of 204 mV.
==> 204 mv
==> 0.204 V

From Step-4(3)–