Introduction: Arduino Bluetooth Master, and Slave Using Any HC-05 Modules

Do you have HC-05 Blue-Smurf modules already, and have no idea what to do, or are you just looking to be able to connect two arduinos together wirelessly? This is the place to be!

This tutorial is meant to cut through all of the confusing tutorials on the internet, and show you how to finally get your HC-05 modules working together. I personally struggled for days trying to get mine working, and simply couldn't. I pulled through however, and here is an all encompassing tutorial meant to be the end all, be all of master, and slave connections, no matter the model number, or set up. I will have links to contributors in the reference section, in the code, and will also add to this tutorial as I see fit.

From ZS-040 models, to FC-114 models, to the strangest of the strange, this tutorial is meant to work with all HC-05's, and will hopefully adapt to help this purpose over time.

The setup we will be using is just a simple blink over Bluetooth serial program, but I currently have a setup for my BB-8 which uses an ultrasonic sensor in the dome to control the drive system in the ball. It will soon be able to roll around autonomously, and I will link to that instructable here when it is done.

https://www.instructables.com/id/Autonomous-BB-8-Drive-System/

Let's get started!

Step 1: Parts

1. Breadboard (you could also have two of them)

2. Two Arduino Boards (I am using a nano, and an uno, but I am sure a mega, and some others would work)

If you don't have a lot of arduino, I recommend getting a starter kit.

https://www.amazon.com/Kuman-Project-Complete-Star...

3. 2 HC-05 Bluetooth Modules (The ZS-040 modules are the best, but any one with a button is convenient w/o is hard)

https://www.amazon.com/gp/product/B00XXALRUG/ref=o...

http://www.banggood.com/3Pcs-HC-05-Wireless-Blueto...

Or, find one on ebay for cheap.

4. Push Button (any kind will work, but the one I started out with began to slip out of the breadboard)

5. Led's (any color, and size works, but if using small ones, I recommend a resistor)

6. One Resister (1k ohm I think)

7. Wires (you will need a lot of these in various colors, and sizes)

Step 2: Wiring If Your HC-05 Has a Button!

There will be a small button connected to the En pin, it should be on the lower right hand side of the face with the electronics. If you don't have this button, skip to the next step, but if you do, follow the wiring above, and annotated below. This method has worked with the ZS-040, and FC-114 modules which I currently have.

Arduino 1 (Mine is the nano)

Plug the bluetooth module into the breadboard to the right of the nano.

5v to vcc on bluetooth module

gnd to gnd on bluetooth module

pin d10 to txd on bluetooth module

pin d11 to rxd on bluetooth module

Bridge the push button across the middle of the breadboard to the right of the bluetooth module.

pin d2 to push button top right

5v to push button bottom left

take out resistor 1k ohm from push button bottom right to gnd

Plug the led into the breadboard.

pin d8 to LED positive

gnd to LED negative

Arduino 2 (Mine is the uno)

Plug the bluetooth module into the breadboard opposite the nano setup.

5v to vcc on bluetooth module

gnd to gnd on bluetooth module

pin d10 to txd on bluetooth module

pin d11 to rxd on bluetooth module

Plug the led into the breadboard.

pin d8 to LED positive

gnd to LED negative

Skip the next step!

Step 3: Key Pin Wiring

If you do not have a button on your EN pin, in order to initialize AT mode, you will need to power the key pin with a refresh. The only change in the wiring is attaching pin 9 to your key pin. If you do have a button on your EN pin, skip this step!

Arduino 1 (Mine is the nano)
Plug the bluetooth module into the breadboard to the right of the nano.

5v to vcc on bluetooth module

gnd to gnd on bluetooth module

pin d9 to key pin on bluetooth module

pin d10 to txd on bluetooth module

pin d11 to rxd on bluetooth module

Bridge the push button across the middle of the breadboard to the right of the bluetooth module.

pin d2 to push button top right

5v to push button bottom left

take out resistor 1k ohm from push button bottom right to gnd

Plug the led into the breadboard.

pin d8 to LED positive

gnd to LED negative

Arduino 2 (Mine is the uno)

Plug the bluetooth module into the breadboard opposite the nano setup.

5v to vcc on bluetooth module

gnd to gnd on bluetooth module

pin d9 to key pin on bluetooth module

pin d10 to txd on bluetooth module

pin d11 to rxd on bluetooth module

Plug the led into the breadboard.

pin d8 to LED positive

gnd to LED negative

Step 4: Entering AT Mode

If you have a button on your HC-05

First, upload the code named BluetoothModuleMasterAndSlaveNoCode below to whatever arduino is connected to the bluetooth module you are currently configuring.

