We can build a Temperature meter by pic18f2550 microcontroller and we need a temperature sensor . In this project we will use LM35 temperature sensor and it is a popular temperature sensor .Look at the picture which is given below .
![]() |
The Picture has been taken from internet |
LM35 produce different voltage outputs at different temperatures . LM35 increase it's output voltage 10mV or 0.01v for each degree increment of temperature . That means 0.01 v per degree centigrade.
Now we need to get a microcontroller as a system to read temperature from sensor . We will use ADC of the microcontroller and the reading will be shown in LCD display . It's the basic idea of the project .
We need a basic knowledge about ADC . Let's take a look at here :
Basically ADC is like as voltage divider . According to voltage It produce output .
bit 5 : VCFG0: Voltage Reference Configuration bit (VREF- source)
1 = VREF- (AN2)
0 = VSS or 0 volt
bit 4 :VCFG0: Voltage Reference Configuration bit (VREF+ source)
1 = VREF+ (AN3)
0 = VDD or 5volt
bit 5 : VCFG0: Voltage Reference Configuration bit (VREF- source)
1 = VREF- (AN2)
0 = VSS or 0 volt
bit 4 :VCFG0: Voltage Reference Configuration bit (VREF+ source)
1 = VREF+ (AN3)
0 = VDD or 5volt
We will set VCFG0[bit 5]=0and VCFG0[bit4]=0 . So we will get highest value 5volt[1023] and lowest value 0volt[0].The ADCON1 is a 10 bit register that means (2 to the power 10) is it's highest counting capacity and the result is 1024 . So this register can count from 0 to 1023 . When 0 volt , we get reading at RA0 pin 0 .When 5 volt , we get reading at RA0 pin 1023. It means 5volt equivalent to 1023 .
If 1023 reading value equal to 5 volt.
So 1 reading value equal to 5/1023 volt
So 'read_val' reading value equal to (5/1023)*read_val .volt .
As we know LM35 reading can be changed with 0.01 v per degree centigrade change . According to the datasheet 10mV = 1 degree centigrade temperature .The temperature calculation should be like that :
0.01 volt for 1 degree centigrade Temperature
so 1 ,, ,, (1/0.01) ,, ,, ,,
So 1 reading value equal to 5/1023 volt
So 'read_val' reading value equal to (5/1023)*read_val .volt .
As we know LM35 reading can be changed with 0.01 v per degree centigrade change . According to the datasheet 10mV = 1 degree centigrade temperature .The temperature calculation should be like that :
0.01 volt for 1 degree centigrade Temperature
so 1 ,, ,, (1/0.01) ,, ,, ,,
and (5/1023)*read_val volt for [{(5/1023)*read_val }/0.01] degree centigrade Temperature .
Source Code :
sbit LCD_RS at LATB7_bit;
sbit LCD_EN at LATB6_bit;
sbit LCD_D4 at LATB5_bit;
sbit LCD_D5 at LATB4_bit;
sbit LCD_D6 at LATB3_bit;
sbit LCD_D7 at LATB2_bit;
sbit LCD_RS_Direction at TRISB7_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB2_bit;
// End LCD module connections
double source=0;
int temperature=0;
char txt[15];
void main() {
ADCON1=0x0E; // Configure RA0 pin as input
CMCON=7;
TRISB.F0=0;
ADC_Init(); // Initialize ADC
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1, 3, "Temperature");
// Different LCD displays have different
Lcd_Chr(2,12,223); // char code for degree
Lcd_Chr(2,13,'C'); // Display "C" for Celsius
while(1){
source=Adc_Read(0);
source=(source*5)/1023;
source=source/0.01;
if(source>30){ // when temperature goes higher than 30 degree , fan turns on .
PORTB.F0=1;
}
else{ // when temperature goes lower than 30 degree , fan remains off .
PORTB.F0=0;
}
inttostr(source,txt);
Lcd_Out(2,1,txt);
}
}
Circuit :
During temperature lower than 30 degree:
During temperature higher than 30 degree:
This Project's Proteus Simulation in Youtube , Please Watch This: