Bukit Mertajam, Penang

Project 5 – Analog Sensor: Temperature using LM35



Back to Project 4                                                                                                          Go to Project 6

Nowadays, there are many type of temperature sensor is come with different output form and also the temperature range such as thermocouple, thermistor, infrared, RTD. In here, we pick LM35 as our temperature sensor due to it have a linear output and also suitable for normal use like weather temperature measuring.




16 x 2 LCD Display








The connection for the LM35 are very easy. Just connect one end to VDD (RED wire)(4V to 20V) and the other end to GND(BLACK wire) while the middle pin (YELLOW wire) is connected to RA0. By referring to the PIC16F887, there are total 14 analog pins that we can choose. In here we use RA0 as out ADC input pin.



The LM35 series are precision integrated-circuit temperature sensors, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 does not require any external calibration or trimming to provide typical accuracies of ±1⁄4˚C at room temperature and ±3⁄4˚C over a full −55 to +150˚C temperature range. Low cost is assured by trimming and calibration at the wafer level. The LM35’s low output impedance, linear output, and precise inherent calibration makeinterfacing to readout or control circuitry especially easy. It can be used with single power supplies, or with plus and minus supplies. As it draws only 60 µA from its supply, it has very low self-heating, less than 0.1˚C in still air. The LM35 is rated to operate over a −55˚ to +150˚C temperature range.

~ Calibrated directly in ° Celsius (Centigrade)
~ Linear + 10.0 mV/°C scale factor
~ 0.5°C accuracy guaranteeable (at +25°C)
~ Rated for full −55° to +150°C range
~ Suitable for remote applications
~ Low cost due to wafer-level trimming
~ Operates from 4 to 30 volts
~ Less than 60 μA current drain
~ Low self-heating, 0.08°C in still air
~ Nonlinearity only ±1⁄4°C typical
~ Low impedance output, 0.1 W for 1 mA load.




LM35 have already designed to give an exact value of temperature in Celsius. By referring to the graph, the ADC output are only need to divide by 2 to get the result in Celsius.

kelvin = ((celsius*100)+27315)/100;
Kelvin formula are (Celsius + 273.15). But for microcontroller, it will not read the result after the DOT. E.g. : if result is kelvin = 300.15, the mcrocontroller will only read 300 only and will ignore .15. In order to get the result after the DOT, we times the result in 100 so that we can get the result after the DOT.

fehrenheit = ((celsius*18)/10)+32;
Fahrenheit formula are ([celsuis*1.8]+32). In the coding, the formula have been times will 10 times to get the exact result.

reaumur = (celsuis*8)/10;
Reaumur formula are (celsius*0.8). Same as the previous technic, in order to let microcontroller to get the more accurate result, we times it with 10 to get the result after the DOT.

Back to Project 4                                                                                                           Go to Project 6



1.P5 User Manual.pdf


Related Posts

Comments (7)

can you briefly explain why adc value must divide by two to get celcius

could you kindly send me complete wiring diagram of project 5

Thank you in advance

the coding is failed..
this is what it show and please advised
Build E:\MP Lab\1st LM35 for device 16F877A
Using driver C:\Program Files (x86)\HI-TECH Software\PICC\PRO\9.60\bin\picc.exe

Executing: “C:\Program Files (x86)\HI-TECH Software\PICC\PRO\9.60\bin\picc.exe” –pass1 “E:\MP Lab\LM35\Project_5\Project_5.c” -q –chip=16F877A -P –runtime=default –opt=default -D__DEBUG=1 -g –asmlist “–errformat=Error [%n] %f; %l.%c %s” “–msgformat=Advisory[%n] %s” “–warnformat=Warning [%n] %f; %l.%c %s”
Error [192] E:\MP Lab\LM35\Project_5\Project_5.c; 43.1 undefined identifier “ANSELH”

********** Build failed! **********

The sample code is for PIC16F887, you are using PIC16F877A 🙂 Anyway, please do come to our technical forum to discuss.

could u send me schematic diagram…i want to try my own self..

Hi Sham,

There is no schematic diagram as this is a simple project.
Please refer to the breadboard view diagram in this article.


Hi all,

I’m very new to MPLAB IDE and C language.
I’ve been meddling with Project 5 codes to run on 16F877A but original coding is for 16F877.
I just need LM35 output to internal ADC and output on LCD
How to modify the 877 source to run on 877A instead?
Any link to forum thread on this?
Assistance much appreciated.
Thank you

Leave a comment