top of page

HC-05 Bluetooth Module Interfacing with PIC18F4550

Updated: Feb 2

Overview of Bluetooth


  • HC-05 is a Bluetooth device used for wireless communication. It works on serial communication (USART).

  • It is a 6-pin module.

  • The device can be used in 2 modes; data mode and command mode.

  • The data mode is used for data transfer between devices whereas command mode is used for changing the settings of the Bluetooth module.

  • AT commands are required in command mode.

  • The module works on 5V or 3.3V. It has an onboard 5V to 3.3V regulator.

  • As the HC-05 Bluetooth module has a 3.3V level for RX/TX and the microcontroller can detect 3.3V level, so, no need to shift the transmit level of the HC-05 module. But we need to shift the transmit voltage level from the microcontroller to RX of the HC-05 module.


For more information about the HC-05 Bluetooth module and how to use it, refer to the topic Bluetooth module HC-05 in the sensors and modules section.


For information on USART in PIC18F4550 and how to use it, refer to the topic on USART in PIC18F4550 in the PIC inside section.


HC-05 Bluetooth Module


Connection Diagram of Bluetooth Module HC-05 to PIC18F4550


HC-05 Bluetooth Module Interfacing with PIC18F4550


Control the LED using HC-05 Bluetooth Module and PIC18F4550


Here let’s develop a small application in which we can control LED ON-OFF through a smartphone.


This is done by interfacing PIC18F4550 with the HC-05 Bluetooth module. Data from HC-05 is received/ transmitted serially by PIC18F.


In this application, when 1 is sent from the smartphone, LED will turn ON and if 2 is sent LED will get Turned OFF. If received data is other than 1 or 2, it will return a message to mobile that select the proper option.


 Programming HC-05


  1. Initialize PIC18F4550 USART communication.

  2. Receive data from the HC-05 Bluetooth module.

  3. Check whether it is ‘1’ or ‘2’ and take respective controlling action on the LED.

 


HC-05 Bluetooth Module Code for PIC18F4550


/* Interface HC-05 Bluetooth module with PIC18F4550
 * http://www.electronicwings.com
 */

#include <pic18f4550.h>
#include "Configuration_Header_File.h"
#include "USART_Header_File.h"

#define LED LATD0             
void main()
{
    OSCCON=0x72;  /* use internal oscillator frequency
                                 which is set to 8 MHz */
    char data_in;
    TRISD = 0;  /* set PORT as output port */
    USART_Init(9600);  /* initialize USART operation with 9600 baud rate */ 
    MSdelay(50);
    while(1)
    {
        data_in=USART_ReceiveChar();
        if(data_in=='1')
        {   
            LED = 0;  /* turn ON LED */
            USART_SendString("LED_ON");  /* send LED ON status to terminal */
        }
        else if(data_in=='2')
                
        {
            LED = 1;  /* turn OFF LED */
            USART_SendString("LED_OFF");  /* send LED OFF status to terminal */
        }
        else
        {
            USART_SendString(" select 1 or 2");  /* send msg to select proper option */
        }
        MSdelay(100);
    }
}



5 views0 comments

댓글


bottom of page