Bluetooth device has been becoming very popular for wireless communication . Bluetooth is a device that helps you to communicate with other through wireless connection . I am not going to describe about Bluetooth technology . If you have more interest about it , please follow the link of wikipedia Link.
In this tutorial , i will show you how to interface Bluetooth module with pic microcontroller . I am using HC-06 Bluetooth Module and PIC 18f2550 microcontroller for this purpose .
We will use USART to make connection between pic18f2550 and HC-06 . So, here is an important thing Baud Rate . This bluetooth module supports 38400 Baud Rate . Actually i don't have much knowledge about Baud Rate . All i know , it's a Symbol rate and differs from bit rate. Higher baud rate makes higher speed of transmission and connection speed. I had tried to understand it clearly from wikipedia , but i failed to completely understand . If you would like to know about Baud Rate , please try these links.
Baud Rate can be changed using "AT Command" like GSM Module. I tried , but i didn't get any impact . I am giving another link if you would like to change it . I think Baud Rate 38400 is fine , i didn't change it .
I think , it's not very essential and that's my personal opinion . Now lets start and take a look at the picture :
![]() |
HC-06 Bluetooth Module |
HC-06 Bluetooth Module [Details] :
Default password: 1234
Baud rate: 38400
Dimensions: 1.73 in x 0.63 in x 0.28 in (4.4 cm x 1.6 cm x 0.7 cm)
PIN OUT
PIN DESCRIPTION
1 KEY
2 VCC
3 GND
4 TXD
5 RXD
Baud rate: 38400
Dimensions: 1.73 in x 0.63 in x 0.28 in (4.4 cm x 1.6 cm x 0.7 cm)
PIN OUT
PIN DESCRIPTION
1 KEY
2 VCC
3 GND
4 TXD
5 RXD
MikroC Project :
Now open MikroC and Create a new Project .If you are an expert you don't have to follow this steps .




Note :
Our microcontroller will only transmits and receives data from HC-06 . For this purpose we will use UART of MikroC . As we did in serial communication. PIC18f2550 transmitted text data and that was taken by our computer and PIC18f2550 also received data text from computer. That was the basic idea. Here we are using HC-06 instead of computer.
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");
}
Reducing Noise :
To reduce noise , we will use a trick . Before reading the data text we will keep a function and this will check first character . If the character is '(' , it will be checked by an if statement. Finally read text function will be performed until the char ')' will be found. That means microcontroller will show us only the text between '(' and ')' . Please follow the example :
If we send (Omnia) , Lcd will show "Omnia" . If we send (PinkFloyd) , we will get "PinkFloyd" . Unless we cant get any text output. If we send "(fee ra huri" , this will show no output .
Source Code :
// LCD module connections
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
char txt[16];
char 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
TRISA.F5=1;
TRISC.F0=1;
Lcd_Init();
UART1_Init(38400);
delay_ms(200); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursdhhdor off
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 4, "Welcome");
Lcd_Out(2, 2, "pictutorial.net");
delay_ms(1500);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 2, "Received Data");
while(1){
ckop=2;
if (UART1_Data_Ready() == 1){
chk = UART1_Read();
for(i=0;i<16;i++){txt[i]=' ';}
}
if(PORTA.F3==0){
delay_ms(1000);
if (UART1_Tx_Idle() == 1 && ckop==2) {
UART1_Write_Text("button1");
}
ckop=4;
}
if(PORTA.F4==0){
delay_ms(1000);
if (UART1_Tx_Idle() == 1 && ckop==2) {
UART1_Write_Text("button2");
}
ckop=4;
}
if(PORTA.F5==0){
UART1_Write_Text("AT+BAUD4");
}
if(PORTC.F0==0){
UART1_Write_Text("AT+BAUD6");
}
if(chk=='('){
UART1_Read_Text(txt,")",13); // reads text until 'enter' is found
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 2, "Received Data");
Lcd_Out(2,1,txt);
delay_ms(500);
for(i=0;i<16;i++){txt[i]=' ';}
}
}
}
Circuit Diagram :
![]() |
Circuit |
may I ask coding / c his program?
ReplyDeleteI didn't get you.
Deletei can not dowload code
ReplyDeleteLink should work. it's a google drive link.
DeleteAwesome.
ReplyDeleteNice blog provide much information if you want to look for some beautiful
ReplyDeleteevening gowns you can visit the centraldress a unqiue store for women wear
Extraordinary post, you have called attention to some phenomenal focuses , I similarly think this s an exceptionally brilliant site.
ReplyDeleteFacilitating Admininstration
Whenever you are equipped with the examination and have picked up all that you can the rest is simple. Investigate the different retail sites to perceive what is selling best. Best Covers for Car Seats
ReplyDeleteThey ought to have the option to fix cars and utilize the various types of supplies that are needed to fix cars. Best Car Air Compressors
ReplyDeleteWow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.Thanks Best Bluetooth projectors
ReplyDeletethanks for this
ReplyDelete------------
شركة تلميع سيارات بالرياض
شركة تلميع أسطح سيارات بالرياض
شركة غسيل سيارات بالرياض
شركة تنظيف بالرياض
شركة تسليك مجارى بتبوك
شركة مكافحة حشرات ببريدة
Thankyou for sharing. visit our website and read guide about welder life expectancy
ReplyDeletevisit our website and read guide about best bow release and choose the best one
ReplyDeleteThank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our. https://lookmovies.space
ReplyDeleteWonderful blog! Do you have any tips and hints for aspiring writers? Because I’m going to start my website soon, but I’m a little lost on everything. Many thanks! https://pelisplus.world
ReplyDeleteExcellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking. https://vegamovies.today
ReplyDeleteThank you for sharing a bunch of this quality contents, I have bookmarked your blog. Please also explore advice from my site. I will be back for more quality contents. https://vegamovies.network
ReplyDeleteI wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post. https://dixmax.website
ReplyDeleteVery well written article. It was an awesome article to read. about shop xiaomi mi smart standing fan pro Complete rich content and fully informative. I totally Loved it.
ReplyDelete