HC-05 Bluetooth module Interfacing with ESP32

Overview of HC-05 Bluetooth Module

 HC-05 Bluetooth Module
 HC-05 Bluetooth Module

 

HC-05 is a Bluetooth device used for wireless communication with Bluetooth enabled devices (like smartphones). It communicates with microcontrollers using serial communication (USART).

The default settings of the HC-05 Bluetooth module can be changed using certain AT commands.

As the HC-05 Bluetooth module work on 3.6 to 6 V and its logic levels are 3.3 V for RX/TX and ESP32 can detect a 3.3V level, so, there is no need to shift the TX/RX voltage level of the HC-05 module.

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

 

HC-05 Bluetooth Hardware Connection with ESP32

ESP32 interfacing with HC-05 Bluetooth

 

 

Read the text from HC-05 Bluetooth and print it on the serial monitor using ESP32

Here, we will transmit data from Smartphone via Bluetooth to the ESP32 and display it on the Serial Monitor of the PC.

Download and install a Bluetooth terminal application on your phone and use it to connect to the HC-05 Bluetooth module.

Data is sent from the Smartphone using the Bluetooth terminal application.

 

Code for HC-05 Bluetooth using ESP32

void setup() {
  Serial.begin(9600); /* Define baud rate for serial communication */
}

void loop() {
    if (Serial.available()) /* If data is available on serial port */
    {
     Serial.write(Serial.read()); /* Print character received on to the serial monitor */
    }
}

 

  • Now upload the code. (While uploading the code make sure your ESP32 board is in the boot mode.)
  • After uploading the code open the serial monitor and set the baud rate to 9600 to see the output.

 

HC-05 Bluetooth Output on Serial Monitor

 

Let’s understand the code

In setup function

We have initiated the serial communication with a 9600 Baud rate.

void setup() {
  Serial.begin(9600); /* Define baud rate for serial communication */
}

 

In loop function

In the loop function, check the data available on the serial port, if data is available then print it on the serial monitor.

void loop() {
  if (Serial.available()) /* If data is available on serial port */
    {
     Serial.write(Serial.read()); /* Print character received on to the serial monitor */
    }

Components Used

Bluetooth Module HC-05
Bluetooth is a wireless communication protocol used to communicate over short distances. It is used for low power, low cost wireless data transmission applications over 2.4 – 2.485 GHz (unlicensed) frequency band.
1
ESP32 WROOM
WiFi Development Tools - 802.11 ESP32 General Development Kit, embeds ESP32-WROOM-32E, 4MB flash.
1

Downloads

ESP32_HC-05_Bluetooth Download
Ad