loading

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!

<p>Nice tutorial.<br>Johncoffee's remark was the key...<br>set ROLE=1 for the master (AT+ROLE=1) and ROLE=0 for the slave</p><p>I </p>
<p>I had to set ROLE=1 for the master (AT+ROLE=1) since the master stayed at ROLE=0 (=slave). Afterwards it worked like a charm! Thanks a lot!!!</p>
<p>Very usefull...<br>Thank you</p>
<p>I want this code in word format, can you please sent me??</p><p>Given code is not opening properly.</p><p>please help me...</p>
<p>hi can u tell the code to connect different sensors on master code and get different outputs on slave code?</p>
<p>Hello Riftliger... Is there anyway that we could actually get into the AT Command mode of the HC-05 pragmatically without holding the button? I'm having a project that which requires every startup of the Bluetooth it requires a brand new 4 pin numeric password. Thanks in advance.</p>
<p>hii....</p><p>i do as it you told...at master side only LED blinks...but LED on slave side not blinks afrer pressing push button..plz guide ..what is the problem ?</p>
<p>is the push button necessary??? </p>
<p>i get something like this :xxxx&yuml;x...........................??</p>
<p>i want to control multiple doors with bluetooth , plz guide me how can i do this </p>
<p>i push the enter after typing AT and nothing happen. what should i do please help me :(</p>
<p>Great tutorial,</p><p>I have one question. How many slave Hc-06, or Hc-05 can a master Hc-05 connect to, and send/receive data to, and from?</p><p>Thank you,</p><p>Roland</p>
<p style="margin-left: 20.0px;">Hi, great tutorial. I have a problem getting my HC-05 to flash rapidly so it can be linked to either my laptop or tablet. I have used several tutorials and was able to connect it up to a arduino UNO and change settings on the bluetooth device in the serial monitor. When I unplug the key wire the led goes off. I unplug the power to bluetooth - wait - then plug it back in leaving key wire unplugged but the led does not come on and my computer can't find it. Help please. My bluetooth settings are: Name: HC-05, Version: 2.0-20100601, Role: 0 slave, </p><p style="margin-left: 20.0px;">ADDR: 2016:1:64004, UART: 115200, </p>
<p>God, at the end some tutorial which works! </p>
<p>Great tutorial.Helped me a lot..!!! Thanks</p>
<p>Hello, the code worked perfectly for the slave bluetooth but when I try to do the same for the master it doesn't enter AT mode. I followed all the steps and when i'm pressing AT at the serial monitor it doesn't do anything. Can you help?</p>
<p>Yes, in order to help, I need to know what model, and type your master module is, and what arduino board you are running it on. Make sure your wiring is correct also. There are a few things that could be wrong.</p><p>1. It isn't wired correctly (i.e. make sure it is the same as the slave... Check the rx, and tx pins)</p><p>If this is all correct, try changing the position of the rx, and tx pins in the code, and in your wiring.</p><p>2. It isn't in AT mode</p><p>3. There is something wrong with the baud rates.</p><p>Try changing these around in the code, as well.</p>
I'm using 2 HC-05 ZS-040 Bluetooth modules and 2 arduino micro. I switched the Bluetooth modules between them and now the master is the one that works. So I changed the other arduino micro with an arduino uno and I still have the same problem. Both modules enter AT mode because the led is blinking every 2 seconds. The wiring and the baud rates are correct. This is what I get:
<p>Interesting. Like I say in my post, this is a hard process. I have a couple of ideas, and will continue to try and support you, but also try other tutorials that I have linked. First of all, you could simply configure both modules with the one arduino, but I doubt the code would work if one of your setups is not working. But try this, and just upload the master, or slave code to the arduino uno, don't configure the module on this device. Another thing I would try is switching out aspects of one setup to the other, like there might be a faulty usb cable... . </p>
<p>I used the AT+CMODE=1 in serial monitor and they linked. it works now but i have no idea what happened. I didn't change anything. Do you think it's possible to connect an HC-06 instead the HC-05 using that command?</p>
<p>AT+CMODE=1 will connect to all nearby bluetooth modules. It would probably connect to an HC-06. So was the connection by address not working?</p>
<p>No, in the beginning i thought it was the wiring but I changed it multiple times. Then I changed the arduino board just in case there was something wrong with that, but in the serial monitor i couldn't get a reply again. So I programmed the slave bluetooth with the arduino board that works correcly and then i swiched it with the master and I programmed it also. They didn't link with the AT+BIND=..... command so I tried the AT+MODE=1 and it worked. I also tried to connect the HC-06 but it doesn't work, maybe it needs some changes in code?</p>
<p>Ya, I haven't worked with the HC-06 a ton, but http://www.martyncurrey.com/ has a good tutorial. Just skip his wiring, and it should work.</p>
<p>Ok, thanks a lot! Your project is very helpful, I struggled for days trying to figure out how to connect them. Yours is the only one that actually works. I'll try to connect the HC-06 too, thanks for the link.</p>
<p>It's great, thank you.</p><p>schk.</p>
Awesome!!! This is exactly what I was looking for. Thank you so much for the instructable!

About This Instructable

25,026views

137favorites

License:

More by Riftliger:Bacteriophage D20 Stand Mk1 2 Pumpkin Bluetooth LED Activation by Motion Sensing Cardboard Ball 
Add instructable to: