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
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
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 ,
180 Comments
10 years ago on Introduction
well done , thanks for this tutorial
please do not forget to post this tutorial in your blog in Arabic :)
1 year ago
Thx, still works almost 10 years later!
2 years ago
I got the communication to work and I am sending Temperature to my computer. However, I am having trouble writing the code to automatically send data every minute or 330 seconds. It would be nice to make this send me a message if the temperature value exceeds a certain point. Any suggestions?
// This program shown how to control arduino from PC Via Bluetooth
// Connect ...
// arduino>>bluetooth
// D11 >>> Rx
// D10 >>> Tx
//Written By Mohannad Rawashdeh
//forhttp://www.genotronex.com/https://www.instructables.com/Arduino-AND-Bluetooth-HC-05-Connecting-easily/
// 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
float voltage = 0;
float degreesC = 0;
float degreesF = 0;
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:
voltage = analogRead(A0) * 0.004882813;
degreesC = (voltage - 0.5) * 100.0;
degreesF = degreesC * (9.0 / 5.0) + 32.0;
if (Genotronex.available()) {
BluetoothData = Genotronex.read();
/*if (BluetoothData == '1') { // if number 1 pressed ....
digitalWrite(ledpin, 1);
Genotronex.println("LED On D13 ON ! ");
Genotronex.println("Degrees F: ");
Genotronex.println(degreesF);
}
if (BluetoothData == '0') { // if number 0 pressed ....
digitalWrite(ledpin, 0);
Genotronex.println("LED On D13 Off ! ");
}
*/
if (degreesF > 0 ) { // if number 0 pressed ....
digitalWrite(ledpin, 1);
Genotronex.println("Degrees F: ");
Genotronex.println(degreesF);
}
delay(100);
}
delay(100);// prepare for next data ...
}
3 years ago
Hey im alittle bit late to this but my phone just won't connect to the module. I can see the Hc-05, and can try to connect just for it to be under the paired devices category and still not be connect. At the moment it's just connected to 5v and gnd but that should be the problem? I'm still new to the journey of the arduino, I'd appreciate any help :)
Question 3 years ago
Mr Mohannad Rawashdeh, can i ask you a question that if i use bluetoothData as a while loop and sen data through serial monitor. Will it work? I'm just a 14 years old boy so pls go easy on me.
Question 3 years ago on Step 1
how to receive int data and print integer data over Genotronex port?
Question 4 years ago
Hello, how do I ramp upp this cofiguration to handle bigger linear actuators, se the scematic
and the actuators in mind.
Kind regards
Tom
5 years ago on Step 5
Hello Mr. Rawashdeh,
Like you, I too had a number of problems in controlling LEDs through Bluetooth from my Android phone. However, your design and sketch worked beautifully.
Thank you so much for posting.
May the blessings of Allah be on you.
Deepak Nair,
Chandigarh,
India.
Question 5 years ago
sir where your application going? app not found
Answer 5 years ago
what is your smartphone ? android version ? this is bluetooth 2.0 and some new android OS version doesn't support it .
Question 5 years ago on Step 5
Hello sir!
The tutorial was very helpful. Thankyou.
But i have some doubts.Actually im not able get the data on tera term window instead im getting 0 and ? symbols. what is the problem?
Question 5 years ago
How many mode(HC-05) can connect to the cellphone similtanously ?
5 years ago on Step 5
This is very helpful. Thanks for you time to post this article in this website. this helps a lot for us. Thank you again.
Question 5 years ago on Step 3
I try to compile code, but only error comes out.
Question 5 years ago
The link on your website for the Arduino Bluetooth terminal doesn't work. Did you mean this program? https://play.google.com/store/apps/details?id=Qwer...
If this link doesn't work it is Bluetooth Terminal - Arduino on the Google Play Store. It is developed by QWERTY and it is E for Everyone. The email of the developer is aries156@gmail.com
If this isn't the same program could you tell me if the one described here is a good alternative or can you give me a link to the correct one?
Thank you for your time and I hope that I can get a response soon.
Question 5 years ago on Step 2
1) Go to the bluetooth icon , what icon where?
thanks
Allard
Answer 5 years ago
by going to bluetooth setting in your computer
Question 5 years ago on Step 3
How can I make the LED turn on/off when I click with a mouse
5 years ago
in my moto g mobile able to send command 1 or 0 , but LED not glow, recever RX getting blink. what to do?
5 years ago
hai, on pc screen not able to entre any 1 or o