Pantech.AI

How to Interface the HC-05 Bluetooth Module with 8051

HC-05 Bluetooth Module

The HC-05 is a Bluetooth module used for wireless communication via serial communication (UART).

This module has 6 pins and operates in two modes: data mode and command mode. Data mode is used for transferring data between devices, while command mode allows you to modify the module’s settings using AT commands.

The HC-05 operates on either 5V or 3.3V and includes an onboard 5V to 3.3V regulator. The module’s RX/TX pins operate at 3.3V, which is compatible with the microcontroller’s input level. Therefore, no level shifting is required for the HC-05’s transmit pin. However, to connect the microcontroller’s TX pin to the HC-05’s RX, level shifting is necessary.

For further details on the HC-05 Bluetooth module and its usage, refer to the Bluetooth module HC-05 topic in the sensors and modules section.

For information on using UART with the 8051 microcontroller, see the UART in 8051 topic in the 8051 inside section.

HC-05 Bluetooth Module

HC-05 Module Pinout

HC-05 Bluetooth Connection with 8051

HC-05 Bluetooth Module Connection with 8051

Example

Let’s create a simple application to control an LED’s ON-OFF state via smartphone.

This application uses the 8051 microcontroller interfaced with the HC-05 Bluetooth module. The 8051 receives and transmits data serially through the HC-05.

In this setup, when “1” is sent from the smartphone, the LED will turn ON. When “2” is sent, the LED will turn OFF. If any other value is received, the system will send a message back to the smartphone prompting the user to select a valid option.

HC-05 8051 Programming  

Initialize UART communication on the 8051 microcontroller.

Receive data from the HC-05 Bluetooth module and check if it is “1” or “2.”

Based on the received data, perform the corresponding action to control the LED.

/*
 *HC-05 Bluetooth interfacing with 8051 to control LED via smartphone
 *http://www.electronicwings.com
 */

#include <reg51.h>
#include "UART_H_file.h"	/* Include UART library */

sbit LED=P1^0;

void main()
{
	char Data_in;
	UART_Init();		/* Initialize UART */
	P1 = 0;			/* Clear port initially */
	LED = 0;		/* Initially LED turn OFF */
	while(1)
	{
		Data_in = UART_RxChar();  /* Receive char serially */
		if(Data_in == '1')
		{
			LED = 1;/* Turn ON LED */
			UART_SendString("LED_ON");  /* Send status of LED*/
		}
		else if(Data_in == '2')
		{
			LED = 0;/* Turn OFF LED */
			UART_SendString("LED_OFF");  /* Send status of LED*/
		
		}
		else
			UART_SendString("Select proper option");
	
	}
}

Leave a Comment

Your email address will not be published. Required fields are marked *