![]() |
Bluetooth Based Temperature Meter Project using Microcontroller |
We will need an ADC Converter so that microcontroller can read the temperature .
ADC [Analog to Digital Converter]:
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 , 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 , 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 .
Mikro C Library Funtions :
UARTx_Init: This
function will initialize USART option of Microcontroller with Baud
rate . We will use baud rate 38400 . The code will be look like this :
UART1_Init(38400);
UARTx_Data_Ready: This will check if it is available to read or transmit data .
UARTx_Read_Text: To read text data .Look at the example .
if (UART1_Data_Ready() == 1) {
UART1_Read_Text( txt, ")" , 13); }
This is checking if data is available to read . ")" means , txt car array variable will be being stored until the ")" will found . 13 means to try for 13 times . So , i think our text should not be longer than 11 character .
UARTx_Write_Text: This will send text data . Look at the example :
if (UART1_Tx_Idle() == 1) {// this will check , if the last data transmission is completed
UART1_Write_Text("button2");
}
UART1_Write_Text("button2");
}
Recommended: How to Interface Bluetooth Module (HC-06) with PIC Microcontroller [Step by Step Picture]
Circuit :
![]() |
Bluetooth Based Temperature Meter Project using Microcontroller and MikroC USART Terminal |
Source Code :
char txt[8];
double chk;
int i=0,ckop=0;
void main() {
ADCON1=0x0E; // Configure RE1 pin as input
CMCON=7;
for(i=0;i<16;i++){txt[i]=' ';}
TRISA.F3=1;
TRISA.F4=1; // Initialize ADC
Adc_Init();
UART1_Init(38400);
delay_ms(200); // Initialize LCD
while(1){
chk=Adc_Read(0);
chk=(chk*5)/1023;
chk=chk/0.01; //10mV == 1 degree
inttostr(chk,txt);
UART1_Write_Text(" Temperature:");
UART1_Write_Text(txt);
UART1_Write_Text(" \n");
delay_ms(6000);
}
}