Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Temperature Sensor (LM35 + PIC16F877A)

  • Author Tahmid
  • Create date
  • Updated
  • Blog entry read time 2 min read
Here's one temperature sensor (thermometer) circuit that you can easily build. It uses the popular PIC 16F877A microcontroller. The temperature sensor is LM35. The LM35 outputs an analog voltage proportional to the temperature. The output from the LM35 is 0.1V/'C. So, when temperature sensed is 61'C, the output voltage is 0.61V. This analog voltage is read by the PIC and processed to display the corresponding temperature value on the LCD.

The temperature range for this circuit is 0'C to 150'C.

The analog to digital conversion is done by the PIC ADC module. In the code, I've used the mikroC library function for ADC. You can view the library file here: https://www.mikroe.com/download/eng/documents/compilers/mikroc/pro/pic/help/adc_library.htm

However, you should have a knowledge of how the ADC module works and how to use it. I had written a tutorial on modalities of operation of the PIC 16F877A ADC.
https://www.edaboard.com/blog/1569/
https://www.edaboard.com/blog/1570/
https://www.edaboard.com/blog/1571/
https://www.edaboard.com/blog/1572/
https://www.edaboard.com/blog/1573/
https://www.edaboard.com/blog/1574/

For LCD interfacing, I used the mikroC LCD library. You can view the library file here: https://www.mikroe.com/download/eng/documents/compilers/mikroc/pro/pic/help/lcd_library.htm

8829907200_1351926212.png


Here is the code for PIC16F877A:
(You can download the source file from: https://rapidshare.com/files/3044512089/LM35PIC16F877A.c)
--------------------------------------------------------------------------------------------------------------
//Programmer: Syed Tahmid Mahbub
//Compiler: mikroC PRO for PIC v4.60
//Target PIC: PIC16F877A
--------------------------------------------------------------------------------------------------------------
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 long ADRead;
unsigned int vDisp[3];
unsigned char Display[7];

void main() {

PORTA = 0;
TRISA = 0X01;
PORTB = 0;
TRISB = 0;
LCD_Init();
LCD_Cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1, 1, "Temp:");
//Display = "+125 'C";
Display[4] = 39; //'
Display[5]= 'C';
ADCON1 = 0x0E;
ADC_Init();
while (1){
ADRead = (ADC_Get_Sample(0) * 500) >> 10;
vDisp[0] = ADRead / 100;
vDisp[1] = (ADRead / 10) % 10;
vDisp[2] = ADRead % 10;
Display[1] = vDisp[0] + 48;
Display[2] = vDisp[1] + 48;
Display[3] = vDisp[2] + 48;
LCD_Chr(1, 8, Display[0]);
LCD_Chr(1, 9, Display[1]);
LCD_Chr(1, 10, Display[2]);
LCD_Chr(1, 11, Display[3]);
LCD_Chr(1, 12, Display[4]);
LCD_Chr(1, 13, Display[5]);
//LCD_Out(1, 8, ); // 'Show temperature
delay_ms(200); //200ms delay for waiting
}
}

Comments

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;
 
Yes, it means that pin RS of the LCD will be connected to RB4 (PORTB4) of the microcontroller.
 
how can make the sensor with wireless...??? placing LM35 wireless so that it will be safer from the hot...??? whether we have to use RF or is there some aother sensor that can work with wireless...???
 
Yes, mikroC PRO is a compiler similar to C18. When adapting any code for C18, remember to keep in mind the differences in syntax (if any) and the library functions used.

For wireless sensing, a 2nd circuit must be used, which transmits the output of the LM35 wirelessly, for example through RF. In that case, that circuit must be capable of withstanding the high temperature. You may use thermistors or long wires and compensate (in hardware or code) for any losses in the wire (which in case wouldn't be much because of the small current, but may amount to something significant when you consider that the voltage is so small anyways).
 
How am i going to build a program that can read temperature from TC74 sensor and display it in a LCD using C18 Compiler ?
 

Part and Inventory Search

Blog entry information

Author
Tahmid
Read time
2 min read
Views
3,570
Comments
11
Last update

More entries in Uncategorized

More entries from Tahmid

Share this entry

Back
Top