Interfacing Temperature Sensor with Microchip PIC16F876A

The tutorial aims at providing the necessary information for interfacing an analog type temperature sensor with a Microchip PIC Microcontroller. PIC (Peripheral Interface Controllers) was introduced in 1985. The PIC16F876A has 8K of Flash Program Memory, 368 bytes of Data Memory (RAM) and many other attractive features. Some features are ADC, USART, and 14 Interrupts all in 28 PDIP Package.

mperature Sensor with Microchip PIC16F876AThe Analog temperature sensor used is LM35. It has a transfer function of 10mv/’c. The output of LM35 is analog voltage which varies with changes in temperature. This analog voltage is digitized using the On-Chip 10bit A/D Converter and the value is displayed on a 2Γ—16 LCD.

It is possible to switch On/Off an external application based on temperature value.

The LCD is based on HD44780 controller. The programming has been done using the MikroC compiler from Mikroelektronika (www.mikroe.com). The demo version has a 2KB Hex Output limit, fortunately it is more than enough for our requirement.

Program

int t1,temp;

char *text[6];

void main()

{adcon1=14;

lcd_init(&portb);

lcd_out(1,1,”Temperature”);

lcd_out(2,8,β€β€˜C”);

while(1)

{t1=adc_read(0);

//temp=0.245*t1;Β Β Β Β Β Β Β Β Β  // For TMP37 Sensor 20mv/’c

temp=0.245*t1*2;Β Β Β Β Β Β Β  // For Lm35 Sensor 10mv/’c

inttostr(temp,text);

lcd_cmd(lcd_cursor_off);

lcd_out(2,1,text);

delay_ms(100);}}

Interfacing Temperature Sensor with Microchip PIC16F876A SchematicThe program is self explanatory, however let me explain you the calculation done. In a while loop. The Input channel 0 is read and the digitized value is obtained. Now the smallest digitized value is equal to Vref/((2^10)-1). Internal Vref is 4096mV but we will consider 5000mV for the ease of calculation. Multiplying the value obtained above with the digitized value will give us the analog voltage. Since the transfer function of Lm35 is 10mV/’c, we can obtain the temperature.

 

For more detail: Interfacing Temperature Sensor with Microchip PIC16F876A


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.