Add Bluetooth to Your Arduino Project - Arduino+HC-06

404,115

165

77

Published

Introduction: Add Bluetooth to Your Arduino Project - Arduino+HC-06

About: I am an electrical engineer and an Arduino and electronics enthusiasts. I believe working with electricity should be fun as well as beneficial to engineers and the world at large. Twitter handle: @arduinoha...

Wouldn't you love to switch on and off the lights in your house without having to raise a finger? (well, technically you would have to raise a finger or two, but you get the jist of the story). The good news is that you can. All you needs is an arduino, HC-06 bluetooth module, some relays and a little electrical know-how.

In this tutorial, however, i am going to show you how to setup the HC-06, send some data to the arduino and receive and echo and control an LED via bluetooth. At least this should get you started, before you get to control the whole grid with your HC-06...just kidding.

Step 1: Setup

Setting up the HC-06 is as easy as ABC. All you need to know is the pin configuration. The HC-06 has 6 pins: wakeup, VCC, GND, TXD, RXD and State. Right now I will only deal with 4 pins, which are VCC, GND, TXD and RXD.

Here is how you should connect the Bluetooth module to your Arduino.
HC-06>>>Arduino

VCC>>>>3.3v

GND>>>>GND

TXD>>>>RXD

RXD>>>>TXD

The HC-06 acts as a serial port through which you can send and receive data. So using a serial terminal or a Bluetooth customized application on your computer or phone, you can control and monitor your project. I used Teraterm as the serial terminal.
Before, uploading the code to the Arduino, disconnect the HC-06 module, since it shares the tx/rx pins and will interfere with the upload. Connect it back once the code has been uploaded successfully.

Step 2: Echo Code

This code enables you to send a string to the Arduino via Bluetooth and get an echo back on your serial monitor.

NB: if you are using an arduino mega change this line of code while(Serial.available()); to while(Serial.available()>0); otherwise the code will not work

Step 3: LED Code

This code allows you to switch on and off an LED using by sending a command to the Arduino via Bluetooth.

Step 4: Pairing HC-06 to the Computer

Pair the HC-06 with your computer or any other Bluetooth device you have as shown in the video

NB: In the video I say that you should connect your serial terminal program (teraterm) to the INCOMING com port. This is not right. The correct way should be connecting your serial terminal program to the OUTGOING com port.

Step 5:

Once the module is paired. Open Teraterm, or any other serial terminal program you have. Select the serial port that corresponds to the HC-06 (I have explained how to identify that port in the video).

Once you successfully connect to the HC-06 serial port you will be able to send strings to your Arduino and get an echo back. If you have uploaded the second code, you will be able to switch on and off and LED by sending “n” and “f” respectively.

Step 6: Echo Example

Step 7: LED Example

Step 8:

There are many applications of the HC-06. Learn more about it in my next post as I show you how to control an Arduino robot arm via bluetooth. For a more detailed tutorial on the HC-06 visit this link.

Share

Recommendations

  • Casting Contest

    Casting Contest
  • Woodworking Contest

    Woodworking Contest
  • Make it Move Contest

    Make it Move Contest
user

We have a be nice policy.
Please be positive and constructive.

Tips

2 Questions

0

What about the code of 8 LED !!!!!

What about it !!!!!!

0

What about the code of 8 LED !!!!!

77 Comments

I use mega 2560 but it doesnt work and has alot of errors ... how can i fix it? Please recommend me.

1 reply

We can't debug your code if we don't have your code, and we can't solve your errors if we don't know what they are.

Thanks for the great and useful tutorial. I followed instructions and it worked first time. Only got a bit stuck on tera term but found some info on the web. I had bought an HC-05 and wanted to test it quickly and your project was perfect and easy to follow for a beginner like me. Also gave me a chance to learn about Tetra term! Thanks !!

3 replies

There are many bluetooth terminal apps available for Android too. I was also successful the first time using one of these apps. Of course I was stuck on forgetting to disconnect the HC-06 (if using the standard Arduino Tx/Rx pins) while trying to upload. Oh well.

If you're still stuck on that, you can use SoftwareSerial to use different pins for the serial connection to the HC-06 which will leave your hardware serial pins open for communication with the computer.

Yes I see the web is full of interesting apps for Arduino and, in particular bluetooth and/ or bots

Sometimes feel like a kid in a candy shop. I Want to dive in the deep end but better to start with basics first!

Question, once a HC-06 is connected to an arduino you cannot use USB to upload an updated sketch any longer right? If a simple power interrupt switch was added to the vcc between the Arduino and the HC-06 would that enable the USB again? or must all four lines me disconnected? I have a project I added the HC-06 to but I have to keep disassembling it to temp remove the BT just to push a new sketch up :( wondering if a simple switch could be added to simplify the issue....

Thanx

1 reply

I had the exact same issue and the thing that causes the trouble is using pin 0 and 1 . You can use the SoftWareSerial library to enable the usesage of all the pins on your arduino for your bluetooth module. For example insted of using 0 and 1 i use 10 and 11 now for the RX and TX and now it works fine! Hope i helped you with this

When i write something on the bluetooth terminal it answers me back with random letters

2 replies

Your baud rate on your Serial Monitor doesn't match the program setting or the default. Change it in the bottom right corner of the Serial Monitor screen.

In French : Moi aussi !!! +1

I downloaded your attached ino file and compiled code successfully but unable to upload to my uno board...
Can you plz help me why this is happening? Failed to upload code to uno board.

1 reply

You need to unplug the buetooth device before uploading the code. The arduiono Uno only has one serial port. after uploading the code you can then reconnec the buletooth

how many ampere can the Bluetooth able to receive?

am i missing something then?
i have on the UNO a 5v and a 3.3v output (tose i mean.
but i bigin to understand something here.( you mean the DIGITAL PINS stay 5V.
or am i go down even more now hahahahaha
watch my name eeh. a WannaDuino
thanx for the quick response, i wil not put it ON before i know for sure how to give it GOOD voltage.

With Regards WannaDuino

WannaDuino,
well don't get confused with the power input of the Arduino Uno (R3) which is 3.3V and the output pins (GPIO) which are 5V.
You can power the ATmega328 with 3.3V but you cannot output 3.3V on the GPIO pins. This is valid 100% for the original Arduino Uno R3.
However, there are Arduino clones with 3.3V GPIO out there, you might have one of them.
Hope this help!
Regards,
Paolo

tasheet info look

Operation up to 5.6V is permissible without damage and without the output voltage rising sufficiently to damage the rest
of BlueCore4-External, but output regulation and other specifications are no longer guaranteed at input voltages in
excess of 4.2V.

Yeah, the hc-06 module itself is not 5V compatible, but the module is often placed on a voltage regulator (the blue part), so it perfectly works with 5V.

pleace make a picture and point it out.
this is like i see, an issue for a lot of people, if 5v is good or bad.for LONG time of use.
the datasheet hmmmm jeah what must i say (to mutch infoooo)