How to Configure HC-05 Bluetooth Module As Master and Slave Via AT Command
Intro: How to Configure HC-05 Bluetooth Module As Master and Slave Via AT Command
This tutorial is going to teach you some basics on configuring two HC-05 Bluetooth Modules as Master and Slave respectively and also a simple tutorial to see how each HC-05 controls LEDs wirelessly.
STEP 1: Introduction
Description:
HC-05 Bluetooth Module is an easy-to-use Bluetooth SPP (Serial Port Protocol) module, designed for transparent wireless serial connection setup. Its communication is via serial communication which makes an easy way to interface with controller or PC. HC-05 Bluetooth module provides switching mode between master and slave mode which means it able to use neither receiving nor transmitting data.
Specifications:
- Model: HC-05
- Input Voltage: 5VDC
- Communication Method: Serial Communication
- can switch between master mode and slave mode
- Transmission Distance: 20m ~ 30m in free space
STEP 2: Pin Definition
STEP 3: To Configure and Pair Two HC-05 As Master and Slave (Step 1)
Components that you need:
- One Arduino board... ( In this tutorial, we use Arduino Uno)
- Two Bluetooth Module HC-05
- A bunch of jumper wires
- USB Cable A-B Type
- Breadboard
STEP 4: To Configure and Pair Two HC-05 As Master and Slave (Step 2)
To configure HC-05, we will have to enter AT mode. But, how to do that? Let's check the steps below.
1. Firstly, connect the components as shown in the diagram above. From the diagram, the VCC of HC-05 is connected to the 3.3V of the Arduino Uno. If the VCC of HC-05 is connected directly to 5V of Arduino Uno, there is a high possibility that HC-05 will be damaged. But still if you insist to do so, DO IT AT YOUR OWN RISK.
2. Next, before connecting the Arduino board to the USB cable, REMOVE THE VCC WIRE FROM THE HC-05. Only after you have removed the VCC wire, connect the USB to the Arduino board.
3. Download the sample source code (file name: AT mode) attached below and upload it into your Arduino board.
4. After the uploading process is complete, then reconnect the VCC wire back to your HC-05.
5. Now you will see the LED on the HC-05 bluetooth module is blinking for every 2 seconds interval. This indicates that the bluetooth module has entered AT mode.
6. To give AT commands, open your Serial Monitor. For about 1 second, a sentence saying "Enter AT commands:" will pop up. But before that, remember to change "No Line Ending" to "Both NL & CR" and also fix the baud rate at 9600. You can refer to the diagram attached above.
7. To see whether everything is okay or not, enter "AT" and send. An "OK" will pop up on the Serial Monitor and this implies that no problems occur.
STEP 5: To Configure and Pair Two HC-05 As Master and Slave (Step 3)
Slave Configuration:
The required AT commands to set the configuration
- AT+RMAAD (To clear any paired devices)
- AT+ROLE=0 (To set it as slave)
- AT+ADDR (To get the address of this HC-05, remember to jot the address down as it will be used during master configuration)
- AT+UART=38400,0,0 (To fix the baud rate at 38400)
If the commands entered are replied with "OK" then it indicates that the settings mentioned have been customized.
You may also try out other AT commands such as how to change the name, the password, and so on. A full set of AT commands is attached below and kindly download it for your own use. Note that the password for both master and slave must be the same otherwise pairing will not be done.
STEP 6: To Configure and Pair Two HC-05 As Master and Slave (Step 4)
Master Configuration:
The required AT commands to set the configuration:
- AT+RMAAD (To clear any paired devices)
- AT+ROLE=1 (To set it as master)
- AT+CMODE=0 (To connect the module to the specified Bluetooth address and this Bluetooth address can be specified by the binding command)
- AT+BIND=xxxx,xx,xxxxxx (Now, type AT+BIND=98d3,34,906554 obviously with your respective address to the slave. Note the commas instead of colons given by the slave module.
- AT+UART=38400,0,0 (To fix the baud rate at 38400)
If the commands entered are replied with "OK" then it indicates that the settings mentioned have been customized.
You may also try out other AT commands such as how to change the name, the password, and so on. A full set of AT commands is attached below and kindly download it for your own use. Note that the password for both master and slave must be the same otherwise pairing will not be done.
STEP 7: Sample Communication Between Master and Slave (Step 1)
With the two HC-05 configured earlier just now, a simple example can be carried out to see how each of them functions. In this example, both master and slave will be controlling LEDs by using buttons. Button A at master will be controlling LED3 and LED4 at slave whereas Button B at slave will control LED1 and LED2 at master. Now let's get started.
Components that you need:
- Two bluetooth modules, HC-05
- Two Arduino boards (In this example, we use Arduino Uno)
- A bunch of jumper wires
- Two push buttons (In this example, a two-pin push button is used)
- Four LEDs (What colour it emits does not matter)
- Two USB cable A-B type
- Two resistor of 220Ω
- Breadboard
STEP 8: Sample Communication Between Master and Slave (Step 2)
*Note that the above sample hardware installation is applicable to both master HC-05 and slave HC-05.
STEP 9: Sample Communication Between Master and Slave (Step 3)
Kindly download the sample source code attached below and upload them into Arduino.
this_is_master must be uploaded into the Arduino connected to master HC-05 while this_is_slave must be uploaded into the Arduino connected to slave HC-05.
STEP 10: Result
The result is displayed in video form. You can see how master and slave interact with each other in this video. Have FUN~
22 Comments
KMOT1943 1 year ago
The same problem occurs with the SLAVE unit.
Tom Kane / Vancouver, BC, Canada
samk62417Sanl 1 year ago
TanishS2 2 years ago
ranjith.bnwr 2 years ago
AT+ADDR?
mawukoattivor 2 years ago
Kv Lineman 2 years ago
If you properly connect 05 to arduino, pin 34 high, on a true 05 it will enter At mode. Remember At mode is different then communication mode. Light will blink slow in at mode, fast in communication, and i believe its solid when connected. Good luck!
Kv Lineman 2 years ago
venegre 3 years ago
pouvez vous m'eclaircir la dessus? Merci...
rwellsz28 3 years ago
Sultannmh 3 years ago
Minion08 5 years ago
Hi,
I wanted to send data from a GPS receiver to my android phone using sh-hc-08. Would that be possible?
aprada661 3 years ago
aprada661 3 years ago
Is it required that connection?
judas79 6 years ago
I just looked at the master and slave code side by side and they seem identical except for the "Master" names:
const int ledPin = 8;
const int buttonPin = 2;
and, the slave names:
const int led = 8;
const int button = 2;
Am I missing something? Can the same .INO be used on both HC-05 modules?
aprada661 3 years ago
malexead 6 years ago
Second paragraph of article says: "... switching mode between master and slave mode which means it able to use neither receiving nor transmitting data." Why would anyone want a module which allows neither receiving NOR transmitting?
richarddl42 4 years ago
ShankarB11 4 years ago
http://bigbelectronics.in/product.php?product=hm-10-ble-bluetooth-4-0-cc2540-cc2541-serial-wireless-module
ABAVI4 4 years ago
Thanks for this simple and easy totorial
Arks rakesh 4 years ago