vendredi 29 janvier 2016

Temperature sensor using PIC16F877A microcontroller




Temperature sensor using PIC16F877A microcontroller




OBJECTIVE:

  • Temperature measurement
  • Digital display of temperature
  • used of microcontroller to measure temperature
  • used of microcontroller to Display temperature value on LCD

COMPONENTS:


  • pic 16f877
  • lm35
  • 2 cap (22p)
  • quartz (4 mhz)
  • LCD 16*2

Only 5 volt power supply is required for LM35 and there is no need of extra circuitry to operate it. PIC16F877A micrcontroller is used to read temperature value. 16X2 LCD is used to display temperature value on LCD. Code of this project written in Pic 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:
                                                              1°C = 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 inerface upto 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 disucss it in programming part. LCD is used to display temperature value.

CIRCUIT DIAGRAM:




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:


#include <16F877.h>
#device adc=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)                                           
#include "LCD.c"                                                                         
//#define use_portb_lcd TRUE  
#define LCD_ENABLE_PIN  PIN_B0                                    ////
#define LCD_RS_PIN      PIN_B1                                    ////
#define LCD_RW_PIN      PIN_B2                                    ////
#define LCD_DATA4       PIN_B4                                    ////
#define LCD_DATA5       PIN_B5                                    ////
#define LCD_DATA6       PIN_B6                                    ////
#define LCD_DATA7       PIN_B7   
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) 
float adc_value,temp;
void     main() {                                                                 
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);delay_us(10);
lcd_init();              
while(1){
adc_value = read_adc();            // convert to volts avec précision 0.001V
temp=(float)((adc_value * 5)/1023.0)*100; // calculer 
lcd_gotoxy(1,1); 
printf(lcd_putc,"  Temperature ");   //lcd 
lcd_gotoxy(1,2); 
printf(lcd_putc,"     %2.1f%cC",temp,223);
printf("%2f\n\r",temp ); 
printf("\nsmart tech\n\r" );
}                       
}

Video:
























Continue Reading...