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

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

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

Picture of 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.





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.


DaleE26 (author)2017-10-10

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....


misterxp (author)2017-06-06

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 !!

MikeA235 (author)misterxp2017-06-17

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.

misterxp (author)MikeA2352017-06-19

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!

RiccardoZ2 (author)2017-03-21

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

MikeA235 (author)RiccardoZ22017-06-17

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.

FranckF3 (author)RiccardoZ22017-05-07

In French : Moi aussi !!! +1

sarenum49 (author)2017-05-29

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

VijendraK (author)2017-03-06

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.

WilliamM397 (author)VijendraK2017-03-10

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

paolochiarlone (author)2016-07-20

Not the best idea to connect the I/O pins directly to 5V.
It might work, bu you might significantly shorten the life of the components.

The BT chip is *NOT* 5V tolerant:

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

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!

WannaDuino (author)WannaDuino2016-10-04

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.

WannaDuino (author)AndreasG342016-10-04

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)

just set the output pins on 3.3V on your UNO

and no worries then

No, unfortunately there is nothing you can do to make the I/O pins on the UNO to 3.3V. By design the pins are 5V.
And again, powering something at 5V if it is designed for 3.3V is a very bad idea....

So you either use a couple of resistors (if you don't care about efficiency) or use a DC-DC converter. That is the best way.

guido199 (author)2016-12-28

can you connect this txd/rxd/gnd to a JR plug from an ESC to make your project bluetooth controlled?

RushikeshP (author)2015-09-28

What if I connect arduino (having no sketch in it) to hc06 by vcc-5v, gnd-gnd, tx rx crossed and pair with hc 06. then go to devices and printer and find the no. of com port of hc06 And then in arduino ide simply change the com port to hc06's com port. will this work ??? Will I would be able to upload sketch???

MichaelT150 (author)RushikeshP2015-12-27

Yes, if you press Reset on the Arduino at the right time, to initiate the bootloader which will listen for the new program being sent by the IDE.

AkiS6 (author)MichaelT1502016-11-14

It depends about bootloader, but bootloader is likely trying to start the sketch and as there is nothing it ends up starting bootloader again. Thus in special case of no sketch flashing should work without reset.

I did update my arduino nano bootloader to run also in soft reset thus I can flash whit hc06 also if I have sketch ( sketch has to do soft reset at right time ).

luizabbm (author)2016-11-01


JphiD (author)2016-04-19

Hello, It is easy to send data from Android to Arduino with HC-06, but can we send data from the arduino to Android? I have been trying and I receive a constant stream of data from HC-06 about 5 times per second, but no data included in it.

Any hint please?

WannaDuino (author)JphiD2016-10-04

HC-6 is only slave drve

use a HC-05 that can send and recieve

WannaDuino made it! (author)2016-10-04

verry cool thanx i made it, so i can use it for another project of Terry look here--

pleace VOTE on him. he helpt me and he also revers to you,(but i already found you, but that dous not matter. I AM HAPPY WITH BOTH OF YOUR IBLES AND HELP

CalebR12 (author)2016-07-01

This also works on 3.3V..

dimitrakis1992 (author)2016-06-17

Hello to everyone.I have make a bleutooth robot which i can control it via android(tablet) and i have a problem with the code.I want from the robot to stop when connection lost or bluetooth disconnected.Now when the connection lost the robot go ahead and falls on the objects.How to add this line on the code?Can you help me please?The STATE pin of HC-05 when is HIGH is connected and when is LOW is disconnected.I put this on my code but it doesn't stop.Thank you for your time

The bluetooth that i use is HC-05

My code:

#include <Servo.h>

Servo SERVO_1; // Initialize Servo1

// Motor Control Variables
int PWM1 = 9;
int ENABLE1 = 8;
int PWM2 = 5;
int ENABLE2 = 7;
int PWM3 = 3;
int ENABLE3 = 4;
int PWM4 = 6;
int ENABLE4 = 12;
int STATE=2;

void setup() {
pinMode(ENABLE1, OUTPUT); //Δήλωση όλων των μεταβλητών ως έξοδος
pinMode(ENABLE2, OUTPUT); //Δήλωση όλων των μεταβλητών ως έξοδος
pinMode(ENABLE3, OUTPUT); //Δήλωση όλων των μεταβλητών ως έξοδος
pinMode(ENABLE4, OUTPUT); //Δήλωση όλων των μεταβλητών ως έξοδος
pinMode(STATE, INPUT);

void loop() {

if(digitalRead(STATE)== HIGH)

// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
int incomingByte =;
// action depending on the instruction
// as well as sending a confirmation back to the app
switch (incomingByte) {
case 'F':
Serial.println("Going forward");
case 'L' : // Case 'L' is received,
SERVO_1.write (180); // Στρίψε Αριστερά.
case 'N':
Serial.println("Turning right");
case 'M':
Serial.println("Turning left");
case 'O' : // Case 'L' is received,
SERVO_1.write (0); // Στρίψε Αριστερά.
case 'B':
Serial.println("Going forward");
case 'P':
SERVO_1.write(90); // Στρίψε Αριστερά.
case 'S':
// if nothing matches, do nothing

void moveForward() {
// turn the driving motor on to go forwards at set speed
digitalWrite(ENABLE1, HIGH);
digitalWrite(ENABLE2, HIGH);
digitalWrite(ENABLE3, HIGH);
digitalWrite(ENABLE4, HIGH);
analogWrite(PWM1, 255);
analogWrite(PWM2, 255);
analogWrite(PWM3, 255);
analogWrite(PWM4, 255);


void moveBackward() {
// turn the driving motor on to go backwards at set speed
digitalWrite(ENABLE1, LOW);
digitalWrite(ENABLE2, LOW);
digitalWrite(ENABLE3, LOW);
digitalWrite(ENABLE4, LOW);
analogWrite(PWM1, 255);
analogWrite(PWM2, 255);
analogWrite(PWM3, 255);
analogWrite(PWM4, 255);
void turnright() {
digitalWrite(ENABLE1, HIGH);
digitalWrite(ENABLE2, HIGH);
digitalWrite(ENABLE3, LOW);
digitalWrite(ENABLE4, LOW);
analogWrite(PWM1, 255);
analogWrite(PWM2, 255);
analogWrite(PWM3, 255);
analogWrite(PWM4, 255);

void turnleft() {
digitalWrite(ENABLE1, LOW);
digitalWrite(ENABLE2, LOW);
digitalWrite(ENABLE3, HIGH);
digitalWrite(ENABLE4, HIGH);
analogWrite(PWM1, 255);
analogWrite(PWM2, 255);
analogWrite(PWM3, 255);
analogWrite(PWM4, 255);
void moveNone() {
// turn the driving motor off
digitalWrite(ENABLE1, 0);
digitalWrite(ENABLE2, 0);
digitalWrite(ENABLE3, 0);
digitalWrite(ENABLE4, 0);
analogWrite(PWM1, 0);
analogWrite(PWM2, 0);
analogWrite(PWM3, 0);
analogWrite(PWM4, 0);

mido990 (author)2016-05-25

hello i am trying to send data from arduino to android application via bluetooth but i want to let it send data automatically when something happen any help??

JamesW230 (author)2016-05-02

Do you know a way I can facilitate the communication to bluetooth module from PC if I am running Ubuntu linux? Teraterm is windows only it appears...

JphiD (author)2016-04-18

your "in this tutorial" link gives a 503 error at the moment

warrickwars (author)2016-04-05

I've seen in some places that the tx of the arduino uno outputs 5V, and the BT board/HC-06 Rx is rated 3.3V, connecting uno tx to HC-06 Rx will damage the board, is that so?

Moreover, I've seen potential dividers to get 3.3V from the uno Tx to HC-06 Rx. Wanting to know if in your case without the potential divider, will it damage the HC-06?

TheOHFiles (author)2016-03-28

I couldn't get my hc-06 to stay connected. Every time I manage to setup it up using the wizard it instantly disconnects. I'm using a macbook.If I'm using a mac, which program can I use to transmit the commands?

jmscnny. (author)2016-03-26

Thank you for that. I was looking for a quick and easy intro to the HC-06, and this was perfect.

NavyaG1 (author)2016-03-08

I want know How HC-05 acts as a bridge for laptop & arduino?

How BT module receives commands from laptop & transfer them to arduino?

DavidB552 (author)2016-03-02

hey can anyone give me two tips on the code

i want to know how to make it so I only need one button to toggle it on and off

and also how to make that as long as I hold the button down its on but when I take my finger off the button it turns off ?

EvyatarB (author)2016-01-24

can i use a hc 06 bluethoot module to transfer music data?

i mean i would like to use the moudle and connect it as a speaker bt

ernestc1 (author)2015-10-07

can i use laptop bluetooth module??

JeffM26 (author)2015-08-14

Thanks Yhtomitsy. This worked well and the instructions were clear!

returner (author)2015-01-21

Hi, i have a question and i hope you guys can help me with this. how does the arduino actually know actually know which data it is going to send or receive? in which part of the code does it do that? i want to make two arduinos one having a HC05 as a master sending data over to a HC06 slave on two different laptops. I hope you can answer me.

zootalaws (author)returner2015-04-16

Have a look at this:

If you get stuck, send me a message.

DesmondC1 (author)zootalaws2015-04-21

Hey, my bluetooth have a pin of 5V instead of Vcc, should i connect it to 3.3V or 5V??

zootalaws (author)DesmondC12015-04-21

if your BT is 5v, you should use 5v. Which Arduino are you using?

zootalaws (author)returner2015-04-15

it's much more complex than this simple sketch, needing you to go into command mode and programming the BT modules to initiate a link with each other.

I will dig out the instructions and send you the link.

yhtomitsy (author)returner2015-02-20

Sending of data is done via the Serial.println(), Serial.print() and Serial.write() commands and receiving data is done via command, just like when dealing with the normal RX/TX serial connection to the computer. This is because the HC-06 /HC-05 acts as a bluetooth serial device.

I am not sure if you can do the type of connection you have just described.

zootalaws (author)yhtomitsy2015-04-15

of course you can.

yusefHD (author)2015-04-17

Awesome Tutorial!

I suppose in addition to this, here's a comparison chart of some popular bluetooth modules on the market.

james.heires (author)2015-04-13

Thanks for the excellent BT example sketches - both worked flawlessly from my PC (not yet from my iPhone). I understand that this module ships with BT v2.1 and that iPhone does not support this version. Do you know how to flash the module so that v4.0 BLE (or whatever version iPhone supports) can be loaded?

zootalaws (author)james.heires2015-04-15

I'm interested in what app you are going to use on your iPhone. AFAIK Apple restrict any use of the BT interface for terminal comms

About This Instructable




Bio: 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 ... More »
More by yhtomitsy:RFduino - Sending and Receiving Data Via BLE Arduino redback simple serverConfiguring xBee in API mode
Add instructable to: