Temperature Display Project

LEAD IN: Temperature Display Project When designing a system that has 1 function or 1 task to perform the idea would be to use a device that is cost effective and only has sufficient program space and the I/O required. The cost of the device is linked to the package size, memory and obviously the I/O. Although not necessarily a hard and fast rule or linear equation, it is a reliable rule of thumb. The technology used in manufacturing the device can and does affect its cost and this can be a disparate factor between devices.

LM35 Working Hard….

The LM35 as mentioned in a previous post is a temperature sensor in a transistor type package TO92 which produces a linear voltage output in relation to the ambient temperature. The temperature changes at a rate of 10mV / C’ either way as the temperature either increases or decreases. The 10mV / C’ makes the LM35 an ideal sensor to use for measurement applications. In this project the LM35 is connected directly to an analogue input and the sensor shares the voltage supply with the PIC. The ground connection between the two devices must be common and this ensures that there is no voltage difference interfering with the voltage reading. The PIC used is a small 14 PIN PIC16F688. The PIC16F688 is a 14 pin device which includes an internal oscillator running at 4MHZ.

The physical requirements for this project are minimal and all the project consists of is a PIC connected to an analogue sensor. The sensor is connected an analogue to digital conversion input which then converts the analogue voltage using software to a temperature which is converted to a digital display which provides the visual output of the temperature for the user. The PIC used is hosted by a ProtoDev 20, a ZarDynamix development PCB. This particular PCB is capable of supporting 8 / 14 / 20 pin devices, but for the now we are using a 14 PIN Package device. Component Description The LCD display is one which I enjoy using owing to its slim and low profile. The display does not have an enclosure which means it needs to handled carefully so that the glass does not get broken. Other than that, it’s a standard LCD display, but it does not have a backlight. The connections when you look at the datasheet can be a bit confusing to ensure that the orientation is correct. The connections are made from right to left. The LM35 is connected to RA2 which is your analogue input.

The Software

The code as shown below includes comments, so explain each line is not necessary. What the code does do is the following:

  • Configure the device o Configures the ports
  • Disable the compatators o Initialise the LCD
  • Process the analogue signal o Read the analogue input
  • Convert the analogue input to a usable value
  • Convert the signal to a value that can be displayed on an LCD
/*
ProtoDev 20 Project for Temperature display using LM35 TempDisp V 1.0 
(c) Copyright 2012, Duetronix Technology Holdings CC TA:ZarDynamix
 */
#define ADPORT 2

// LCD module connections

sbit LCD_RS at RC4_bit;
sbit LCD_EN at RC5_bit;
sbit LCD_D4 at RC0_bit;
sbit LCD_D5 at RC1_bit;
sbit LCD_D6 at RC2_bit;
sbit LCD_D7 at RC3_bit;
sbit LCD_RS_Direction at TRISC4_bit;
sbit LCD_EN_Direction at TRISC5_bit;
sbit LCD_D4_Direction at TRISC0_bit;
sbit LCD_D5_Direction at TRISC1_bit;
sbit LCD_D6_Direction at TRISC2_bit;
sbit LCD_D7_Direction at TRISC3_bit;

// End LCD module connections

char StartUp[] = "PIC16F688 - Temp";
char DEG[] ="C'"; 
unsigned int LM35Volt=0;
float LM35=0; 
char TempVal[15];
const unsigned short VREF = 5;
unsigned int ADC_Value, DisplayTemp;

/*All initialisation requirements for the device*/

void Initialise() {
ANSEL = 0b00000100; // RA2/AN2 is analog input
ADCON0 = 0b00001000; // Analog channel select @ AN2
ADCON1 = 0x00;      // Reference voltage is Vdd
CMCON0 = 0x07 ;   // Disable comparators
TRISC = 0b00000000; // PORTC All Outputs
TRISA = 0b00001100; // PORTA All Outputs, Except RA3 and RA2
}

void main() {

Initialise();

Lcd_Init();                          // Initialize LCD
Lcd_Cmd(_LCD_CLEAR);                 // CLEAR display
Lcd_Cmd(_LCD_CURSOR_OFF);            // Cursor off
Lcd_Out(1,1,StartUp);
Lcd_Out(2,10,DEG);

do {

LM35Volt = ADC_Read(ADPORT);    // Get 10-bit results of AD conversion
LM35 = (LM35Volt * VREF)/10.240;  // Calculate temperature in Celsius
FloatToStr(LM35, TempVal);            // Convert temperature to string
TempVal[4] = 0;
Lcd_Out(2,3,TempVal);
delay_ms(500);                        // Hold for 500 ms

} while(1);
}// End main()

Hardware Connections

The hardware connections are shown diagrammatically below. The connections are simple and few. If you choose to use a ProtoDev 20, not all the connections are shown, only the ones required to configure the project. For further information, view the ProtoDev 20 Getting Started Guide.

LCD and LM35 Connections