top of page

LM35 Temperature sensor interface  with PIC16F877A:

Presented by: Bernice Zuiya

Introduction:

              LM35 is one of the best sensor used to measure the temperature, mainly use in embedded system where its cost is basically less than one dollar from the shop I used to buy my component, this sensor is an accurate integrated circuit which present its output temperature in terms of analog volt, this maybe calibrated directly in Celsius (centigrade) it can operate at a temperature ranging between -55 to 150 degree Celsius and its input operating voltage varies from 4 to 30 volt.

Working:

Connect the output pin of the sensor to the first analog pin of the controller and the two remaining pins used for supplying the sensor to VSS and GND respectively

Steps:

1. LM35 sensor gives an analog signal at the output proportionally to the temperature

2. Using ADC converter module of our PIC16F877A MCU we converter the analog quantities at the output of the sensor into DC values

3. we apply the following formula to find the corresponding temperature in degree Celsius as shown below:

    

                      Formula: dc_v = ((4.9999 * adc)/1024)*100;  // temperature

: where > 4.999 is the voltage measured between the two pins (VSS and GND) of our controller in your case it maybe 4.53 you just have to check !!

            > adc represent the DC value converted from AC signal

            > 1024 this number is used in such away our PIC16F877A has a resolution of 2^10 which means 1024 samples corresponding to their voltages

            > finally is 100 as we already know that 10mvolt change at the output pin of the sensor correspond to 1 degree Celsius the change.

Circuit diagram:

  •    a resistor of value 4k7 ohm is connected in series with +5 volt and the reset pin (1st pin)

  •    Q1 is the crystal oscillator in this case its frequency oscillation is 20 MHz.

  •    supply: the circuit is connected with a voltage maximum equal 5 volt

  •    LM35 temperature sensor

  •    C1 & C2 are of 22pF.

This code were written using mikroC compiler software, you can copy and compile it or modify it as well, LM35 Digital thermometer using PIC16F877A

Download the full project here


sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
unsigned int adc;
unsigned int i;
double dc_v;
int valve;
char temp[7];
void main() 
   {
       LCD_Init();
       LCD_Cmd(_LCD_CLEAR);
       LCD_Cmd(_LCD_CURSOR_OFF);
       Delay_ms(50);
       LCD_Out(1,1,  LM35 MODULE);
              while(1) {
                              adc = adc_read(0);
                             
dc_v = ((4.9999 * adc)/1024)*100;  // temperature
                              valve = dc_v;
                              IntToStr(valve,temp);
                         LCD_Out(2,1,temp);
                         LCD_Out(2,8,Degree C);
                    delay_ms(300);
   }

}

Code:

bottom of page