HC-05 with Arduino

Description

A lesson focused on using the HC-05 Bluetooth module with Arduino to establish wireless communication between a smartphone and an electronic board. We will examine how to connect and configure the Bluetooth module, understand how serial communication works, and learn how to send commands from mobile devices using the "Arduino Bluetooth Controller" and "BT Car Controller" apps. This is a practical introduction to remotely controlling Arduino projects, ideal for robotic vehicles, smart devices, home automation systems, and DIY electronics applications.

Required components:

  • 1x Arduino UNO
  • 1x HC-05 Bluetooth module
  • Jumper wires (and an optional breadboard)

Module image

1 Image of the HC-05 Module 2 Immagine del modulo HC-05

HC-05 Bluetooth module with Arduino: how it works and how to configure it

What is the HC-05 Bluetooth module?

The HC-05 Bluetooth module allows Arduino to communicate wirelessly with smartphones, tablets, computers, and other Bluetooth devices.
Its operation is very simple: it receives data via Bluetooth and sends it to Arduino through serial communication.
It can therefore be used to control robots, toy cars, lights, motors, and sensors directly from an application.
The HC-05 does not control electronic components itself: it acts as a “bridge” between Arduino and the Bluetooth device.

Connecting the HC-05 module to Arduino

The module's most important pins are VCC, GND, TXD, and RXD.
On common HC-05 boards equipped with a regulator, the VCC pin can be connected to Arduino's 5V pin, while GND must be connected to GND.
The HC-05 TXD pin must be connected to Arduino pin 10, which in our example will be used to receive data.
Arduino pin 11 must instead be connected to the HC-05 RXD pin.
The TX and RX connections are therefore crossed: the transmitter must be connected to the receiver.

It is advisable to place a voltage divider between Arduino pin 11 and the module's RXD pin.
Arduino Uno transmits 5V signals, while the HC-05 RX input uses logic levels of approximately 3.3V.
The HC-05 TXD pin can instead be connected directly to Arduino pin 10.

Understanding normal mode and AT mode

The HC-05 module can operate in two different modes.
Communication mode is normally used to send data between Arduino and the smartphone.
AT mode is used to change the module's internal settings, such as its Bluetooth name, pairing PIN, serial speed, and master or slave role.
In practice, AT mode is a small hidden configuration area within the module.

Enabling AT mode on the HC-05

Before powering the module, hold down the small button on the HC-05 board, or set the KEY or EN pin high according to your board's instructions.
While keeping the button pressed, connect the power supply.
When the LED flashes slowly, generally about once every two seconds, the module is in AT mode.
The HC-05's full AT mode normally uses a speed of 38400 baud.

On some boards, you may need to keep the button pressed even while sending commands.
If the LED continues to flash very quickly, the module is probably still in normal pairing mode.

Uploading the Arduino code for AT commands

This code creates a connection between the computer's Serial Monitor and the HC-05 module.
Everything you type in the Serial Monitor will be sent to the Bluetooth module, while its responses will be displayed on the screen.

bluetooth_module.ino
// https://nemiatools.com
#include <SoftwareSerial.h>

// Arduino RX, Arduino TX
// HC-05 TXD → Arduino pin 10
// Arduino pin 11 → voltage divider → HC-05 RXD
SoftwareSerial hc05(10, 11);

void setup() {
  // Communication between Arduino and the computer
  Serial.begin(9600);

  // Communication with the HC-05 in AT mode
  hc05.begin(38400);

  Serial.println("HC-05 ready in AT mode");
  Serial.println("Select Both NL & CR in the Serial Monitor");
}

void loop() {
  // Display the HC-05 responses on the computer
  if (hc05.available()) {
    Serial.write(hc05.read());
  }

  // Send to the HC-05 what is typed on the computer
  if (Serial.available()) {
    hc05.write(Serial.read());
  }
}