Next, unplug the power to your bluetooth module, hold the button down, and plug the power back in, then release the button. This should put the bluetooth module into AT mode causing it to blink on, and off every 2 seconds, as seen in the video above.

If you don't have a button on your HC-05

First, upload the code named MasterAndSlaveBluetoothNoCodeKeyPin below to whatever arduino is connected to the bluetooth module you are currently configuring.

This should cause your HC-05 to enter into AT mode when the arduino is refreshed, to do this... before you plug in the USB cable to the arduino, unplug the power pin which goes to the bluetooth module, this is the 5v pin. Now, plug the power pin in, and the HC-05 should be blinking on, and off every 2 seconds, signifying at mode.

If this doesn't work, please check out techbitar's tutorial, and then come back for the next step..

https://www.instructables.com/id/Modify-The-HC-05-Bluetooth-Module-Defaults-Using-A/

Step 5: Entering AT Commands, and Uploading the Code!

For The Slave Module (Whichever one you want to be the slave Hint: It doesn't matter!)

1. Connect to the computer to the port connected to the arduino which is connected to the bluetooth module you wish to configure.

2. Open Serial Monitor

3. Select 9600 as your baud rate, and both nl, and cr. If this config doesn't work, comment below, or go to one of the other links, and I will try to help.

4. Now, type AT, and hit enter. You should get a message saying OK, but if you get an error, try one more time until you seek help.

5. If that works, type AT+UART, and press enter to show your baud rate. It should be 38400, if it is, move on, if not, try the next step, then check again using this command. The baud rate must be the same for both modules, and this is often where things go wrong. If the next step doesn't fix it, leave a comment.

6. Next, type AT+ORGL, and press enter.

7. Finally, type AT+ADDR, and press enter. You should get an address like the one shown in the video 2016:3:250491, or something similar. Write this down, you will need it later.

8. Close the serial monitor, unplug, and re-plug in the arduino, and upload the code called B_SlaveLink below.

For The Master Module (The other one that will be controlling the link.)

1. Connect to the computer to the port connected to the arduino which is connected to the bluetooth module you wish to configure (not the same one as before, which is now the slave).

2. Follow Steps 2-6 above.

3. Now, type AT+BIND=2016,3,250491 obviously with your respective address to the slave. Note the commas instead of colons given by the slave module.

4. Alternatively, you may type AT+CMODE=1, and press enter. This will connect to all bluetooth modules within range, but does not work when you have more than two.

5. Close the serial monitor, unplug, and re-plug in the arduino, and upload the code called B-Master below.

6. Close all instances of the arduino IDE. This will counter any linkage, limiting the functioning of the program to only as long as it is initially plugged in.

7. The program should work now. If it doesn't, check your wiring, and look at the next step.

Step 6: Further Debugging, and Beyond

What should happen?

The modules should auto link when plugged in, and when the button is pressed, both LED's should blink.

What to do if it doesn't work!

1. Pressing the button doesn't do anything: Either your wiring is wrong, or the code got corrupted, and you should re-upload.

2. Pressing the button only causes the LED connected to it to turn on: Your HC-05's are not linked, so try some of the other tutorials below, and leave a comment.

3. The LED's are always off, or on: Your button is wired incorrectly.

3. My LED is still blinking slowly: Unplug for 30 seconds, and plug back in.

4. I am not getting any messages in the serial monitor: Check the comm port you are connected to, and that the type of arduino matches up with the one you are programming to. Make sure both nl, and cr are set, and that the baud rate is correct.

5. Any other issues, or suggestions: Post a comment.

Note: The LED's on the bluetooth modules will go out of sink after a while, this does not mean that the bluetooth connection has stopped.

Links To Other Tutorials...!

Help:

For Key Pin https://www.instructables.com/id/Modify-The-HC-05-B...

AT Commands http://phillipecantin.blogspot.com/2014/08/hc-05-b...

Obscure Models, and Configs http://www.martyncurrey.com/

Very Helpful! http://howtomechatronics.com/tutorials/arduino/how-to-configure-pair-two-hc-05-bluetooth-module-master-slave-commands/

More:

http://howtomechatronics.com/tutorials/arduino/how...

https://www.instructables.com/id/AT-command-mode-of...

Post your links, and projects below, and inform me if any of these should be removed.

Beyond!

1. Will this work with the HC-06? I believe so, post a comment if it does.

2. What now? Use my code as an example for your projects, and wait for my BB-8 control system!

https://www.instructables.com/id/Autonomous-BB-8-Drive-System/

3. Other? Post a comment!