HC-05 with firmware 2.0-20100601

There are now many cheap and no brand HC-05 modules that use the 2.0-20100601 firmware and rather than keep making the same post for different modules I will have a single main post which, as I update and add to it, will become a single point of reference.

The 2.0-20100601 firmware is originally by HC/Wavesen and as the version number may suggest it is from 2010. I am not sure if other manufacturers use it under license or simply copy it since the genuine HC/Wavesen modules now use version 2.1 firmware.

HC-05
HC-05 with 2.0-20100601: AT Command Mode
HC-05 with 2.0-20100601: Connecting to an Arduino
HC-05 with 2.0-20100601: Initial Communications Test
HC-05 with 2.0-20100601: Main AT Commands
HC-05 with 2.0-20100601: AT Commands Dealing With Connections
HC-05 with 2.0-20100601: Making A Connection
Downloads

 

 

HC-05

HC-05s are Bluetooth 2 EDR devices that have a serial UART layer on top of the Bluetooth. The UART layer makes them easy to use but hides the Bluetooth functions from the user. This makes then easy to use with microprocessors like Arduinos, especially if all you want is to let 2 things talk to each other.

The HC-05 can operate as either a slave or master device.
Slave devices cannot initiate connections, they can only accept them. If you want to form a connection with a mobile device such as an Android phone, the phone will be the master device and so the HC-05 will need to be the slave.
Master devices can initiate and control connections. If you want to link two HC-05s, one will need to be a master and the other one a slave. When using with a HC-06, the HC-06 will be the slave (HC-06s are slave only).

The HC-05 has two modes of operation; AT command mode and communication mode.
When in AT command mode the device accepts commands and all data received over the serial UART connection is treated as a command.
When in communication mode, all data received over the serial UART connection is treated as data and sent to the connected device. If HC-05 is in communication mode but not connected to another device the data disappears in to some mysterious void.


 

HC-05 with 2.0-20100601: AT Command Mode

AT command mode allows you to control the module, check the modules settings, and change the settings; things like the name, the baud rate, whether or not it operates in slave mode or master mode, to make a connection, and whether or not it auto connects on start.

The HC/Wavesen 2.0-20100601 firmware has different AT command modes:

  • A full mode at 38400 baud.
  • A partial mode at 38400 baud.
  • A partial mode at the user settable baud rate.
  • A partial mini mode (even less commands work) at the user settable baud rate.

The majority of commands work when in any AT command mode but there are some key commands that only work in the full AT command mode. This fooled me for quite a while. I now believe the partial/mini AT command mode is a bug in the firmware and so I now only recommend using the full 38400 baud rate AT command mode.

To put the HC-05 in to AT command mode pin 34 has to be HIGH on power up. On most HC-05s there is a small button switch which connects pin 34 to 3.3v when closed, therefore, to enter AT command mode we can either:
– Directly connect pin 34 to 3.3v on start, or
– Close the push button switch and power on the module.

To enter full AT command mode, pin 34 has to be HIGH all the time.

To enter AT mode using the button switch:
– power off the module,
– press and hold the small button switch,
– re-apply power while holding the button switch closed,
– when you see the LED come on, release the button switch.

Please remember, this puts the module in to a “mini” AT command mode and not all commands work. For AT command mode to be fully operational pin 34 should be kept HIGH but this is not possible when using just the push button switch. Therefore, some commands need you to close the switch before sending.
To put the module in communication mode simply cycle the power without closing the button switch.

To enter AT command by connecting pin 34 to +3.3v:
– connect pin 34 to +3.3v
– power on the module.

This puts the HC-05 in to full AT command mode and all commands should work. To return to communication mode, remove the +3.3v from pin 34 and cycle the power. If you are doing a lot of work in AT command mode you could solder a wire directly to pin 34 and connect to +3.3v.

When in AT command mode the LED flash rate will change to 1 second on, 1 second off (or maybe a little slower).

You can also enter a mini AT command mode by pressing the button switch after the module is powered but since many commands do not work I believe this is a bug in the firmware and no longer recommend this method.


 

HC-05 with 2.0-20100601: Connecting to an Arduino

To use AT commands we need to communicate with the HC-05 over the serial UART channel. There are 2 main ways of doing this; with a USB to serial UART adapter, or an Arduino and a serial in – serial out sketch.

If using a serial UART adapter simply connect and open the Arduino serial monitor. Be aware that the main window will only display the replies from the HC-05.
The HC-05 RX pin is 3.3v not 5V. The adapter here has a jumper to select the voltage. If your adapter is 5V only you will need to bring the adapters 5v TX line down to 3.3v before connecting to the HC-05s 3.3v RX pin.
HC-05_2.0-20100601_UART_Adpater_1200

 
For the examples below I am using an Arduino and a serial sketch. Using this setup allows me to echo the commands to the serial monitor so we can clearly see what is happening.
HC-05_2.0-20100601_BreadBoard_1200

HC-05_2.0-20100601_Circuit_01_800

For convenience I have soldered a wire directly to pin 34. There is no need to do this unless you are using AT command mode a lot. If you just want to set up the HC-05 once or twice use the push button switch.
HC-05_2.0-20100601_WireOnPin34_1200

HC-05_2.0-20100601_BreadBoard_Pin34_1200

HC-05_2.0-20100601_BreadBoard_Pin34Closeup_1200The voltage divider converts 5V to 3.3v. To control the pin status I use the main vcc lead to the voltage divider. To set pin34 to ground I simply remove the lead from 5v.

HC-05_2.0-20100601_Circuit_02_PIN34_800

 

HC-05 with 2.0-20100601: Serial Sketch

//  SerialIn_SerialOut_004
//
//  Uses hardware serial to talk to the host computer and Software Serial for communication with the bluetooth module
//
//  What ever is entered in the serial monitor is sent to the connected device
//  Anything received from the connected device is copied to the serial monitor
//
//  Pins
//  BT VCC to Arduino 5V out. 
//  BT GND to GND
//  Arduino D8 (SS RX) - BT TX no need voltage divider 
//  Arduino D9 (SS TX) - BT RX through a voltage divider (5v to 3.3v)
//
 
#include <SoftwareSerial.h>
SoftwareSerial BTserial(8, 9); // RX, TX
 
char c=' ';
boolean NL = true;
 
void setup() 
{
    Serial.begin(9600);
    Serial.print("Sketch:   ");   Serial.println(__FILE__);
    Serial.print("Uploaded: ");   Serial.println(__DATE__);
    Serial.println(" ");
 
    BTserial.begin(38400);  
    Serial.println("BTserial started at 38400");
    Serial.println(" ");
}
 
void loop()
{
    // Read from the Bluetooth module and send to the Arduino Serial Monitor
    if (BTserial.available())
    {
        c = BTserial.read();
        Serial.write(c);
    }
 
 
    // Read from the Serial Monitor and send to the Bluetooth module
    if (Serial.available())
    {
        c = Serial.read();
        BTserial.write(c);   
 
        // Echo the user input to the main window. The ">" character indicates the user entered text.
        if (NL) { Serial.print(">");  NL = false; }
        Serial.write(c);
        if (c==10) { NL = true; }
    }
}


 

HC-05 with 2.0-20100601: Initial Communications Test

To check that everything is wired up correctly we can use the “AT” command. This simply returns an “OK”.
Make the circuit, connect to the Arduino. The LED on the HC-05 should be blinking quickly about 5 times a second. When the HC-05 is in AT command mode the LED will change to slow blink, 2 seconds on, 2 seconds off.

Enter AT command mode using the push button switch

– remove the power to the HC-05
– press and hold the button switch
– add power to the HC-05 (while holding the button switch)
– when you see the LED come on release the button switch.

Enter AT command mode using a direct connection to pin 34

If you had pin 34 connected to 3.3v the HC-05 should have started in AT command mode. If it did not:
– remove power
– connect pin34 to +3.3v
– add power

Open up the Arduino IDE and upload the above sketch. Then open the serial monitor. You see something like:
HC-05_2.0-20100601_SerialMon
Make sure “Both NL &CR” is selected and the baud rate is set to 9600.

Note that there are 2 different baud rates being used; 9600 for the serial monitor, and 38400 for the HC-05.

To see if we have everything connected correctly, enter “AT” and you should get an “OK” reply.
HC-05_2.0-20100601_SerialMon_AT_00


 

HC-05 with 2.0-20100601: Main AT Commands

The 2.0-20100601 firmware has a fairly long list of commands. Some perform common functions and others you may never need. Here are some of the more useful/common commands. Remember that some commands need pin 34 to be HIGH. I have tried to highlight this but may have missed some. If you are using the button switch and do not get a reply, try closing the switch and send the command again (while keeping the switch closed).

Command Comment
AT Serial communications test.
Returns “OK”.
AT+VERSION? Get the firmware ID/version number.
Returns “+VERSION:2.0-20100601″.
AT+ORGL Resets the module to the factory default settings.
Returns “OK”.
AT+RESET Restarts the module. Some times required for changes to take place.
AT+NAME? Get the device name. Requires pin 34 to be HIGH. If the pin is not HIGH the HC-05 will not reply.
Returns the device name such as “+NAME:H-C-2010-06-01″.
AT+NAME=newName Change the modules name to newName.
Returns an “OK” if successful.
AT+ADDR? Query the module mac address. Returns a hex value in the form “+ADDR:1234:12:123456″.
AT+UART? Query the baud rate used for UART serial communication. This is the speed a host device like an Arduino uses to talk to the BT module. It is not the the speed used to send wireless signals between different modules.
Returns the baud rate, stop bit, parity bit in the form “+UART:38400,0,0″
AT+UART=baudRate,stop,parity Set the baud rate used for serial UART commincation.
baudRate is one of the following decimal values:
4800
9600
19200
38400
57600
115200
230400
460800
1382400
stop is the stop bit. Either 0 or 1
parity is the parity but. Either 0, 1, or 2.
0 = none.
1 = odd.
2 = even.
i.e. “AT+UART=38400,0,0″
AT+STATE? Query the current device state.
Replies with one of the following:
INITIALIZED
READY
PAIRABLE
PAIRED
INQUIRING
CONNECTING
CONNECTED
DISCONNECTED
UNKNOWN
AT+ROLE? Query the current role. Returns 0,1, or 2.
0 = slave mode
1 = master mode
2 = slave echo mode.
AT+ROLE=x Set the module mode.
Where x = 0,1, or 2.
AT+ROLE=0 puts the HC-05 in to slave mode.
AT+ROLE=1 puts it in to master mode.
AT+ROLE=2 puts it in to slave echo mode.
Returns “OK” if successful.
In Slave echo mode, the module echos back the data it receives.
AT+CMODE? Query the current connection mode. Returns the connection mode value (0,1,2) in the form “+CMOD:0″.
0 = Manual connection.
1 = Auto connection on start.
2 = Slave loop mode.
AT+CMODE=x Set the connection mode.
Where x can be 0,1, or 2. For CMODE to work, the module has to be in master mode (“AT+ROLE=1″).
0 = Manual connection: The remote device address must be specified to make a connection.
1 = Auto connect: Connect to any module/last connected module on start.
2 = Slave loop mode.
AT+PSWD? Query the current PIN.
Returns a 4 digit decimal number.
AT+PSWD=xxxx Set the PIN code used for pairing
xxxx = a 4 digit decimal number.
AT+PAIR=address,timeout Attempt to PAIR with a remote Bluetooth device.
The address must be in the form 1234,56,abcedef (notice the commas).
timeout is a decimal value that sets the length of time to try.
“AT+PAIR=98d3,32,70facf, 9″ attempts to PAIR with a slave module with the address 98d3:32:70facf for 9 seconds. If pairing is not successful within 9 seconds a”FAIL” error message is given.
The SPP has to be initialized before using the AT+PAIR command.
AT+INIT Initialize the Serial Port Profile (SPP)
This is required by some of the other commands.
“AT+INIT” requires pin34 to be HIGH. If the HC-05 is in AT command mode but pin34 is not HIGH the module will not reply.
If AT+INIT is used and SPP has already been initialized the “ERROR(17)” error message is given.
If a command requires SPP and it has not been initialized a “ERROR(16)” error message is given.

For a full list of the available commands, download the datasheet.

AT+NAME
To get the modules name, use “AT+NAME?”
HC-05_2.0-20100601_AT_NAME

To change the name of the module use “AT+NAME=newName” where newName is any string up to 32 characters in length. To change the name to “MainLightSensor” use “AT+NAME=MainLightSensor”
HC-05_2.0-20100601_AT_NAME_02
And use “AT+NAME?” again to check the change was successful.
HC-05_2.0-20100601_AT_NAME_03

Note:
“AT+NAME?” only works when pin 34 is HIGH, therefore, if using the button switch you need to press and hold the switch closed while you send the command. After you get a reply you can release the switch.
“AT+NAME=newName” works when pin 34 is HIGH or LOW (as long as you are in AT command mode of course).

AT+ADDR
To get the mac address of the HC-05 use “AT+ADDR?”. This is a read only command and you cannot change the mac address.
HC-05_2.0-20100601_AT_ADDR

AT+UART
To get the baud rate used for serial commication when in transmission mode use “AT+UART?”.
HC-05_2.0-20100601_AT_UART_01

To set the baud rate use “AT+UART=baudRate,stop,parity” where baudRate is one of the values from the list in the table above. For most occasions stop and parity should be 0. To set the baud rate to 57600 the command is “AT+UART=57600,0,0″
HC-05_2.0-20100601_AT_UART_02
Remember, this sets the baud rate for the transmission mode only. The baud rate for AT command mode is set to 38400.

Note:
Software serial doesn’t work well at high speeds. The fastest I have good results with is 38400 and this is not 100% guaranteed. If speed is important but not critical try AltSoftSerial. If speed is critical you really need to be using the hardware serial channel.
In all the examples I use Software serial or AltSoftSerial to talk to the Bluetooth module. This leaves the hardware serial free so I can use the serial monitor.

AT+PSWD
Bluetooth 2 devices often require a PIN or passcode when pairing with other devices.The HC-05 is no exception and to see what the PIN is set to use “AT+PSWD?”
HC-05_2.0-20100601_AT_PSWD_01

and to set a new PIN use “AT+PSWD=xxxx” where xxxx is a 4 digit number.
HC-05_2.0-20100601_AT_PSWD_02

 

 

HC-05 with 2.0-20100601: AT Commands Dealing With Connections

Not yet available. In the meantime please see the links below.

 

 

HC-05 with 2.0-20100601: Making A Connection

Connecting 2 Arduinos by Bluetooth using a HC-05 and a HC-06: Easy Method Using CMODE
Connecting 2 Arduinos by Bluetooth using a HC-05 and a HC-06: Pair, Bind, and Link

 

 

HC-05 with 2.0-20100601: Downloads

HC-05 FW 2.0-20100601 DataSheet (English)

 
 
 
 

One thought on “HC-05 with firmware 2.0-20100601

  1. Pingback: HC-05 (ZG-B23090W) Bluetooth 2.0 EDR modules | Martyn Currey

Leave a Reply

Your email address will not be published. Required fields are marked *


− five = 2

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>