Interface LM35 with 8051 ADC


The LM35 series are precision integrated-circuit temperature sensor, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 thus has an advantage over linear temperature sensorscalibrated in ° Kelvin, as the user is not required to subtract a large constant voltage from its output to obtain convenient Centigrade scaling. The LM35 does not require any external calibration or trimming to provide typical accuracies of ±¼°C at room temperature and ±¾°C over a full -55 to +150°C temperature range. Low cost is assured by trimming and calibration at the wafer level. The LM35's low output impedance, linear output, and precise inherent calibration make interfacing to readout or control circuitry especially easy. It can be used with single power supplies, or with plus and minus supplies. As it draws only 60 µA from its supply, it has very low self-heating, less than 0.1°C in still air. The LM35 is rated to operate over a -55° to +150°C temperature range. 

  • Calibrated directly in ° Celsius (Centigrade)
  • Linear + 10.0 mV/°C scale factor
  • 0.5°C accuracy guaranteeable (at +25°C)
  • Rated for full -55° to +150°C range
  • Suitable for remote applications
  • Low cost due to wafer-level trimming
  • Operates from 4 to 30 volts
  • Less than 60 µA current drain
  • Low self-heating, 0.08°C in still air
  • Nonlinearity only ±¼°C typical
  • Low impedance output, 0.1 Ohm for 1 mA load
        lm35 construction lm35 pin outs 

LM35 Pin Outs: 

Mainly the LM35 has 3 pins, which are: 
  • Pin 1: VDD - Supply voltage
  • Pin 2: Vout - Output analogue voltage, Linear + 10.0 mV/°C scale factor
  • Pin 3: GND - Ground

More information can be seen on the Datasheet of the LM35

lm35 pin outs 

How to Interface LM35 With the 8051? 

The Only method to interface the LM35 with the 8051 microcontroller is by using the internal ADC of 8051. With this method we can read the analogue voltage outputting the LM35 and so we can convert this value to temperature (since the LM35 has a Linear + 10.0 mV/°C scale factor). 

8051 ADC 

The Design for the system was controller by a microcontroller, which is the T89C51AC2. The microcontroller is the core of the system, which has a function of a monitor element and gives display the reading to the user. The T89C51AC2 has an integrated ADC, which has a resolution of 10-bit (Precision conversion) or 8-bit (Standard Conversion). Eight ADC channels are available for sampling of the external sources AN0 to AN7. An analog multiplexer allows the single ADC converter to select one from the 8 ADC channels as ADC input voltage (ADCIN). ADCIN is converted by the 10-bit cascaded potentiometer ADC. The conversion time of the ADC is of 16 microseconds and the Positive External Reference Voltage Range (VAREF) is between 2.4 to 3.0 Volt (typical). The input voltage (ADCIN) must be between 0 to 3V maximum. 

The LM35 has a scale factor of 10mV per 1oC, so the range of temperature set was between 0 oC and 100 oC. The LM35 would give a total output voltage 1v since every degree has a value of 10mv and so a range of 0 to 1V. This means that when the temperature is 0 oC then the output voltage is 0V. At 100 oC * 10mV = 1V (o/p voltage). 

As explained the microcontroller will get the analogue voltage, which is generated, from the LM35 plus the gain block. After this part the microcontroller will need certain routines so that it can convert this 8-bit data (ADDH register for the ADC of the micro) to a specific Temperature varying from 0oC to 100oC. This value of temperature is then display on the LCD 20 by 4. The block diagram of the system is shown below. 

So the maximum voltage that the LM35 will give is 1V and the maximum voltage that the microcontroller will input is of 2.5V (since the VAREF is set to 2.5V). We can conclude that we need to have a gain so that the LM35 voltage must be increased to 2.5V (VAREF) because when making 2.5V (VREF) / 1V (Max. Voltage) the answer will be of a 2.5 gain. 

8051 ADC 'C' Program - Polling method
#include < REG51AC2.H >

void main(void){
int x = 0;
EA = 1;
ADCF = 0x02; //P1.1 = ADC

while ((ADCON & 0x10) != 0x10);

ADCON &=  0XEF;  //clear adeoc = 0



8051 ADC 'C' Program - Interrupt method 

#include < REG51CC01.H >

unsigned char value_converted=0x00; /* converted value */
unsigned char value_AN6=0x00;       /* converted AN6 value */
bit end_of_convertion=0;            /* software flag */

 * FUNCTION_PURPOSE:this function setup 
 * Adc with channel 6 and start 8bits convertion.
void main(void)
/* configure channel P1.6(AN6) for ADC */
ADCF = 0x40;                        
/* init prescaler for adc clock */
/* Fadc = Fperiph/(2*(32-PRS)), PRS -> ADCLK[4:0] */
ADCLK = 0x06;           /* Fosc = 16 MHz, Fadsc = 153.8khz */
ADCON = 0x20;           /* Enable the ADC */
EA = 1;                 /* enable interrupts */
EADC = 1;               /* enable ADC interrupt */
  ADCON &= ~0x07;      /* Clear the channel field ADCON[2:0] */
  ADCON |= 0x06;       /* Select channel 6 */
  ADCON &= ~0x40;      /* standard mode */
  ADCON |= 0x08;       /* Start conversion */
  while(!end_of_convertion);/* wait end of convertion */
  end_of_convertion=0;     /* clear software flag */
  value_AN6=value_converted;/* save converted value */


 * FUNCTION_PURPOSE:Adc interrupt, save ADDH into an unsigned char
void it_Adc(void) interrupt 8
ADCON &= ~0x10;         /* Clear the End of conversion flag */
value_converted = ADDH; /* save value */
end_of_convertion=1;    /* set flag */

Download Project Folder

Project includes the projects in C compiled from Keil UV4 and the Proteus schematic.

electronics control,
Aug 13, 2011, 5:57 AM
electronics control,
Aug 13, 2011, 5:57 AM