Introduction: Secure Your HC-05 Bluetooth Module Using AT Commands

In this project, we will be using AT commands with the HC-05 Bluetooth module, to make a secure connection with other Bluetooth devices. The default name of the module is HC-05 and the default password is 1234. So if you were to make a DIY door lock that can be opened using Bluetooth. For someone to get into your house all they need to do is to find in the Bluetooth setting where it says HC-05 and they can enter the password and get into your house. To fix this issue we will use AT commands to directly communicate with the HC-05 module and change up some of the settings.

This project can still be improved.

Step 1: Supplies

The components needed to make the project are:

Step 2: Wiring

There are two ways you can get your HC-05 Bluetooth Module into AT command mode. If for some reason your HC-05 does not have a button or the button is not working you can wire as shown,
Arduino >> Bluetooth Module

GND >> GND

5V >> VCC

D3 >> TXD

D2 >> RXD

EN >> 3.3v

If your Bluetooth module does have a button all you have to do is to remove the EN pin from 3.3v. Now before you plug in the power cable hold the button and then plug it in.
Arduino >> Bluetooth Module

GND >> GND

5V >> VCC

D3 >> TXD

D2 >> RXD

To check if your Bluetooth module is in AT command mode you should see the Red LED blink slowly.

Step 3: Uploading the Program

The program for this project is not so long.
We are doing this in the first part of the program because if the Bluetooth module is available, they write to the serial monitor what the Bluetooth module is saying.

  // Read from HC-05 and send data to the Arduino Serial Monitor
  if (Bluetooth.available())
    Serial.write(Bluetooth.read());

If the serial monitor is available, we are writing to the Bluetooth module in the serial monitor.

  // Read from Arduino Serial Monitor and send it to the HC-05
  if (Serial.available())
    Bluetooth.write(Serial.read());  

Note: Make sure you have set the serial monitor to 9600 bauds and Both NL & CR

For more information about this, please visit my Patreon:
https://www.patreon.com/acedinventor

Step 4: Working With AT Commands

Here are some of the AT commands which you can use. If you were playing around with the commands and your Bluetooth module stops working you can try the last two commands which are "AT+RESET" or "AT+ORGL" which will reset your module or reset to the factory default your module.
Note: If you reset your module there is a possibility that the name will change from "HC-05" to something else.

  HC-05 AT Commands
  Function                | Command                  | Response         | Parameter
  Test                    | AT                       | OK               | None
  Name                    | AT+NAME?                 | +NAME:HC-05, OK  | HC-05 (Default)
  Password                | AT+PSWD?                 | +PSWD:1234, OK   | 1234 (Default)
  Change Name             | AT+NAME = <name>         | OK               | None
  Change Password         | AT+PSWD=<pswd>           | OK               | None
  UART                    | AT+UART?                 | +UART:38400,0,0  | 38400 (Default
  Connection mode         | AT+CMODE?                | +CMOD:<cmod>     | 0 (Default)<br>
  Connection mode set     | AT+CMODE=<cmode>         | Ok               | (0 (Connect to a specified 
  address)) >> (1 (Connect to any available address))
  Find Address            | AT+ADDR?                 | +ADDR:<addr>, OK | None
  Connect to Address      | AT+BIND=<addr>           | OK               | Replace the : with ,
  Reset Device            | AT+RESET                 | OK               | None
  Restore Factory Default | AT+ORGL                  | OK               | None

Step 5: Testing the Project

To test if everything is working properly, wire up the project and plug it into your computer. The LED on the HC-05 should blink slowly. Open serial monitor on Arduino IDE. Set the baud rate to 9600 and change newline to newline & carriage return. Type "AT" on the serial monitor. If you get a reply of "OK," it means you have successfully entered "AT Command Mode." After that change the name and password. Unplug your Arduino and then disconnect the HC-05 EN pin from 3.3v. Plug your Arduino into your computer and then open your phone. Turn on Bluetooth. Go in the setting and you will see a new Bluetooth device with the name and password you chose.

If there is still something you don't understand, you can comment down below.

Microcontroller Contest

Participated in the
Microcontroller Contest