Watch the Video Tutorial part 1:

Figure 1: LM35 Temperature sensor

The LM35 series are precision integrated-circuit temperature sensors from Texas Instruments, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. Its output is linearly proportional to Centigrade temperature Scale and 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. 
The LM35 does not require any external calibration or trimming to provide typical accuracy 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 make interfacing 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 Temperature Sensor has Zero offset voltage, which means that the Output is 0V when the temperature is at 0 °C. Thus for the maximum temperature value (150 °C), the maximum output voltage of the sensor would be 150 * 10 mV = 1.5V.

If we use the supply voltage (5V) as the Vref+ for Analog to Digital Conversion (ADC) the resolution will be poor as the input voltage will goes only up to 1.5V and the power supply voltage variations may affects ADC output. So it is better to use a stable low voltage above 1.5 as Vref+. We should supply Negative voltage instead of GND to LM35 for measuring negative Temperatures.

Digital Thermometer using PIC Microcontroller and the LM35 Temperature Sensor

Figure 2: Circuit diagram of Digital Thermometer

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

More information can be found from the LM35 datasheet

MikroC Code

A 16 x 2 lines LCD display is connected to PORT B. PORTA is configured as a analog input. The analog data from LM35 digital sensor is connected to Analog 0 (RA0). To configure Analog to Digital converter is really easy, all we need is to configure the ADC, Start conversion and then manipulate the results.

To learn more, refer to these articles:

Interfacing LCD Display with PIC microcontroller

Analog to Digital Converter in PIC Microcontroller

Watch the Video Tutorial part 2:

The circuit diagram of the project is shown on figure 2. At the beginning of the project, the LCD is is initialized, cleared, and the cursor is turned OFF. “StudentCompanion” is displayed on the first line of the LCD and “Thermometer” is displayed on the second line. After 1 second, the LCD is cleared and the main program starts in  an  endless  loop. The temperature is read from analog channel 0 (AN0 or RA0), converted into millivolts by multiplying with 5000, and dividing by the A/D converter resolution  (10 bits), and divided by 10 to get the temperature. The temperature is then converted into a string and is displayed on the LCD.

In this program, floating point arithmetic is used to find and display the temperature for higher accuracy.

//
/*
 * Project name: Digital Thermometer with LM35 Sensor
 * Author: www.studentcompanion.co.za
 * Test configuration:
     MCU:             PIC18F45K22
                      http://ww1.microchip.com/downloads/en/DeviceDoc/41412D.pdf
     Oscillator:      HS-PLL 32.0000 MHz, 8.0000 MHz Crystal
     SW:              mikroC PRO for PIC
 */
 
// LCD module connections
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_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
 
unsigned int temperature = 0;
float mV;
unsigned char txt[15];
 
void main() {
  ANSELA = 1;                        // Configure PORTA pins as analog
  ANSELB = 0;                        // Configure PORTB pins as digital
  TRISA.RA0 = 1;                    // Configure RA0 pin as input
 
  ADC_Init();                        // Initialize ADC
 
  Lcd_Init();                        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
 
  Lcd_Out(1, 1, "StudentCompanion");  // Display "StudentCompanion"
  Lcd_Out(2, 1, "Thermometer");       // Display "Thermometer"
  Delay_ms(1000);                    // 1 Second delay
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
 
  Lcd_Out(1, 1, "Temperature :");
  Lcd_Chr(2,8,223);                  // char code for degree
  Lcd_Chr(2,9,'C');                  // Display "C" for Celsius
 
  temperature = 0;
   do {
   temperature = ADC_Read(0);          // Get 10-bit results of AD conversion
   mV = temperature * 5000.0 /1024.0;// Convert to mV (1024 is ADC Resolution (10-bits)
   mV = mV/10.0;                     // Convert mV to temperature in Celsuis
    FloatToStr(mV, txt);             // Convert temperature to string
    txt[4]=0;
    Lcd_Out(2, 3, txt);              // Display Temperature
    Delay_ms(500);                   // 500ms delay
 
  } while(1);
}

You can download the full project files (MikroC Pro for PIC source code 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 Themometer with MikroC

Download Digital Thermometer Proteus Shematic

(Visited 391 times, 2 visits today)