Watch the Video Tutorial

In this tutorial we’re gonna apply what we’ve learnt in the Analog to Digital tutorial. Temperature sensors are very important in many projects especially in temperature logging devices and alarms. An Analog temperature sensor will be used to read the temperature. The Microcontroller will convert this analog voltage representing the temperature into Digital format and display it continuously on an LCD display.

The temperature sensor used is the LM35 which is a precision integrated-circuit temperature sensor from Texas Instruments, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature, it changes by 10 mV per °C.
The LM35 thus has an advantage over linear temperature sensors calibrated in ° Kelvin, as the user is not required to subtract a large constant voltage from its output to obtain convenient Centigrade scaling.

            Features 
   1. Calibrated directly in ° Celsius (Centigrade) 
   2. Linear + 10.0 mV/°C scale factor 
   3. 0.5°C accuracy guaranteed (at +25°C) 
   4. Rated for full −55° to +150°C range 
   5. Suitable for remote applications 
   6. Low cost due to wafer-level trimming 
   7. Operates from 4 to 30 volts 
   8. Less than 60 μA current drain 
   9. Low self-heating, 0.08°C in still air 
  10. Non-linearity only ±1⁄4°C typical 
  11. Low impedance output, 0.1 Ω for 1 mA load

          Extract from the LM35 Datasheet

Full-Range Centigrade Temperature Sensor

More information can be found from the LM35 datasheet

Circuit diagram

As shown on the circuit diagram above, it is very easy to interface the LM35 to a PIC, its output pin can be connected to any analog input of the PIC, the VS to +5 supply and the ground to ground. In this example, the LM35 is connected to Analog 0 (pin 2 of PIC18F2620).
VDD and VSS of the pic microcontroller is not shown in the circuit diagram. VDD should be connected to +5V and VSS to GND. The MCLR is disabled in software and an internal oscillator clock is selected so no need for external crystal. 
A 16 x 2 lines LCD display is connected to PORT B. refer to the Interfacing LCD Display article to learn more.

Digital Thermometer using PIC Microcontroller and LM35 Temperature Sensor Circuit diagram

Figure 1: Digital Thermometer Circuit Diagram

Flowcode Project Options

Let us set our PIC to use the internal oscillator so we won’t need an external crystal oscillator. Let us also disable the MCLR as we won’t need to disable our microcontroller.  

—> On Build Menu, click on Project Options

Starting PIC options

                 Figure 2: Starting PIC options

—>On the Clock Speed combo box, enter the Clock Frequency in Hertz (Hz). In our case we’re gonna set our clock to 8MHz (8000000), then click on Configure Chip. 

Set the Clock Frequency

                 Figure 3: Set the Clock Frequency

—>On Oscillator section, select the Internal Oscillator (INT RC Port on RA6, port on RA7), on Select Chip, make sure to select the correct microcontroller. In our case, we’re gonna use the PIC18F2620. On Master Clear Enable, select MCLR Disabled. Leave the rest of the settings on their default values than click OK. 

Configuration Bits

                  Figure 4: Setting Configuration Bits in Flowcode

Flowcode Full Code

Flowcode main Program

Figure 5: Flowcode main Program

You can download the full project files (Flowcode Project and Proteus Schematic design) below here.
All the files are zipped, you will need to unzip them (Download a free version of the Winzip utility to unzip files). 

Download Digital Thermometer Flowcode

Download Flowcode Digital Thermometer Proteus