Friday, April 27, 2018

LM35 Temperature Sensor with PIC16F887



Today I will interface LM35 Temperature sensor with PIC16F887. It is a very basic and simple project. In this tutorial we will use the following Software:

   1. MikroC pro for PIC (student verison)
   2. Proteus 8 professional
   3. PicKit 2

MikroC pro for PIC will be used for writing and compiling the code. Here we will use C language.
Proteus 8 professional will be used for the simulation and finally Pickit 2 will be used for burning the hex file in the PIC16F887  IC.

To do this project we need following components;

   1. PIC16F887
   2. LCD 20*4
   3. 16 MHz Crystal Oscillator
   4. LM35 Temperature Sensor
   5. Breadboard
   6. Wires
   7. 5V DC Power source
   8. male header (to solder with LCD)


Little bit about LM35


LM35 is a precision IC temperature sensor with its output proportional to the temperature (in oC). The sensor circuitry is sealed and therefore it is not subjected to oxidation and other processes. With LM35, temperature can be measured more accurately than with a thermistor. It also possess low self heating and does not cause more than 0.1 oC temperature rise in still air.   
The operating temperature range is from -55°C to 150°C. The output voltage varies by 10mV in response to every oC rise/fall in ambient temperature, i.e., its scale factor is 0.01V/ oC.


Figure 1




MikroC Code:

// LCD module connections
sbit LCD_RS at RC6_bit;
sbit LCD_EN at RC7_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISC6_bit;
sbit LCD_EN_Direction at TRISC7_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections


int t;
char b;
char lcd[] = "000 Degree";

void main()
{
  ADCON1 = 0x04;
  Lcd_Init();
  Lcd_Cmd(_LCD_CURSOR_OFF);
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_out(1,1, "PIC Microcontroller ");
  delay_ms(500);
  Lcd_out(2,1, " Temperature Sensor ");
  delay_ms(500);
  Lcd_out(3,1, "   Using LM35 and   ");
  delay_ms(500);
  LCD_out(4,1, "     PIC16F887      ");
  delay_ms(2000);
  Lcd_Cmd(_LCD_CLEAR);
  delay_ms(200);

  do
  {
    Lcd_out(1,1,"     AHAMOD IBNE    ");
    Lcd_out(2,1,"      ABDUR ROUF    ");
    Lcd_out(3,1, "Temperature:   ");
    t = ADC_Read(0);

    t = t * 0.4887;
    b = t%10;
    lcd[2] = b + '0';

    t = t/10;
    b = t%10;
    lcd[1] = b + '0';

    t = t/10;
    b = t%10;
    lcd[0] = b + '0';

    Lcd_out(4,1,lcd);
    Delay_ms(200);
  }while(1);

}


Circuit Diagram:



Figure 2



Figure 3



Please don't forget to connect pin 1,11 and 32 to 5V source.
Connect pin 12 and 31 with Gnd. Also connect 16 MHz oscillator with pin 13 and 14.

For LCD we are using 4 bit data transfer mode. Connect the LCD according to the diagram. Pin 15 and pin 16 are backlight power of the LCD. Connect pin 15 with 5V and connect pin 16 with Gnd.

THANKS A LOT.


No comments:

Post a Comment

Line Follower Robot using Arduino

This project was a part of Line Follower Robot Competition