Interfacing of LM35 with PIC Microcontroller

Hello friends, I hope you all are fine and having fun with your lives. In today's post, I am going to share How to interface LM35 with PIC Microcontroller. I have already shared Interfacing of LM35 with Arduino so now we are gonna interface this same temperature sensor with PIC Microcontroller. Interfacing LM35 with PIC isn't much difficult as its a simple sensor which gives us analog output and we just need to read this output and convert it into temperature format. Before going into details, you should first read the Interfacing of LM35 with Arduino as I have given the basic details of this LM35 sensor in that post. You should also have a look at How to use 18B20 in Proteus.

So, today I am not gonna go into the details of this temperature sensor. Instead let's start with Interfacing of LM35 with PIC Microcontroller. I have used Proteus software for simulation purposes but you can also test it on hardware. It will work fine on hardware as I have already tested it. I have used PIC 16F876A Microcontroler for this simulation and the PIC Compiler used for writing the programming code is MikroC Pro for PIC. If you have any problem then as k in comments and I will try to resolve them as soon as possible.

I have already posted the tutorial on Arduino and today we are having a look at interfacing of LM35 with PIC Microcontroller and soon I will also post the tutorial on Interfacing of LM35 with 8051 Microcontroller. ITs a simple sensor which you can interface with any kind of Microcontroller like PIC, Atmel, Arduino or 8051 Microcontroller. Anyways let's get started with interfacing of LM35 with PIC Microcontroller.

Interfacing of LM35 with PIC Microcontroller

  • You can download the complete simulation along with programming code by clicking on the below button:

Download LM35 Code and Simulation

  • First of all, design a simple circuit as shown in the below figure:
  • You should also try our New LCD Library for Proteus, it will give a better look to your project.
  • As you can see in the above figure, we have used LM35 sensor in Proteus which is connected with PIC Microcontroller.
  • Moreover, we have also connected LCD with PIC Microcontroller.
  • PIC Microcontroller we have used is PIC16F876A, but you can use any other PIC Microcontroller here.
  • LCD is used to display the Termperature Sensor LM35 value.
  • Now copy the below code and place it in your MikroC Pro For PIC Compiler and get the hex file.
// 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


char display[16]="";

void Move_Delay() { // Function used for text moving
Delay_ms(500); // You can change the moving speed here
}

void main() {
unsigned int result;
float volt,temp;

trisb=0;
trisa=0xff;
adcon1=0x80;
lcd_init();
lcd_cmd(_lcd_clear);
lcd_cmd(_LCD_CURSOR_OFF);
lcd_out(3,2,"www.TheEngineering");
lcd_out(4,5,"Projects.com");
while(1)
{
result=adc_read(0);
volt=result*4.88;
temp=volt/10;

lcd_out(1,1,"Temp = ");

floattostr(temp,display);
lcd_out_cp(display);
lcd_chr(1,14,223); //print at pos(row=1,col=13) "°" =223 =0xdf
lcd_out_cp("C"); //celcius
//delay_ms(1000);
//Lcd_Cmd(_LCD_CLEAR);
}

}
  • When you get the hex file upload it in your Proteus software and run your Proteus simulation.
  • If everything goes fine then you will get something as shown in below figure:
  • As you can see in the above figure, LCD is displaying the same temperature values as in LM35 temperature sensor.
  • Now you can change this temperature value and the updated value will be displayed in LCD as you can see in below figure:
  • Now you can see in above figure that the temperature sensor LM35 value is 100 and same is displayed on LCD.
  • You should also have a look at How to use 18B20 in Proteus, which is another temperature sensor.
  • You should also try 18B20 with PIC Microcontroller.
  That's all for today. That's how you can interface LM35 with PIC Microcontroller and can get the temperature of your room. Will meet you guys in the next tutorial, till then take care and have fun!!! :)
Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir