MICROCHIP - PIC 16F877A - I/P

  4.50 JD                  Add to cart

  LM35DZ
 

  1.90 JD                  Add to cart

  2x16 Character LCD

 

   5.50 JD                  Add to cart

  830-Point Breadboard
 

   6.00 JD                   Add to cart

  Tactile Push Button

Tactile Button

   0.15 JD                   Add to cart

 4 MHz Crystal Oscillator
 

  1.00 JD                    Add to cart

Temperature Sensor LM35

LM35 sensor has three legs like a Transistor, first leg is Vin second one is Vout and the third one is Ground. we have to supply 5 volts to Vin and Ground and take the output voltage at Vout which tells us the temperature in terms of voltage. The output from the LM35 is 0.01V/'C. So, when temperature sensed is 50'C, the output voltage is 0.5V.

Circuit

      

Code

The result of the 10-bit Analog to Digital (A/D) Conversion is read using the function ADC_Read(0). This 10-bit digital value is then converted to the corresponding voltage by multiplying with 0.4887.

The 0.4887 came from that the ADC resoultion is 10 bits, so that the 0.1 volts resoultion of the LM35 is converted to the digital value 2.046 on the scale of 1023 ( 0.1V/5V * 1023). so in our code calculations we need to dived the digital reading converted from analog input by 2.046 which is the same as 0.4887 (1/2.046). 

// LCD module connections 
 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; // End LCD module connections

int t;
char a;
char lcd[] = "000 Degree";
void main()
{
ADCON1 = 0x04;
Lcd_Init();
Lcd_Cmd(_LCD_CURSOR_OFF);
do
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_out(1,1, "Temperature:");
t = ADC_Read(0);

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

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

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

Lcd_out(2,1,lcd);
Delay_ms(100);
}while(1);
}