The Blink Sketch

HC-05 Bluetooth Module Master Mode

The HC-05 bluetooth module comes configured as a slave, and as such can only connect with a master, like a PC or another HC-05 previously configured as a master. To change a module to be a master requires the module be in "AT" mode, which is the mode that allows you to enter commands. Some modules have a "KEY" pin, which is connected to pin 34 on the module. That is used to enter command mode. You tie the pin to VCC, and then power up the module. The module will then be in command mode.

Many other modules do not have a "KEY" pin, and appear to have no way to enter comand mode. If the module is really an HC-05, and not an HC-06, there is another way. It involves soldering on end of a jumper to pin 34 on the module. If it looks difficult, it really isn't. The pins on the module are tiny, but they are not particularly close together. I used a breadboard jumper - the kind with pins on each end - and soldered the tip of one pin to the module.

How do I enter command mode?

If the module already has a "KEY" pin, just connect it to the VCC pin before powering the unit up. Both pins will go high at the same time, and the module will start in command mode. If you have had to put a jumper on pin 34, you do it the same way, but you connect the jumper to the VCC pin before powering everything up. Command mode is indicated by an LED which blinks on for just over a second, and off for the same time. If it is not in command mode, it blinks two times per second.

Programming the HC-05

Once in command mode, you have all of the time in the world. The module does not time-out and leave command mode. Theree are probably several things you want to do while you are at it. First, of course, is to set the module to be a master. That is done by entering the following command:

AT+ROLE=1

The module will become a master. While you are at it, though, you should change the name to be something more meaningful than "HC-05". I named mine "MASTER" so I would know it when I see it.

AT+NAME=MASTER

The Baud rate defaults to 9600, which is quite a bit lower than it needs to be. The module can handle 115.2kBaud, and should probably be that speed for throughput, unless you have a reason to run it slower. To change the Baud rate, enter a command from the following table.

CommandBaud rate
AT+UART=1200,0,01200
AT+UART=2400,0,02400
AT+UART=4800,0,04800
AT+UART=9600,0,09600
AT+UART=19200,0,019.2k
AT+UART=38400,0,038.4k
AT+UART=57600,0,057.6k
AT+UART=115200,0,0115.2k

To exit command mode, disconnect the jumper from VCC, and power cycle the module. It will come back up with the Baud rate you selected previously. Command mode, when activated in this way, is always at 38.4kBaud. If you are confident you have nothing else to change, power off and remove the jumper from pin 34.

You can test your changes by powering up two modules - one in master mode and one in slave mode. They will blink rapidly for a few seconds, then change to two flashes every two seconds, indicating they are connected. To verify, jumper RXD and TXD on the slave unit, and connect a 3.3V USB to TTL converter to the master. Anything you enter in a terminal window on the master will be sent to the slave, looped back, and sent back to the master. It should show up on your screen. If it shows up double, turn off local echo.

The closest module is in "Initialized" state, meaning running but not connected, and the one behind is in command mode.

You can use the same process to change the name and Baud rate of the slave - but don't change the mode.

The closer module is the slave and the farther module is the master. Powering them up causes them to automatically locate and pair with each other. It takes just over a second to pair. You can begin serial communication as soon as they've paired. If you need to get a definite status of the pairing, the "STATE" pin on the header has a signal that exactly matches the LED. Unpaired they put out a 5Hz squarewave. If the line goes low for approximately 2.5 seconds, then pulses twice, with 100mS pulses, the module is paired with another module. It will continue that pattern for as long as it is paired. If it loses connection with the other module, it will begin the 5Hz squarewave pattern again.

Arduino Board Logo

 

Arduino-Board is the go-to source for information on many available Arduino and Arduino-like boards, tutorials and projects.

Help and Support

Arduino-Board

Stay updated

Sign up if you would like to receive our once monthly newsletter.