Wednesday, 29 May 2013

How to make a temperature sensor circuit using lm35 and pic microcontroller


An easy step by step build of a temperature sensor circuit
  •     parts needed
  •     software needed
  •     code needed
  •    circuit diagram
  •     final result



Step 1

  1. pic16f73
  2. lcd  (I use jhd204a)
  3. lm35 ic
  4. 1k resistor 2pc
  5. breadboard
  6. switch button
Step 2

  • mikro c pro  (I use mikroc pro for pic 5.6.1)
  • proteus  (not mandatory)
Step 3

Circuit diagram
Use this digram to give connections in breadboard.
Step 4
Before write the code we have to configure a new project in mikro c project.
i use 20MHz oscillator and default settings.
Then write the code:
// LCD module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
// End LCD module connections
int temp_res;
char txt[15];
void main()
{
Lcd_Init();                        // Initialize LCD
TRISA  = 0xFF;              // PORTA is input
TRISB  = 0;                 // PORTB is output
Lcd_Out(1, 1, "Welcome To Digital");
Lcd_Out(2, 1, "Temperature measure");
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
INTCON=0b11000000;
ADCON1=0b0000000;
ADCON0=0b00001101;
while(1){
temp_res=ADC_Read(1)*2;
IntToStr(temp_res, txt);
Lcd_Out(1, 1, txt); }
}
copy this code and build it in mikro c.
After successful build collect the hex file.
Step 5

Now we have to load hex in pic.
I use pic-pg2 circuit which i made myself and it is a serial programmer
needs serial port.
you can use your own circuit such as pickit2.
You can download picpg2 circuit diagram from net also.
Step 6
Now give power to breadboard.
First lcd will print a message "Wellcome to digital temperature measure".
After 1 second delay it shows the temperature in degree celcius.
enjoy!!!!
If any complexity arise just put a comment.
I will try to give feedback.

No comments:

Post a Comment