I interfaced PIC16F877A with a HC-05 Bluetooth module using serial communication and I can transmit data from the PIC to my PC. I connected my PC's Bluetooth to HC-05 Bluetooth module and in Tera Term or termite 2.9 I see the output. However, when I send data from the terminal I receive nothing on the PIC. As per my code the data received by PIC showed by echoed back by transmitting the same.

My PIC code

#include <htc.h>
#define _XTAL_FREQ  16000000
#define BAUDRATE 9600
void InitUART(void)
    BRGH = 1;
    SPBRG = ((_XTAL_FREQ/16)/BAUDRATE) - 1;
    TRISC6 = 0; // TX Pin
    TRISC7 = 1; // RX Pin 
    TXSTA = 0x24;
    RCSTA = 0x90;
    //SPBRG  = 129;
void SendByteSerially(unsigned char Byte) // Writes a character to the serial port
    while(!TXIF) ; // wait for previous transmission to finish
    TXREG = Byte;

unsigned char ReceiveByteSerially(void) // Reads a character from the serial port
    continue;   // Wait for transmission to receive
return RCREG;

void SendStringSerially(const unsigned char* st)

void main (void)
    unsigned char SerialData;
    unsigned int i;
    InitUART(); // Intialize UART
    SendStringSerially("Hello World");
    for(i=0; i<100; i++)
    for(i=0; i<100; i++)
    SerialData = ReceiveByteSerially();

In the while loop I blink a LED for 1 second if any data is received.

  • 1
    \$\begingroup\$ Or you can do it with one electronics.stackexchange.com/questions/94921/… \$\endgroup\$
    – Martin
    Commented Jan 13, 2014 at 6:51
  • \$\begingroup\$ i have a project and i want to send data from android application to pic16f877a i try to use your code but it doesn't send to pc , can you tell me if you make any configuration for HC-05 befor you use it , or can you help my to send data . pleas. \$\endgroup\$ Commented Nov 25, 2014 at 11:30

1 Answer 1


The HC-05 Bluetooth module runs off a 3.3V supply. If you're running your PIC off 5V then you'll need to level-shift the module's 3.3V output signal to a 5V signal input to the PIC. Figure 6 in the product guide manual:


...shows how to do that with a couple of transistors.

  • \$\begingroup\$ the HC-05 has 3.3 volt regulator, so we can wire directly to 5 volt \$\endgroup\$ Commented Nov 1, 2014 at 19:42
  • \$\begingroup\$ @makouda True, the JY-MCU board has a 3.3V regulator to power the HC-05 but the signal levels coming out of the HC-05 module itself are still relative to 3.3V - so level shifting is still required if you are communicating with a MCU running off 5V \$\endgroup\$
    – aja
    Commented Nov 2, 2014 at 3:06
  • \$\begingroup\$ tell me, but when i use two HC-05 modules to communicate between PICs, I dont need regulator?????. since I receive from another HC-05 \$\endgroup\$ Commented Nov 2, 2014 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.