Project 01.1 Updating the setup of HC 05

When I realized that 1234 was the default password for connecting the HC 05, I suddenly knew that the password must be changed for security reasons. But how to handle this?

In fact it is quite easy to change the setup of HC 05. It has a special mode in which you can use so called AT commands to change the setup.

All we need is a method of sending AT commands to the HC 05. The picture below gives you an idea of what we going to do.

We create a Serial connection between the MAC and Arduino, called Serial and another connection between Arduino and HC 05, called SerialBT. All Arduino has to do is read from Serial and write the read command into SerialBT. HC 05 will answer on SerialBT. Arduino will forward the answer on Serial. Easy as 1-2-3.

Required Hardware

  • Arduino uno
  • HC 05 Bluetooth module
  • 1 x LED
  • 1 x resistor 220 Ohm
  • 1 x resistor 1 kOhm
  • 1 x resistor 2 kOhm
  • 1 x switch
  • Some Jumper cables

Circuit

This circuit is almost the same as in my first project. There is only one difference: The switch or to be more precise the press button. Its GND side is connected to the EN input of HC 05.

Setting EN to HIGH while powering the HC 05 will force HC 05 into AT mode, i.e. if you want to enter AT mode you have to perform following steps:

  1. Disconnect HC 05 from power
  2. Press the button
  3. Reconnect HC 05 to power and keep button pressed
  4. Release button

If HC 05 entered AT mode its LED will blink in a 2 second frequency.

Code

/*  Working with the HC 05 Bluetooth module in AT mode
* Date: 22.02.2020
*
* This sketch sets up a connection to HC 05 to perform AT commands
*
*/


#include <SoftwareSerial.h>

// The pins we will use for the Serial
const int BTRX = 2;
const int BTTX = 3;

SoftwareSerial SerialBT(BTRX, BTTX);

/*
* Function setup
*
* Establish the connection to the HC 05
*/
void setup() {
SerialBT.begin(38400);
Serial.begin(38400);
Serial.println("AT mode activated.");
}


/*
* Function loop
*
* Read from Serial and write to SerialBT and vice versa
*
*
*/
void loop() {
// The message we will send using BT
char c;

// send a command to HC 05
if(Serial.available()) {
c = Serial.read(); // read from console
SerialBT.print(c); // write to HC 05
}

// return value from HC 05
if(SerialBT.available()) {
c = SerialBT.read(); // read from HC 05
Serial.print(c); // return to console
}
}

Once the code is uploaded and HC 05 set to AT mode, open a Serial monitor. Type AT into the console. HC 05 will answer OK.

If you type „AT+PSWD?“ HC 05 will return the current set password. To set a new, more secure password, like „0000“ you have to type „AT+PSWD=0000“ into console. If you are interested in AT commands please have a look at this page.

If you want to restore factory state type AT+ORGL. HC 05 will answer OK. The factory state is:

  1. Equipment category = 0
  2. Search code = 0x009e8b33
  3. Module job role = SlaveMode
  4. Serial port baud parameters: 38400 bit/s; 1 stop bit; no parity bit
  5. Pairing code = 1234
  6. Device name = HC-2010-06-01

To exit AT mode type as AT command AT+INIT.