loading

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.

<p>When i write something on the bluetooth terminal it answers me back with random letters</p>
<p>In French : Moi aussi !!! +1</p>
I downloaded your attached ino file and compiled code successfully but unable to upload to my uno board...<br>Can you plz help me why this is happening? Failed to upload code to uno board.
<p>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</p>
<p>Not the best idea to connect the I/O pins directly to 5V.<br>It might work, bu you might significantly shorten the life of the components.<br><br></p><p>The BT chip is *NOT* 5V tolerant:</p><p><a href="https://cdn.sparkfun.com/datasheets/Wireless/Bluetooth/CSR-BC417-datasheet.pdf" rel="nofollow">https://cdn.sparkfun.com/datasheets/Wireless/Bluet...</a></p>
<p>how many ampere can the Bluetooth able to receive?</p>
am i missing something then?<br>i have on the UNO a 5v and a 3.3v output (tose i mean.<br>but i bigin to understand something here.( you mean the DIGITAL PINS stay 5V. <br>or am i go down even more now hahahahaha<br>watch my name eeh. a WannaDuino<br>thanx for the quick response, i wil not put it ON before i know for sure how to give it GOOD voltage.<br><br>With Regards WannaDuino
<p>WannaDuino,<br>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.<br>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.<br>However, there are Arduino clones with 3.3V GPIO out there, you might have one of them.<br>Hope this help!<br>Regards,<br>Paolo<br></p>
tasheet info look <br><br>Operation up to 5.6V is permissible without damage and without the output voltage rising sufficiently to damage the rest<br>of BlueCore4-External, but output regulation and other specifications are no longer guaranteed at input voltages in<br>excess of 4.2V.
<p>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.</p>
pleace make a picture and point it out.<br>this is like i see, an issue for a lot of people, if 5v is good or bad.for LONG time of use.<br>the datasheet hmmmm jeah what must i say (to mutch infoooo)<br>
<p>just set the output pins on 3.3V on your UNO</p><p>and no worries then</p>
<p>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.<br>And again, powering something at 5V if it is designed for 3.3V is a very bad idea....</p><p>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.</p>
<p>can you connect this txd/rxd/gnd to a JR plug from an ESC to make your project bluetooth controlled?</p>
<p>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???</p>
<p>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.</p>
<p>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.</p><p>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 ). </p><p>https://github.com/asalminen/arduinobootloader</p>
<p>LOVE YOUUUU MARrY MEEEEEE</p>
<p>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. </p><p>Any hint please?</p>
<p>HC-6 is only slave drve</p><p>use a HC-05 that can send and recieve</p>
<p>verry cool thanx i made it, so i can use it for another project of Terry look here--</p><p><a href="https://www.instructables.com/id/8x8-Matrix-Display-With-BT/" rel="nofollow">https://www.instructables.com/id/8x8-Matrix-Display...</a></p><p>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</p>
<p>This also works on 3.3V..</p>
<p>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</p><p><br>The bluetooth that i use is HC-05<br><br>My code:<br><br>#include &lt;Servo.h&gt;<br><br>Servo SERVO_1; // Initialize Servo1<br><br>// Motor Control Variables<br>int PWM1 = 9;<br>int ENABLE1 = 8;<br>int PWM2 = 5;<br>int ENABLE2 = 7;<br>int PWM3 = 3;<br>int ENABLE3 = 4;<br>int PWM4 = 6;<br>int ENABLE4 = 12;<br>int STATE=2;<br><br><br>void setup() {<br> SERVO_1.attach(10);<br> Serial.begin(9600);<br> pinMode(ENABLE1, OUTPUT); //&Delta;ή&lambda;&omega;&sigma;&eta; ό&lambda;&omega;&nu; &tau;&omega;&nu; &mu;&epsilon;&tau;&alpha;&beta;&lambda;&eta;&tau;ώ&nu; &omega;&sigmaf; έ&xi;&omicron;&delta;&omicron;&sigmaf;<br> pinMode(ENABLE2, OUTPUT); //&Delta;ή&lambda;&omega;&sigma;&eta; ό&lambda;&omega;&nu; &tau;&omega;&nu; &mu;&epsilon;&tau;&alpha;&beta;&lambda;&eta;&tau;ώ&nu; &omega;&sigmaf; έ&xi;&omicron;&delta;&omicron;&sigmaf;<br> pinMode(ENABLE3, OUTPUT); //&Delta;ή&lambda;&omega;&sigma;&eta; ό&lambda;&omega;&nu; &tau;&omega;&nu; &mu;&epsilon;&tau;&alpha;&beta;&lambda;&eta;&tau;ώ&nu; &omega;&sigmaf; έ&xi;&omicron;&delta;&omicron;&sigmaf;<br> pinMode(ENABLE4, OUTPUT); //&Delta;ή&lambda;&omega;&sigma;&eta; ό&lambda;&omega;&nu; &tau;&omega;&nu; &mu;&epsilon;&tau;&alpha;&beta;&lambda;&eta;&tau;ώ&nu; &omega;&sigmaf; έ&xi;&omicron;&delta;&omicron;&sigmaf;<br> pinMode(STATE, INPUT);<br>}<br><br>void loop() {<br><br> if(digitalRead(STATE)== HIGH)<br><br> // see if there's incoming serial data:<br> if (Serial.available() &gt; 0) {<br> // read the oldest byte in the serial buffer:<br> int incomingByte = Serial.read();<br> // action depending on the instruction<br> // as well as sending a confirmation back to the app<br> switch (incomingByte) {<br> case 'F':<br> moveForward();<br> Serial.println(&quot;Going forward&quot;);<br> break;<br> case 'L' : // Case 'L' is received,<br> SERVO_1.write (180); // &Sigma;&tau;&rho;ί&psi;&epsilon; &Alpha;&rho;&iota;&sigma;&tau;&epsilon;&rho;ά.<br> SERVO_1.attach(10);<br> break;<br> case 'N':<br> turnright();<br> Serial.println(&quot;Turning right&quot;);<br> break;<br> case 'M':<br> turnleft();<br> Serial.println(&quot;Turning left&quot;);<br> break;<br> case 'O' : // Case 'L' is received,<br> SERVO_1.write (0); // &Sigma;&tau;&rho;ί&psi;&epsilon; &Alpha;&rho;&iota;&sigma;&tau;&epsilon;&rho;ά.<br> SERVO_1.attach(10);<br> break;<br> case 'B':<br> moveBackward();<br> Serial.println(&quot;Going forward&quot;);<br> break;<br> case 'P':<br> SERVO_1.write(90); // &Sigma;&tau;&rho;ί&psi;&epsilon; &Alpha;&rho;&iota;&sigma;&tau;&epsilon;&rho;ά.<br> SERVO_1.attach(10);<br> break;<br> case 'S':<br> moveNone();<br> Serial.println(&quot;Stopping&quot;);<br> break;<br> default:<br> // if nothing matches, do nothing<br> break;<br> }<br> }<br>}<br><br>void moveForward() {<br> // turn the driving motor on to go forwards at set speed<br> digitalWrite(ENABLE1, HIGH);<br> digitalWrite(ENABLE2, HIGH);<br> digitalWrite(ENABLE3, HIGH);<br> digitalWrite(ENABLE4, HIGH);<br> analogWrite(PWM1, 255);<br> analogWrite(PWM2, 255);<br> analogWrite(PWM3, 255);<br> analogWrite(PWM4, 255);<br><br>}<br><br>void moveBackward() {<br> // turn the driving motor on to go backwards at set speed<br> digitalWrite(ENABLE1, LOW);<br> digitalWrite(ENABLE2, LOW);<br> digitalWrite(ENABLE3, LOW);<br> digitalWrite(ENABLE4, LOW);<br> analogWrite(PWM1, 255);<br> analogWrite(PWM2, 255);<br> analogWrite(PWM3, 255);<br> analogWrite(PWM4, 255);<br>}<br>void turnright() {<br> digitalWrite(ENABLE1, HIGH);<br> digitalWrite(ENABLE2, HIGH);<br> digitalWrite(ENABLE3, LOW);<br> digitalWrite(ENABLE4, LOW);<br> analogWrite(PWM1, 255);<br> analogWrite(PWM2, 255);<br> analogWrite(PWM3, 255);<br> analogWrite(PWM4, 255);<br>}<br><br>void turnleft() {<br> digitalWrite(ENABLE1, LOW);<br> digitalWrite(ENABLE2, LOW);<br> digitalWrite(ENABLE3, HIGH);<br> digitalWrite(ENABLE4, HIGH);<br> analogWrite(PWM1, 255);<br> analogWrite(PWM2, 255);<br> analogWrite(PWM3, 255);<br> analogWrite(PWM4, 255);<br>}<br>void moveNone() {<br> // turn the driving motor off<br> digitalWrite(ENABLE1, 0);<br> digitalWrite(ENABLE2, 0);<br> digitalWrite(ENABLE3, 0);<br> digitalWrite(ENABLE4, 0);<br> analogWrite(PWM1, 0);<br> analogWrite(PWM2, 0);<br> analogWrite(PWM3, 0);<br> analogWrite(PWM4, 0);<br> SERVO_1.detach();<br>}</p>
<p>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??</p>
<p>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...</p>
<p>your &quot;in this tutorial&quot; link gives a 503 error at the moment</p>
<p>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?</p><p>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?</p>
<p>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?</p>
<p>Thank you for that. I was looking for a quick and easy intro to the HC-06, and this was perfect.</p>
<p>I want know How HC-05 acts as a bridge for laptop &amp; arduino? </p><p>How BT module receives commands from laptop &amp; transfer them to arduino?</p>
<p>hey can anyone give me two tips on the code <br><br>i want to know how to make it so I only need one button to toggle it on and off <br><br><br>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 ?</p>
<p>can i use a hc 06 bluethoot module to transfer music data?</p><p>i mean i would like to use the moudle and connect it as a speaker bt</p>
<p>can i use laptop bluetooth module??</p>
<p>Thanks Yhtomitsy. This worked well and the instructions were clear! </p>
<p>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.</p>
<p>Have a look at this: <a href="https://www.instructables.com/id/BlueTooth-Link-with-auto-detect-connect/" rel="nofollow">https://www.instructables.com/id/BlueTooth-Link-wit...</a></p><p>If you get stuck, send me a message.</p>
<p>Hey, my bluetooth have a pin of 5V instead of Vcc, should i connect it to 3.3V or 5V??</p>
<p>if your BT is 5v, you should use 5v. Which Arduino are you using?</p>
<p>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.</p><p>I will dig out the instructions and send you the link.</p>
<p>Sending of data is done via the Serial.println(), Serial.print() and Serial.write() commands and receiving data is done via Serial.read() 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. </p><p>I am not sure if you can do the type of connection you have just described. </p>
<p>of course you can.</p>
<p>Awesome Tutorial! </p><p>I suppose in addition to this, here's a comparison chart of some popular bluetooth modules on the market.</p><p>http://blog.upverter.com/post/102541328427/bluetooth-module</p>
<p>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? </p>
<p>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</p>
zoot,<br>I've downloaded JBWave, but don't have an iPhone-compatible BT module (BLE 4.0) yet (it's on order).<br>I understand that JBWave will act as a mobile BT terminal, with which I can test my Arduino circuit and sketch.<br>Long term, I may have to hire an iPhone app developer to create an app that is designed for my particular domain.
<p>I just connected to a BT2.1 device from my iMac and my Macbook, both of which have BT4.0, while paired with my iPod, which is BT4.0. So it isn't a limitation of BT4.0 - which is backwards compatible right back to BT1.0.</p><p>From my pairing details: The TINY CNC is an HC-05 made by GoMCU.</p><p>Devices (Paired, Configured, etc):</p><p> TINY CNC:</p><p> Address:xx-xx-xx-xx-xx</p><p> Major Type:Unknown</p><p> Minor Type:Unclassified</p><p> Services:Dev B</p><p> Paired:Yes</p><p> Configured:Yes</p><p> Connected:Yes</p><p> Manufacturer:Cambridge Silicon Radio (0x4, 0x1735)</p><p> Class of Device:0x1F 0x00 0x1F00</p><p> AFH:On</p><p> AFH Map:FFFFFFFFFFFFFFFFFF7F</p><p> RSSI:-65</p><p> Role:Master</p><p> EDR Supported:Yes</p><p> eSCO Supported:Yes</p><p> SSP Supported:No</p><p> Mike&rsquo;s iPod:</p><p> Address:xx-xx-xx-xx-xx</p><p> Major Type:Portable</p><p> Minor Type:Audio</p><p> Services:Handsfree Gateway, AVRCP Device, Audio Source, MAP MAS-iOS, Wireless iAP, AVRCP Device</p><p> Paired:Yes</p><p> Configured:Yes</p><p> Connected:No</p><p> Manufacturer:Broadcom (0x7, 0x410D)</p><p> Firmware Version:0x0810</p><p> Vendor ID:0x05AC</p><p> Product ID:0x12AA</p><p> Class of Device:0x04 0x07 0x6A041C</p><p> EDR Supported:Yes</p><p> eSCO Supported:Yes</p><p> SSP Supported:Yes</p>
<p>zoot, </p><p>Thanks for the additional details. Did you connect using a terminal program (e.g., putty, tera term, etc) on your Mac?</p><p>How did you retrieve all of the above details from your HC-05? Is there an AT command which returns this kind of info?</p><p>Last night I was able to use my FTDI USB-to-UART and Arduino IDE serial monitor to query my HC-06 module using AT commands. I learned that my device was shipped with &quot;Linvor V1.8&quot; - does this equate to some bluetooth standard?</p><p>After a short/incomplete search, I also learned that Firefox browser has a plug-in that enables communication to a bluetooth serial device. If this could be configured to talk to my HC-06 over bluetooth, it would make for a platform-independent solution (at least not dependent upon hardware platforms)...more to come as I learn more.</p>
<p>Linvor is the company that made the original 'HC' model of BT serial device. It has become a generic name for BT devices from China.</p><p>and yes, I can use Coolterm, Arduino serial monitor, any comms program can talk with BT devices from the Mac.</p><p>But, Apple have made it impossible on any iOS device without the developer paying for the privilege, which is why there aren't any BT2.1 devices - BT4.0 devices aren't subject to the restriction.</p><p>Who knows why - stupid Apple.</p>
<p>looks like I was misinformed. This will work.</p><p>Laird Serial by Laird Technologies</p><p>https://appsto.re/gb/0YBIN.i</p>
This is a bluetooth classic module and cannot be converted into a BLE module through firmware change. I would suggest you purchase an RFduino BLE module or any other open-source BLE modules that are available in the market and use them. There is a simple tutorial i have on the RFduino. You can check it out here: https://www.instructables.com/id/RFduino-Sending-and-Receiving-Data-Via-BLE/<br><br>Thanks

About This Instructable

352,937views

153favorites

License:

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 server Configuring xBee in API mode 
Add instructable to: