loading

Hello Every body , This is my first artical on Instructable.com , I'm so happy for that , and I will start by How to connect arduino with bluetooth , I suffered a lot of problems when I try to connect it as the website and instructable artical did , So i decided To share my experience with You

The bluetooth module I will use today is HC-05 which is so familiar and cheap ,

Most tutorial on The website Connect the bluetooth with default Rx and Tx on the arduino Board , I faced a lot of problem and bluetooth didn't work will .

But arduino  support something Called Software Serial , which allow You to change any arduino board pin to serial pin 

http://arduino.cc/en/Reference/SoftwareSerial

so After reading this article you will be able to:

1) Connect arduino Board with PC By Bluetooth , to send and receive data .
2)Connect arduino Board with Any android device .


so you can send your information , Like Sensors reading , from arduino to PC Or android device , and you can build your Home automation system by bluetooth , and controlling your robot wirelessly


 

Step 1: Material and connection

you need to do this experiment :

1) Arduino Board " I used Arduino Uno ".
2) Bluetooth module HC-05.
3)Solderless jumper.
4)Bread Board .
5)Battery 9V "Optional".

The connction between  Arduino and bluetooth is like the schematic above 





well done , thanks for this tutorial <br>please do not forget to post this tutorial in your blog in Arabic :)
<p>Thanks! This was really helpful to dip my toes in to working with the HC-05</p>
<p>I have an Arduino Due and a HC-05 HM-10 and nothing I've seen works.</p>
<p>hi, i am sereyen and i'd like to ask you about the bluetooth module HC-05 as i have met many troubles while working with it. i really don't know where is the error i've connected the VCC to 5v , the GND to GND and the RX of module to 18 pin and the TX to 19 pin and i've written the same code as you've written but, the bluetooth couldn't read any data and i am asking for help please. Here is the code i've written .</p>
<p>Thanks! I managed to get it working on my computer. I used PuTTY instead of Tera Term.</p>
<p>Thank you for this tutorial...i made it and function! I made also a small tutorial in italian language for people that not speak english http://www.ilnoningegnere.it/arduino-bluetooth-hc-05/</p>
<p>Thank you for this tutorial...i made it and function! I made also a small tutorial in italian language for people that not speak english http://www.ilnoningegnere.it/arduino-bluetooth-hc-05/</p>
<p>Hi, I have a question: how do you upload your sketch? via USB cable or directly use HC-05? Seems I could not upload the sketch via HC-05 Bluetooth.</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>Really easy and cool code for BT connectivity. just needed to uncomment first line and add header for SoftwareSerial and it worked perfect. Thanks.</p>
Awesome...you solved my problem
<p>Very good example, thks</p>
<p>hey</p><p>thank you for this article.</p><p>but i have some problem</p><p>I wanna use a pulse sensor and i wanna send data from pulse sensor by bluetooth to pc</p><p>what should I do?</p><p>would you plz send me the answer to my e-mail?</p><p>majj2000.mail@gmail.com</p>
<p>nice </p>
<p>I'm thinking of getting an inexpensive tablet like an RCA 7&quot; to run android software called Bluetooth Electronics from Keuwisoft. The tablet specs say it has bluetooth 4.0. Will these modules communicate with such devices with bluetooth 4.0?</p>
<p>The HC-05 supports Bluetooth 2.0. Bluetooth 4.0 is backwards compatible with all previous versions of Bluetooth, so your tablet should have no problem communicating with the CH-05 module.</p>
<p>Nice job!</p>
<p>Thank you for this tutorial. i will surely apply this tutorial in my next arduino project.</p>
<p>Hi ,</p><p>Thank you for a great instructable. I modified your code slightly to allow the use of hardware Serial1 , so I could connect my HC-05 to my Arduino Mega 1280. All I did was<em> ctrl+ f </em> to replace your software serial object with<em> Serial1 so </em><em>Genotronex.begin(9600);</em> will become <em>Serial1.begin(9600); </em>I also used the Tx1 and Rx1 pins connected to my HC-05 RX and Tx respectively . <strong><em>I had to remove the USB connection from my PC (Win7)to my Arduino and power it from a 5v wall wart. </em></strong>As my Arduino will not connect properly with bluetooth when the USB serial is connected. I xctu to scan for the (Blue Tooth)serial ports and used Putty Tel to try each com port (10 , 11 ), I had read somewhere the lower number would work but in my case it was Com port 11. I have put my mod of your code below for anyone using a mega.</p><p>//SoftwareSerial Serial1(10, 11); // RX, TX</p><p>int ledpin=13; // led on D13 will show blink on / off</p><p>int BluetoothData; // the data given from Computer</p><p>void setup() {</p><p> // put your setup code here, to run once:</p><p> Serial1.begin(9600);</p><p> Serial1.println(&quot;Bluetooth On please press 1 or 0 blink LED ..&quot;);</p><p> pinMode(ledpin,OUTPUT);</p><p>}</p><p>void loop() {</p><p> // put your main code here, to run repeatedly:</p><p> if (Serial1.available()){</p><p>BluetoothData=Serial1.read();</p><p> if(BluetoothData=='1'){ // if number 1 pressed ....</p><p> digitalWrite(ledpin,1);</p><p> Serial1.println(&quot;LED On D13 ON ! &quot;);</p><p> }</p><p> if (BluetoothData=='0'){// if number 0 pressed ....</p><p> digitalWrite(ledpin,0);</p><p> Serial1.println(&quot;LED On D13 Off ! &quot;);</p><p> }</p><p>}</p><p>delay(100);// prepare for next data ...</p><p>}</p>
<p>Hi! you said:&quot;As my Arduino will not connect properly with bluetooth when the USB serial is connected.&quot; so i understand that it is not possible to connect arduino to bluetooth while using the usb port juste for alimentation!!! so do i have to use an external battery??</p>
<p>Hi elhemm,</p><p> Yes you have to disconnect the usb and power the Arduino using a different 5v supply(external battery ). (An old 5v phone charger could be used or something with a barrel connector ) Everything should work quickly once this is done.</p><p>Regards</p>
<p>It is a long time since I used the AT commands,</p><p>There is a EN button on the hco5 that you must press during a power up (something like holding the EN pin low I dont remember exactly) this will put it in AT mode. Some boards dont have the EN button then you need to touch a wire to the EN pin during power up</p><p>This is the guide I followed <a href="http://www.instructables.com/id/AT-command-mode-of-HC-05-Bluetooth-module/" rel="nofollow">http://www.instructables.com/id/AT-command-mode-of...</a></p><p>You will have to find the data sheet and google for more details.</p><p>Good luck</p>
<p>i already did that! i pressed the EN button during a power up it started blinking every 2s i thought that i am in AT mode i entred the commands with 38400 baud rate and with both CR NL but it did not respond, i think that i am missing something! this is really makin me crazy...</p>
<p>You're saying that you have 38400 baud rate. Have you tried with 9600? It worked for me.</p><p>And thanks for mentioning this EN button :) I tried to send AT commands without success, and then I googled this discussion and found an info about that button :)</p>
<p>yes i've already tried!</p><p>Now i realised that i have a prob in my bluetooth module coz i have two BT module which have exactly the same type (HC 05 FC114) it worked for one but i couldn't set the other in AT mode if u are interrested in, i could give u the connection that i used to make it respond to the AT commands</p>
<p>Ok thnx for the answer!</p><p>Am sending AT commands but there is no response i tried every solution that i found on the net but in vain so i thought that maybe because of the alimentation...</p>
<p>Hi elhemm,</p><p> Yes you have to disconnect the usb and power the Arduino using a different 5v supply(external battery ). (An old 5v phone charger could be used or something with a barrel connector ) Everything should work quickly once this is done.</p><p>Regards</p>
<p>When it works it is very simple no AT commands needed to set it up initialy(you can use them later once you are up and running) .</p><p>Just connect TX (Arduino) goes to RX (HC05) and RX(Arduino )-TX(HC05)</p><p>and HC power pins.</p><p>Then write your code just like any normal serial : Serial.begin : set baud Serial.print(&quot;Hello World&quot;).</p><p>Make sure the Serial you write matches the pin - Serial(TX RX pins ) Serial1 (TX1 RX1 pins).</p><p>When you power up you should see the driver installing , you have to wait till it has finished then on your pc add a device and enter in the code to connect the bluetooth to your pc .(1234)</p><p>The go to device manager to see bluetooth serial on COM5 or 6 or whatever.</p><p>Open putty tel ,to that port and you should see your &quot;hello World&quot; I think you can use the Arduino serial monitor (as you have no usb connected)if it shows the Com port you see in the device manager. </p><p>Good Luck </p>
<p>i have 2 hc 05 BT module every one is connected on arduino uno and my PC: the connection BT1- PC is done no problem :D but am facing a problem in connecting the two BT module the first one have to write something the second BT must read it </p><p>i need the AT commande to configure them as one master the other slave so that they can communicate. if there is an other way to make them communicate i'll be so thankfull...</p>
<p>itha kan 3andek esta3mel ye Elhem wKHayti ghir khadmilna AT bark </p>
<p>wken ma3andiich cha3malna trah!</p>
<p>Hello, Do I need to use a voltage divider ? because the bluetooth module works with a 3.3v signal.</p>
<p>There are some HC-05 modules with adapters that have voltage regulators. You have to check in specification of your module(adapter). </p>
<p>I know it's rather late but StephaneE5 is quite correct. The HC-05 uses 3.3V but the Arduino uses 5V. If you don't use a voltage divider for you will fry your HC-05. I have seen several sets of instructions that do not include a voltage divider. Some people get away with it, some people don't but it isn't supposed to work without one.</p>
<p>Yes, you do. I fried my module by doing exactly what was described here. Mine worked for 10 minutes then went dead after that.</p>
<p>Is there a way to let the USB cable plugged in the Arduino ? I am using an Arduino Nano and I have no wired power cable or battery.</p><p>I heard of the SoftwareSerial library, but I do not know how to use the serials to solve the problem...</p>
<p>so this code below will allow me to communicate to the arduino mega via blue tooth with android, </p><p>//SoftwareSerial Serial1(10, 11); // RX, TX</p><p>int ledpin=13; // led on D13 will show blink on / off</p><p>int BluetoothData; // the data given from Computer</p><p>void setup() {</p><p> // put your setup code here, to run once:</p><p> Serial1.begin(9600);</p><p> Serial1.println(&quot;Bluetooth On please press 1 or 0 blink LED ..&quot;);</p><p> pinMode(ledpin,OUTPUT);</p><p>}</p><p>void loop() {</p><p> // put your main code here, to run repeatedly:</p><p> if (Serial1.available()){</p><p>BluetoothData=Serial1.read();</p><p> if(BluetoothData=='1'){ // if number 1 pressed ....</p><p> digitalWrite(ledpin,1);</p><p> Serial1.println(&quot;LED On D13 ON ! &quot;);</p><p> }</p><p> if (BluetoothData=='0'){// if number 0 pressed ....</p><p> digitalWrite(ledpin,0);</p><p> Serial1.println(&quot;LED On D13 Off ! &quot;);</p><p> }</p><p>}</p><p>delay(100);// prepare for next data ...</p><p>}</p>
<p>Which Language you are using for this code ? is it C++ ?</p><br><br>
<p>Thank you very much Mohannad! This one was easy and works like a charm.</p>
<p>This is amazing, would there be a way of communicating between a hc-05 with an arduino and a hc-05 with just a power source? i have very limited space and wondered if i would be possible to send a signal to turn a pin live on the arduino from a hc-05 without at arduino? i have ordered two and am awaiting postage. i have done this with 433mhz rf tx and rx but hey pick up to much interference. Basiclly hope to put a push switch on the hc-05 and have the ardino trip a relay. </p>
<p>hi there! I'm looking to do the exact same thing as you. did you ever found a way to do this? if so, please let me know. thanks</p>
<p>Standard Serial over bluetooth connection is established in Tera term but i am not able to type and see the result on LED. What could be the reason?</p><p>Connections are made same as stated.</p>
Arduino has 5V and 3.3V outs - you should connect the hc-05 to the 3.3V port not to fry it, afaik.
How do i connect hc-06 to auxiliary chord?
<p>Nice Project. You can use DroidScript to easily create a pretty Android App to talk to the HC-05. Check out the 'Bluetooth Serial' sample :)</p>
<p>Nice tutorial! Really helpful and awesome images and instructions. Thanks!</p>
<p>My HC-05 is paired to pc and Android, however it is disconnected. I am unable to send AT commands. To assure that the HC-05 is functional I tried 2 other HC-05, and the other modules also were paired but disconnected. Any ideas on what's going on? </p>
<p>With Ubuntu 14.04, after pairing an additional step was required to make Bluetooth available as a serial device within Ubuntu. See<a href="http://www.westernwillow.com/cms/blog/franco/creating-bluetooth-serial-port-ubuntu." rel="nofollow">http://www.westernwillow.com/cms/blog/franco/creat...</a></p><p>The basic commands are<br>#sudo hcitool scan<br>this will give you the address of the HC-05 bluetooth module<br>next, create the serial device as<br>#sudo rfcomm bind /dev/rfcomm0 &lt;the device ID retrieved in the prev command, e.g. [20:15:10:19:37:81]</p><p>This will give you a serial port /dev/rfcomm0.</p><p>This serial port can be accessed from TeraTerm, like in this tutorial, or from moserial (my preferred tool).</p><p>HTH, Willem</p>
<p>Nice tutorial hehe</p>
<p>Nice tutorial hehe</p>