Introduction: Arduino AND Bluetooth HC-05 Connecting Easily


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 , 

Comments

author
sunxing22 made it!(author)2013-06-05

well done , thanks for this tutorial
please do not forget to post this tutorial in your blog in Arabic :)

author
PetioP1 made it!(author)2017-06-25

I would like to test this out on a teensy 3.2. What pins should I connect to in that case?

author
Mohannad+Rawashdeh made it!(author)2017-06-26

on teensy 3.1 / 3.2 you need to use Digital Pins with serial 1 (D0,D1) ,serial 1 (D9,D10) OR serial 3 (D7,D8) and use the hardware serial serial , which is easier and have more capability than software serial

author
PetioP1 made it!(author)2017-06-27

Thanks for quick reply!

author
LeeC93 made it!(author)2017-05-29

Has this been updated for Arduino IDE 1.6.1

And changed libraries?

author
MasumH1 made it!(author)2017-05-13

The google play link is not working, please provide a replacement.

author
Mohannad+Rawashdeh made it!(author)2017-05-24

https://play.google.com/store/apps/details?id=com.nerd.dev.arduino_bluetooth_controller

author
HimanshuM26 made it!(author)2017-05-23

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.

image_2305_hi_v1_Problem.PNG
author
Mohannad+Rawashdeh made it!(author)2017-05-24

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 ?

author
ShahM11 made it!(author)2017-05-04

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

author
Mohannad+Rawashdeh made it!(author)2017-05-09

you can check that using at command

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

author
AmarnathM3 made it!(author)2017-04-09

got an error of incorrect passkey

it never asked for any passkey

author
Mohannad+Rawashdeh made it!(author)2017-04-09

Pass key is 1234 or 0000

author
HarshC17 made it!(author)2017-03-30

1)I installed tra term

2) paired hc-05 to my PC

3) open tera term

but the serial port for my bluetooth module does not show up in the list.

Only the Serial port for my arduino (connected via usb) appears in the list.

Can anyone help me resolve the issue?

Thanks for the help.

author
Mohannad+Rawashdeh made it!(author)2017-03-30

OK you need to check the serial port# of the bluetooth , are you using external bluetooth usb dongle or build in bluetooth ?

author
HarshC17 made it!(author)2017-03-31

I am using built in bluetooth. HC-05 shows up as com-9 in control pannel.

author
VincentY16 made it!(author)2017-02-16

Hello there sir, I'll like to ask a few questions, my HC-05 Module has no "KEY" pin but a "EN" 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 "EN" pin to one of the socket on my Arduino Uno, and have set :-

pinMode(12, OUTPUT);

digitalWrite(12, HIGH);

Still couldn't enter the AT Mode.

author
Mohannad+Rawashdeh made it!(author)2017-02-17

I thing you need to power it off and then power it again to enter AT mode

author
VincentY16 made it!(author)2017-03-05

Hmm, do I have to link the "GND" with a resistor to the "EN" pin to make it workable? o.O

author
Mohannad+Rawashdeh made it!(author)2017-03-05

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.

after you enter to AT mode you can disconnect this pin , no need to connect it to GND .
open serial monitor and set the serial option "both NL & CR" not
no new line"

author
VincentY16 made it!(author)2017-03-09

But Mine only has the "EN" pin on my HC-05, I've tried powering it off and turning it back on while my "EN" 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.

author
siffup made it!(author)2017-03-26

I`m using ftdi module to connect, but should work the same way for you.

Connect the bt modul as usual (led´s blink fast)

bridge vcc to en for a second (led`s still blink fast) and open arduino serial @ 38400, nl and cr.

author
fmarengo made it!(author)2017-03-15

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 :)

author
Mohannad+Rawashdeh made it!(author)2017-03-09

after you re-power on the module remove EN pin from Vcc and keep it unconnected to enter AT mode .

did you try different buad rate ? sometimes it's 9600 another time 38400

author
Mohannad+Rawashdeh made it!(author)2017-03-04

you need to power off the module and then power it on again

author
VismayP made it!(author)2017-03-02

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.

i also changed its AT+class=0 to 1

author
Mohannad+Rawashdeh made it!(author)2017-03-04

the problem in the bluetooth it self.
can you just power on the bluetooth alone and check the led status

author
VismayP made it!(author)2017-03-04

I did its blinking.

author
Mohannad+Rawashdeh made it!(author)2017-03-04

you need to set HC05 as a slave so your phone can pair with it , otherwise it will not see it.

author
vu2aeo made it!(author)2017-02-23

Excellent tutorial. Thanks for uploading.

author
Mohannad+Rawashdeh made it!(author)2017-03-04

thanks

author
vivekschari made it!(author)2017-02-06

Sir
I want the LED to turn on for 10 minutes when the button is pressed like a timer circuit can you help me plz.....

author
Mohannad+Rawashdeh made it!(author)2017-02-17

just set the delay on your code
delay(600000);

this is a simple solution , you can use metro library

author
harsithng made it!(author)2017-02-03

the version is not supporting windows 10

author
Mohannad+Rawashdeh made it!(author)2017-02-03

Try to download putty from here
http://www.putty.org/

if not working you need to search on Microsoft store for something similar to this
https://www.microsoft.com/en-us/store/p/bluetooth-serial-terminal/9wzdncrdfst8

author
dianasthat made it!(author)2017-01-23

Hello,

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?

author
AkshayJ42 made it!(author)2016-12-28

int ledPin=13;

int state=0;

int flag=0;

void setup()

{

pinMode(ledPin, OUTPUT);

digitalWrite(ledPin, LOW);

Serial.begin(9600);// put your setup code here, to run once:

}

void loop()

{

if(Serial.available()>0) // put your main code here, to run repeatedly:

{

state=Serial.read();

flag=0;

}

if(state=='0')

{

digitalWrite(ledPin, LOW);

if (flag==0)

{

Serial.println("LED:off");

flag=1;

}

}

else if(state=='1')

{

digitalWrite(ledPin, HIGH);

if(flag==0);

{

Serial.println("led:on");

flag=1;

}

}

}

Can someone please say this code is right or wrong ...

Becasue im getting following error:

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x9a

author
delaflota made it!(author)2016-11-16

Hi Mohannad,

thanks for sharing your experience!
I'm not sure if that does what I wanted to do.
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.

Is that also possible?

Thanks

delaflota

author
HirdeshS2 made it!(author)2016-12-05

yes possible pm me hirdeshsaxena112@gmail.com

author
Raudatul+Jannah made it!(author)2016-11-15

Hi

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

please send it to: janne3330@gmail.com

thank you

author
comiicome made it!(author)2016-11-07

Hi,
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?
Thanks

author
comiicome made it!(author)2016-11-07

Hi,
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?
Thanks

author
WilliamA144 made it!(author)2016-10-13

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 "information that I don't need to forget to my laptop" so that I can remember what I need, say to word or notepad or another type of program

author
nakulkundra made it!(author)2016-09-03

I am not able to get this working
warning: always_inline function might not be inlinable [-Wattributes]

this is the error i am getting in your code

author
kblair3 made it!(author)2016-08-27

Thanks! This was really helpful to dip my toes in to working with the HC-05

author
Gljames24 made it!(author)2016-08-23

I have an Arduino Due and a HC-05 HM-10 and nothing I've seen works.

author
sereyen made it!(author)2016-08-15

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 .

instruc.PNGinstruc1.PNG
author
HobbyTransform made it!(author)2016-08-07

Thanks! I managed to get it working on my computer. I used PuTTY instead of Tera Term.

author
StefanoZ1 made it!(author)2016-07-01

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/

author
StefanoZ1 made it!(author)2016-07-01

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/

About This Instructable

1,199,892views

409favorites

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:Convert Your Pringles Cans to RTTTL Audio PlayerTTP224 Digital Touch Sensor Applications Using ArduinoRF 315MHz/433MHz Wireless and Arduino...again!
Add instructable to: