Temperature sensor using PIC16F877A microcontroller




OBJECTIVE:

Components:

  • PIC 16F887: This MCU is powerful and very easy-to-program. It is CMOS FLASH-based 8-bit microcontroller. It has 40- or 44-pin package. The PIC16F887 features 256 bytes of EEPROM data memory, self programming. Operating Voltage range is between 2v to 5.5v.It also contains 2 Comparators, 14 channels of 10-bit Analog-to-Digital (A/D) converter, 1 capture/compare/PWM and 1 Enhanced capture/compare/PWM functions. It is very easy to use with LCD and sensors.
  • Pickit 3 is required to program the PIC using MPLAB IPE.
  • LCD 16×2: LCD is used to show alpha numeric characters. It has total 16 pins. A 10K ohm potentiometer is connected with pin three to set the contrast of the LCD. It also contains a backlight LED. In this project LCD we use is 16×2 which means we can display 16 characters in two lines. In this project LCD is used to show whether the motion is detected or not.
  • LM 35: The LM35 is a inexpensive but precise temperature sensor. The range to LM35 to measure temperature lies between -50 to 150 Celsius. It  operates from 4 V to 30 V and consume less than 60-μA Current. It is small in size as compare to other temperature sensors. It is very useful for portable projects.

Others: Breadboard, jumper wires and 10k ohm potentiometer

There are many temperature sensors available in market. But LM35 temperature sensor is used in this project. It is cheapest in price and one can easily find it in market. There are many other advantages of LM35 like:

  • It is more efficient than thermistor
  • It is made up of integrated circuit hence no chance of damaging to internal circuitry.
  • It draws current only in micro Amperes.
READ  DIY Internet connected smart humidifier

Only 5 volt power supply is required for LM35 and there is no need of extra circuitry to operate it. PIC16F877A microcontroller is used to read temperature value. 16X2 LCD is used to display temperature value on LCD. Code of this project written in Mikro C compiler.

Implementation:

LM35 temperature sensor converts temperature into its proportional analog voltage value. LM35 is three terminal device.Pin number one and three are for 5-volt voltage supply. Pin two is analog voltage output with respect to temperature value.Relation between measured temperature and analog output voltage is:

1oC = 10m volt

Hence for every 1 degree increase in temperature there will be a increment of 10m volt in output voltage of LM35 sensor. PIC16F877A microcontroller is used to measure analog voltage value.  PIC16F877A  microcontroller built in ADC (analog to digital converter) is used to measure analog voltage.  PIC16F877A PORTA have seven built in ADC channels. So one can interface up to seven sensors with this microcontroller very easily.I will post a project on green house system.In green house system project I have used four ADC channels to measure temperature , light, humidity and moisture. Coming back to our digital thermometer, ADC has been used to read analog voltage. After reading ADC value, using voltage and temperature relationship voltage is converted back into temperature. A conversion factor is used to convert voltage back into temperature. All these conversion has been done through programming. LCD is connected to PORTB of  PIC16F877A microcontroller. I will discuss it in programming part. LCD is used to display temperature value.

Circuit diagram:

Proteus is used for simulation. Following is a circuit diagram of Digital temperature sensor:

READ  Roll and Temperature sensor applications using PIC18F2550
Schematic Temperature sensor using PIC16F877A microcontroller

temperature sensor circuit diagram

As shown in above figure both temperature sensor and LCD is displaying same values of temperature. To ensure protection of LM35 and microcontroller you can connect 80k ohm resistor parallel to output of temperature sensor.

NOTE: Before making this project , I recommend you should learn about LCD interfacing with microcontroller especially hardware part. because I have seen many students struggling with LCD display.

CODE:

In programming part conversion factor is used to convert voltage back into temperature.The conversion factor is:

1 volt = 100 degree

temp   = ( Output voltage * 100 oC/V )

Code is written in MIKRO C compiler.

//************************* LCD module connections****************************************
//********************** written by [email protected]**********************************
sbit LCD_D7 at RB2_bit;
sbit LCD_D6 at RB3_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D4 at RB5_bit;
sbit LCD_EN at RB6_bit;
sbit LCD_RS at RB7_bit;
sbit LCD_D7_Direction at TRISB2_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_RS_Direction at TRISB7_bit;
//************************temperature variables****************
int temp;
char temper[7];
//**************************************************************
void READ_temp(void)
{
temp = ADC_Read(0);
temp = temp * 5/1023;                                                                                                                                                                         temp = temp * 100;
}
void data_converstion(void)
{
inttostr(temp,temper);
}
void display1(void)
{
lcd_out(1,1,"TEMPERATURE=");
lcd_out(1,13, Ltrim(temper));
Lcd_Chr_Cp(0xdf);
Lcd_Chr_Cp('C');
Lcd_Chr_Cp(' ');
}
void main()
{
ADC_Init();
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
lcd_cmd(_LCD_CURSOR_OFF);
lcd_out(1,4,"DIGITAL TEMPERATURE");
lcd_out(2,6,"SENSOR");
delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
while(1)
{
READ_temp();
data_converstion();
display1();
}
}

If you want complete simulation and hex file of this project.Comment on this post.Also comment your issue I will love to reply to your comments.To download circuit diagram and hex file of digital temperature sensor comment on following link

READ  SDP3x Series - Differential Pressure Sensors




Current Project / Post can also be found using:

  • temperature sensor using pic16f877a
  • pic16f877a thermpmeter
  • voltage measurement with pic16f877A
  • PIC coding for temperature sensor

Leave a Comment

*
= 4 + 5

Read previous post:
LT puts supercapacitor power back-up on a chip

Linear Technology has put the whole of a supercapacitor power back-up system on one chip. Rated at 2A, it will...

Close
Scroll to top