After uploading the code, open the Arduino IDE Serial Monitor.
Set the Serial Monitor speed to 9600 baud and select the Both NL & CR option.
The 9600 baud setting applies to communication between the computer and Arduino, while the 38400 baud setting in the code applies to communication between Arduino and the HC-05 in AT mode.

Changing the HC-05 name, password, and settings

To check that everything is working, type the AT command in the Serial Monitor and press Enter.
If the connection is correct, the module should respond with OK.

AT

To change the module's Bluetooth name, use the following command.
You can replace NEMIATOOLS with any name you prefer.

AT+NAME=NEMIATOOLS

To check the name currently saved, use:

AT+NAME?

To change the pairing PIN, use the following command.
In this example, the new PIN will be 2580.

AT+PSWD=2580

To read the PIN currently set:

AT+PSWD?

To use the module with a smartphone, it is advisable to leave it in slave mode.
A value of 0 indicates slave mode, while a value of 1 sets the module as master.

AT+ROLE=0

To check the currently configured role:

AT+ROLE?

The speed used during normal Bluetooth communication can be set with the following command:

AT+UART=9600,0,0

The first value indicates a speed of 9600 baud.
The second value indicates the use of one stop bit.
The third value disables parity checking.
This is a simple configuration suitable for most Arduino projects using the HC-05.

To check the saved serial speed:

AT+UART?

You can also read the module's firmware version and Bluetooth address:

AT+VERSION?
AT+ADDR?

If you have changed too many settings and want to return to the original configuration, use:

AT+ORGL

Warning: this command restores the module's original settings and deletes the changes you have made.
To restart the module using a command, use:

AT+RESET

Exiting AT mode and connecting the smartphone

After saving the settings, disconnect the module's power supply.
Reconnect it without pressing the button and without activating the KEY pin.
The LED should start flashing quickly again, indicating that the module is waiting for a connection.
Open the smartphone's Bluetooth settings and look for the new name you selected, for example NEMIATOOLS.
When prompted, enter the new PIN configured with the AT+PSWD command.

If the smartphone had already saved the module under its old name or old PIN, you may need to remove the previous pairing and repeat the procedure.

Controlling Arduino with a Bluetooth app

After pairing the smartphone with the HC-05, you can use an application compatible with Bluetooth serial communication.
These applications send simple letters, numbers, or words to Arduino.
Arduino can then interpret each character as a command: for example, one letter can make a toy car move forward, while another can turn on a light.

The applications that we at NEMIATOOLS use most often are Arduino Bluetooth Controller and BT Car Controller.
Arduino Bluetooth Controller provides several interfaces, buttons, and terminals for sending commands to the module.
BT Car Controller instead provides an interface designed mainly for Bluetooth robots and toy cars.

Arduino Bluetooth Controller: Play Store
BT Car Controller: Play Store

Using the module in normal mode

After configuration, the module should no longer communicate at 38400 baud, but at the speed set with the AT+UART command.
If you used AT+UART=9600,0,0, you must therefore set communication with the HC-05 to 9600 baud in the Arduino program for your project.
In the previous code, you would simply replace:

hc05.begin(38400);

with:

hc05.begin(9600);

The module must also be powered on normally, without pressing the button and without enabling AT mode.

Troubleshooting the most common problems

If the AT command does not return OK, first check that the module is actually in AT mode.
Also check that TXD is connected to pin 10, RXD is connected to pin 11, and Arduino and the HC-05 share the same GND.
Check that the Serial Monitor is set to 9600 baud and to the Both NL & CR option.

If unreadable characters appear, an incorrect serial speed has probably been selected.
If the smartphone does not accept the new PIN, remove the old Bluetooth pairing and pair the module again.
If some commands do not respond, try holding down the module's button while sending them.

Once you have completed these steps, your HC-05 Bluetooth module with Arduino will be ready for use in robots, remote-controlled toy cars, home automation systems, and many other wireless projects.