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 





Step 2: Connect Arduino With PC

We now want to send or receive Data between arduino and computer , first we need to make a Communication link to Definition arduino Board to the computer .

We will need a software called Tera Term to show the data received or what we want to send through it .

You can download Tera Term or any terminal emulator software , you can download Tera term  from this link :

http://hp.vector.co.jp/authors/VA002416/ttermv14.zip

To make a link between your Arduino and bluetooth , do the following :

1) Go to the  bluetooth icon , right click and select Add a Device 

2) Search for new device , Our bluetooth module will appear as HC-05 , and add it 

3) The pairing code will be 1234 .

4)after make a pairing , we can now program the arduino and upload a sketch  to send or receive data from Computer.

 

Step 3: Arduino Code

As I mentioned before , I will use software serial library to make pin D10 & D11 As Tx & Rx instead of using the default Rx and tx " D0 &D1 On most arduino Board " .

this program below allow us to control LED connected to D13 To blink on/off , by press # 1 from PC Keyboard the LED blink on , and if we press 0 LED blink off ! 

To send the Control commands from Computer to arduino , Go to the tera term , Run it , and choose Serial , and select the bluetooth Serial from the list as Shown on the picture .

The code below :

// This program shown how to control arduino from PC Via Bluetooth
// Connect ...
// arduino>>bluetooth
// D11   >>>  Rx
// D10   >>>  Tx
//Written By Mohannad Rawashdeh
//for http://www.genotronex.com/

// you will need arduino 1.0.1 or higher to run this sketch

#include <SoftwareSerial.h>// import the serial library

SoftwareSerial Genotronex(10, 11); // RX, TX
int ledpin=13; // led on D13 will show blink on / off
int BluetoothData; // the data given from Computer

void setup() {
  // put your setup code here, to run once:
  Genotronex.begin(9600);
  Genotronex.println("Bluetooth On please press 1 or 0 blink LED ..");
  pinMode(ledpin,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
   if (Genotronex.available()){
BluetoothData=Genotronex.read();
   if(BluetoothData=='1'){   // if number 1 pressed ....
   digitalWrite(ledpin,1);
   Genotronex.println("LED  On D13 ON ! ");
   }
  if (BluetoothData=='0'){// if number 0 pressed ....
  digitalWrite(ledpin,0);
   Genotronex.println("LED  On D13 Off ! ");
  }
}
delay(100);// prepare for next data ...
}

After uploading This sketch go to tera term and press 0 or 1 and see the results

This Video show the results of this code .

Step 4: Connect Arduino to Android Device

after we finished from connecting arduino with PC By bluetooth , let's move to how we can connect arduino To android device .

at first you need a terminal emulator on your andriod device to send or receive  data to arduino .

You can download this app from Google play .

https://play.google.com/store/apps/details?id=arduino.bluetooth.terminal&feature=search_result#?t=W251bGwsMSwxLDEsImFyZHVpbm8uYmx1ZXRvb3RoLnRlcm1pbmFsIl0.

after that , you can use the same arduino Sketch and control LED Blinking on or Off from android device .

just  type and t send #1 to make LED Blink on , or 0 to blink off .

this video below show how to control arduino I/O from android tablet .



Step 5: Receiving Data From Arduino

The last arduino Sketch that i wrote , used to send commands from PC Or android device  to android , Now in this program i will use arduino to Calculate the time since the start of the program in second , and send it Via bluetooth to any pairing device .

the code below 

// This program shown how to control arduino from PC Via Bluetooth
// Connect ...
// arduino>>bluetooth
// D11   >>>  Rx
// D10   >>>  Tx
//Written By Mohannad Rawashdeh
//for http://www.genotronex.com/

// you will need arduino 1.0.1 or higher to run this sketch

#include <SoftwareSerial.h>// import the serial library

SoftwareSerial Genotronex(10, 11); // RX, TX
int ledpin=13; // led on D13 will show blink on / off
long previousMillis = 0;        // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000;           // interval at which to blink (milliseconds)
int ledState = LOW;             // ledState used to set the LED
long Counter=0; // counter will increase every 1 second
void setup() {
  // put your setup code here, to run once:
  Genotronex.begin(9600);
  Genotronex.println("Bluetooth On please wait....");
  pinMode(ledpin,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;  
     Counter+=1;
  
    Genotronex.println(Counter);
  
    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledpin, ledState);
  }
}

