LM35 Temperature Sensor Interfacing with PIC18F4550
Introduction
LM35 is a temperature sensor which can measure temperature in the range of -55°C to 150°C.
It is a 3-terminal device that provides analog voltage proportional to the temperature. Higher the temperature, 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 the topic LM35 Temperature Sensorin the sensors and modules section.
For information about ADC in PIC18F4550 and how to use it, refer the topic ADC in PIC18F4550in the PIC inside section.
Interfacing Diagram
LM35 Temperature Sensor Interfacing with PIC18F4550
Example
Let’s interface LM35 temperature sensor with PIC18F4550 and display the surrounding temperature on the LCD16x2 display.
As LM35 gives output in analog form so connect out pin of a sensor to one of the ADC channels of PIC18F4550.
Program
/*
*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);
}
}
No comments:
Post a Comment