8051 temp sensor adc

Thread Starter


Joined Jan 1, 2011
I am trying to display the temperature from an LM35 on an LCD. I am sure that i am getting something from the internal adc of 8051 as when tested with a pot, i was getting a small range that varied linearly. My problem is in modifying and adjusting the adc according to the output of the LM35. The code is attached. Any help would be appreciated a lot. thanks



Joined Apr 24, 2011
Sorry I can't help with your code, I don't use the 8051 so I can't see how you are using it. But generally...

An A2D will convert a voltage to a pure number according to the following:

Number = Voltage / Vref * (2^bits -1)

For a 10 bit A2D using a 5V reference this becomes:

Number = Voltage / 5 * (1023) = Voltage * 204.6/V (/V means "per volt" as Number is pure (has no dimension))

(Note that while this expression has a real number (the ".6" part) the Number will be an integer value).

The LM35 produces an output voltage of 10mV per °C from +2°C to +150°C, so it's output is 20mV to 150mV.

For a 5V reference this isn't the worst thing. Your resolution, or the change in Number for a change in Voltage is:

Voltage = Temp * 10mV/°C

delta Voltage for 1°C change = 10mV/°C

delta Number (for 1°C change) = 10mV/°C * 204.6/V = 2.046 /°C

As this delta is greater then 1 you get something acceptable.

You can use the relation between Number, Voltage, and Temp to Voltage to solve for Temp from number:

Number = Temp[°C] * 10mV/°C * 204.6/V

Temp[°C] = Number / [ 10mV/°C * 204.6/V ] = Number / [ 2.046/°C ] = [ Number / 2.046 ] °C

Example: At 25°C

Voltage = 25°C * 10mV/°C = .25V

Number = .25V * 204.6/V = 51.15 (rounds down to 55)

Temp = [ 55 / 2.046 ] °C = 26.88 °C

The 1.88°C error is due to the finite resolution of the system. The easiest way to fix this is to use a reference voltage closer to the max Voltage input, here 150 mV. If your reference voltage is fixed you could put a gain stage between the LM35 and the A2D.