at the end , You can visit the orginal artical in arabic language on my website

http://www.genotronex.com/

Hope my first artical here is useful to you  , thank you for your time , 
well done , thanks for this tutorial <br>please do not forget to post this tutorial in your blog in Arabic :)
<p>The google play link is not working, please provide a replacement.</p>
<p>https://play.google.com/store/apps/details?id=com.nerd.dev.arduino_bluetooth_controller</p>
<p>terminal is asking me to press either 1 or 0 , but when I am giving either of them nothing happens. Nothing is displayed. Please help ASAP.</p>
<p>what is the software do you use on your PC ? check your Rx pin connection , and did you try from a mobile and got the same results ? </p>
<p>Sir, can you guide me on How to turn on buzzer if the connection bluetooth module HC-05 connection were lost with my phone. i'll really appreciate for any help. Thank You</p>
<p>you can check that using at command </p><p>otherwise connect bluetooth pin PIO9 to your board , this pin will give you pulses if no connection available , or give you HIGH if there is an connection</p>
<p>got an error of incorrect passkey </p><p>it never asked for any passkey</p>
<p>Pass key is 1234 or 0000</p>
<p>1)I installed tra term</p><p>2) paired hc-05 to my PC</p><p>3) open tera term</p><p>but the serial port for my bluetooth module does not show up in the list.</p><p>Only the Serial port for my arduino (connected via usb) appears in the list.</p><p>Can anyone help me resolve the issue?</p><p>Thanks for the help.</p>
<p>OK you need to check the serial port# of the bluetooth , are you using external bluetooth usb dongle or build in bluetooth ? </p>
I am using built in bluetooth. HC-05 shows up as com-9 in control pannel.
<p>Hello there sir, I'll like to ask a few questions, my HC-05 Module has no &quot;KEY&quot; pin but a &quot;EN&quot; pin, but I can't seem to use the Arduino IDE to enter AT mode unless I have to manually hold the button on the HC-05 Module itself. I've connected the &quot;EN&quot; pin to one of the socket on my Arduino Uno, and have set :-</p><p>pinMode(12, OUTPUT); </p><p>digitalWrite(12, HIGH);</p><p>Still couldn't enter the AT Mode.</p>
<p>I thing you need to power it off and then power it again to enter AT mode</p>
<p>Hmm, do I have to link the &quot;GND&quot; with a resistor to the &quot;EN&quot; pin to make it workable? o.O</p>
<p>EN pin is connected to wakeup pin in HC05 , you need to connect Key pin to VCC and then power off the VCC and re-power it again to enter to AT mode.<br><br>after you enter to AT mode you can disconnect this pin , no need to connect it to GND .<br>open serial monitor and set the serial option &quot;both NL &amp; CR&quot; not <br>no new line&quot; </p>
<p>But Mine only has the &quot;EN&quot; pin on my HC-05, I've tried powering it off and turning it back on while my &quot;EN&quot; pin is connected to the VCC. It still wouldn't enter the AT Command mode. Unless I have to manually hold a button that is on my HC-05 module and turning the VCC back on. Then only, I'll enter the AT Command mode... I've been frustrated with this problem for the pass 1 month. Couldn't solve it.</p>
<p>I`m using ftdi module to connect, but should work the same way for you.</p><p>Connect the bt modul as usual (led&acute;s blink fast)</p><p>bridge vcc to en for a second (led`s still blink fast) and open arduino serial @ 38400, nl and cr.</p>
<p>Hello VincentY16. I had the same problem as you, until I powered up the Arduino Uno alone. Then I powered up the HC-05 module while keeping the button pressed. Hope this helps :)</p>
<p>after you re-power on the module remove EN pin from Vcc and keep it unconnected to enter AT mode .<br><br>did you try different buad rate ? sometimes it's 9600 another time 38400 </p>
<p>you need to power off the module and then power it on again</p>
<p>I tried connecting HC 05 with arduino NG or older but the bluetooth is not discoverable on my android device can you please help me out with it.</p><p>i also changed its AT+class=0 to 1 </p>
<p>the problem in the bluetooth it self.<br>can you just power on the bluetooth alone and check the led status</p>
I did its blinking.
<p>you need to set HC05 as a slave so your phone can pair with it , otherwise it will not see it. </p>
<p>Excellent tutorial. Thanks for uploading.</p>
<p>thanks</p>
Sir <br>I want the LED to turn on for 10 minutes when the button is pressed like a timer circuit can you help me plz.....
<p>just set the delay on your code<br>delay(600000); </p><p>this is a simple solution , you can use metro library </p>
<p>the version is not supporting windows 10</p>
<p>Try to download putty from here<br><a href="http://www.putty.org/" rel="nofollow">http://www.putty.org/</a></p><p>if not working you need to search on Microsoft store for something similar to this<br>https://www.microsoft.com/en-us/store/p/bluetooth-serial-terminal/9wzdncrdfst8</p>
<p>Hello,</p><p> I'm diana, for my final year project at school, i want to write an application that will run on microsoft waist band using arduino uno and bluetooth low energy, please, is that possible and how do i start with it?</p>
<p>int ledPin=13;</p><p>int state=0;</p><p>int flag=0;</p><p>void setup()</p><p>{</p><p>pinMode(ledPin, OUTPUT);</p><p>digitalWrite(ledPin, LOW);</p><p>Serial.begin(9600);// put your setup code here, to run once:</p><p>}</p><p>void loop() </p><p>{</p><p> if(Serial.available()&gt;0) // put your main code here, to run repeatedly:</p><p>{</p><p> state=Serial.read();</p><p> flag=0;</p><p>}</p><p>if(state=='0')</p><p>{</p><p> digitalWrite(ledPin, LOW);</p><p> if (flag==0)</p><p> {</p><p> Serial.println(&quot;LED:off&quot;);</p><p> flag=1; </p><p> } </p><p> }</p><p> else if(state=='1')</p><p> {</p><p> digitalWrite(ledPin, HIGH);</p><p> if(flag==0);</p><p> {</p><p> Serial.println(&quot;led:on&quot;);</p><p> flag=1;</p><p> }</p><p> }</p><p>}</p><p>Can someone please say this code is right or wrong ...</p><p>Becasue im getting following error:</p><p> avrdude: stk500_recv(): programmer is not responding </p><p>avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x9a</p>
<p>Hi Mohannad,<br><br>thanks for sharing your experience!<br>I'm not sure if that does what I wanted to do.<br>What I want is connecting my door bell to arduino(via cable) and let arduino transfer the bell ringing to some bluetooth receivers like speakers or earphones for example.</p><p>Is that also possible?</p><p>Thanks</p><p>delaflota</p>
<p>yes possible pm me hirdeshsaxena112@gmail.com</p>
<p>Hi</p><p>I want to ask about the thesis that I do. I have 2 robots. each robot using bluetooth. how pseudocode arduino that both the robot is connected via bluetooth. and how the program so that the robot can each access the data with each other</p><p>please send it to: janne3330@gmail.com</p><p>thank you</p>
Hi, <br>I'd like to connect my computer to my arduino Uno using a hc 05. I did every step carefully but when I go to Tera term I connect to COM3 (my receiving Bluetooth port) but nothing happens, and I can't even type 0 or 1. Do someone know where could the problem come from? <br>Thanks
Hi, <br>I'd like to connect my computer to my arduino Uno using a hc 05. I did every step carefully but when I go to Tera term I connect to COM3 (my receiving Bluetooth port) but nothing happens, and I can't even type 0 or 1. Do someone know where could the problem come from? <br>Thanks
<p>Lets say that I am making something in a class so that I can send information from my Android based phone to my laptop through bluetooth. Is this a program that I could use? I need to send &quot;information that I don't need to forget to my laptop&quot; so that I can remember what I need, say to word or notepad or another type of program</p>
<p>I am not able to get this working <br>warning: always_inline function might not be inlinable [-Wattributes]<br><br>this is the error i am getting in your code</p>
<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

About This Instructable

1,181,908views

405favorites

License:

Bio: Maker, PCB designer , electronics instructor from Jordan just one word ! I Adore electronics follow me on FB https://www.facebook.com/Mohannad-Rawashdeh-Raw-774983565988641/
More by Mohannad Rawashdeh:TTP224 Digital Touch Sensor Applications Using Arduino RF 315MHz/433MHz Wireless and Arduino...again! Motor Driver BTS7960 43A 
Add instructable to: