Modify The HC-05 Bluetooth Module Defaults Using AT Commands
In this guide, I will explain how to use Arduino to change the settings of the ubiquitous HC-05 Bluetooth module using the AT command set. The HC-05 comes with a rich set of AT commands to perform various tasks such as changing the module's default settings including changing the pass code, the device name, and the baud rate. But the process of switching the HC-05 into AT command mode for first time users of the module is not straight forward and the docs takes short cuts. There are a couple of ways to do this. I have picked the one I think is the easiest I will do my best to illustrate the process in simple to follow steps. You can find the full set of AT commands in the attached datasheet.
The HC-05 Bluetooth module and its siblings are by far the most popular and inexpensive Bluetooth modules used for RF communications by microcontroller hackers. It costs less than $10 on ebay and it's easy to implement. I have published two guides based on the HC-05 Bluetooth module. The first guide explains how to use the HC-05 with the Arduino. The second is an Android app that simplifies controlling Arduino from your smart phone over Bluetooth using the HC-05. In both cases, the default settings for the HC-05 were fine.
In the process of using the HC-05 for a project, I ran into a situation where I needed to change the defaults for the module. For example, the default baud rate on the HC-05 is 9600. That's slow for high-speed transmission. The HC-05 can go as high as 1382400 baud rate according to the HC-05 reference. Also, the HC-05 has a default device name of HC-05. Having two or more of those devices in the same area can be confusing. You can use an AT command to change the device name. Also, the pin code default is 1234. You may wish to change that for some projects to ensure basic security.
After spending some time searching the web I realized many people are having a hard time changing the default settings for the HC-05. Switching the HC-05 from data transmission mode to configuration mode, to send AT commands to the HC-05, involves a few wiring and software acrobatics. Add to the mix all the variations of the HC Bluetooth module family and the various vendor settings and you get the picture.
This guide only covers the HC-05 module with the breakout board.
The HC-05 is a 3.3V system but the breakout board offers current limiting resistors for some protection. While it's not advisable to keep the HC-05 connected to the 5V Arduino Uno pins, for this short exercise I decided to skip the voltage dividers which I use to drop 5V to 3.3V. I advise you to use voltage dividers whenever you connect the HC-05 pins to 5V pins such as the Arduino Uno. If you skip the voltage divider, do so at your own risk.
Components & Wiring
I have tested this guide with the following:
The Arduino Code for HC-05 Command Mode
his Arduino program (HC_05.ino) does two things. It takes the AT commands you enter from the Arduino IDE Serial Monitor and sends those commands to the HC-05. The program then reads the output of the HC-05 and displays it on the Arduino IDE Serial Monitor. You can also use a terminal emulator such as Tera Term instead of the Arduino Serial Monitor.
The Arduino communicates with the HC-05 using the SoftwareSerial ports while the Arduino communicates with the user via the Serial Monitor.
AUTHOR: Hazim Bitar (techbitar)
DATE: Aug 29, 2013
LICENSE: Public domain (use at your own risk)
CONTACT: techbitar at gmail dot com (techbitar.com)
SoftwareSerial BTSerial(10, 11); // RX | TX
pinMode(9, OUTPUT); // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
Serial.println("Enter AT commands:");
BTSerial.begin(38400); // HC-05 default speed in AT command more
// Keep reading from HC-05 and send to Arduino Serial Monitor
// Keep reading from Arduino Serial Monitor and send to HC-05
Steps To Switch The HC-05 Into Command Mode
For the HC-05 module to switch to AT command mode, the HC-05 pin 34 (often referred to as the Key pin) needs to pulled HIGH but in a certain order of events explained below. When the HC-05 enters the AT command mode, it will communicate at 38400 baud rate.
Follow these steps in the stated order to switch to the HC-05 to AT command mode.
Example HC-05 AT Commands
You can send AT Commands to the HC-05 from the Arduino IDE Serial Monitor while the Arduino is running the attached Arduino program.
I have listed a few popular AT commands that will change the HC-05 device name, pass code, and speed. You will find a full set of AT commands from the attached HC-05 reference PDF file.
(remove double quotes from AT command)
- ArduDroid: Simple Bluetooth control for Arduino and Android
- TV Volume Loudness Guard
- Geo Data Logger
- Face Tracking with Arduino and OpenCV
- Kinect Controls Servos Using Human Motion
- Fast Line-following Robot
- Universal IR Remote Control Station for Android
- Bluetooth-controlled Pan-Tilt Servo
- Modify The HC-05 Bluetooth Module Defaults Using AT Commands
- Bluetooth Comm for Arduino and PC
- GOduino: The Breadboard-friendly Robot Controller
- How to Network Many Arduinos with Sensors using I2C
- Your Android Phone Is A Sensors & Comm Nervana