top of page

LM35 Temperature Sensor Interfacing with PIC18F4550

Updated: Feb 2

Overview of LM35

LM35 Temperature Sensor


LM35 is a temperature sensor that can measure temperature in the range of -55°C to 150°C.


It is a 3-terminal device that provides an analog voltage proportional to the temperature. The higher the temperature, the higher is the output voltage.


The output analog voltage can be converted to digital form using ADC so that a microcontroller can process it.


For more information about LM35 and how to use it, refer to the topic LM35 Temperature Sensor in the sensors and modules section.


For information about ADC in PIC18F4550 and how to use it, refer to the topic ADC in PIC18F4550 in the PIC inside section.


Connection Diagram of LM35 temperature Sensor to PIC18F4550


LM35 Temperature Sensor Interfacing with PIC18F4550

 


Read Temperature using LM35 and Display on LCD16x2 using PIC18F4550


Let’s interface the LM35 temperature sensor with PIC18F4550 and display the surrounding temperature on the LCD16x2 display.


LM35 gives output in the analog form so connect out pin of a sensor to one of the ADC channels of PIC18F4550.

 

LM35 Code for PIC18F4550


/*
 *LM-35 Temperature Sensor Interfacing with PIC18f4550
 *http://www.electronicwings.com
 */

#include <stdio.h>
#include <string.h>
#include <p18f4550.h>
#include "Configuration_Header_File.h"          /* Header File for Configuration bits */
#include "LCD_16x2_8-bit_Header_File.h"                 /* Header File for LCD Functions */
#include "PIC18F4550_ADC_Header_File.h"

void main()
{    
    char Temperature[10];    
    float celsius;
    int i;
    OSCCON=0x72;                /* set internal Oscillator frequency to 8 MHz*/
    LCD_Init();                 /* initialize 16x2 LCD*/
    ADC_Init();                 /* initialize 10-bit ADC*/
    
    while(1)
    {   
        LCD_String_xy(0,0,"Temperature");
       /* convert digital value to temperature */
        celsius = (ADC_Read(0)*4.88);
        celsius = (celsius/10.00);
       /*convert integer value to ASCII string */
        sprintf(Temperature,"%d%cC  ",(int)celsius,0xdf); 
        LCD_String_xy(1,0,Temperature);                /* send string data for printing */    
        MSdelay(1000);
        memset(Temperature,0,10);
    }
}

 

2 views0 comments

Comments


bottom of page