Cheap 2-Way Bluetooth Connection Between Arduino and PC

734,340

652

76

About: Did I unplug the solder iron?
UPDATE

INTRODUCTION

In the guide, I will explain how I managed to send data back and forth between a PC and Arduino via a cheap Bluetooth HC-05 transceiver, which can be found for less than $10 on ebay with the breakout board. The version I have used in this project does not have a breakout board so it's little cheaper but  more difficult to solder.  I strongly recommend buying the module with the breakout board. This Bluetooth transceiver basically acts as a generic serial COM port.

The PC to Arduino Bluetooth serial connection can be useful in many applications such as controlling servos, motors, and writing to LCDs. The Arduino to PC connection can be useful in applications where the Arduino reads sensors then pass their values  via serial Bluetooth to a PC for processing. The distance for this transceiver is about 30 feet or so but it really depends on many other variables. This is ideal for indoors projects. 

The only downside of this cheap Bluetooth transceiver is the absence of headers which means you have to solder at least 4 wires. Then there's the absence of power LED as well as no TX/RX LEDs. I did not consider these features a necessity but some of you might want to pay more and get an enhanced version of this transceiver with all of these features.


The Bluetooth serial module I bought has the following specs:

-- Default COM setting: 9600, N, 8,1
-- Default Password/pairing code: 1234.
-- Supports the AT command to modify the baud rate, device name, passkey, master/slave, etc.
-- Supports baud rates 2400 -1382400.
-- Based on the CSR Bluetooth chip BC417143
-- Bluetooth specification v2.0 + EDR
-- Power supply: +3.3VDC 50mA
-- Frequency:  2.4GHz ISM band
-- Modulation:  GFSK(Gaussian Frequency Shift Keying)
-- Emission power:  ≤4dBm, Class 2
-- Sensitivity:  ≤-84dBm at 0.1% BER
-- Speed: Asynchronous:  2.1Mbps(Max) / 160 kbps, Synchronous: 1Mbps/1Mbps
-- Security:  Authentication and encryption
-- Size: 26.9mm x 13mm x 2.2 mm.
-- Working temperature: -20 ~ +75 Centigrade
-- Dimension: 26.9mm x 13mm x 2.2 mm

CREDITS

During my research, I have benefited from many projects on this and related topics. I have listed them in the references section.

RELATED PROJECTS

1) In a previous project, I used a Pololu Wixel and an Arduino to control a robot remotely from a PC terminal. Here, I will show similar data exchange functionality but without the robot.

2) I also hacked the RF system of cheap wireless car toy and used the Arduino to transmit signals.


Step 1: The Parts List

HARDWARE

-- Arduino Uno (R2) or clone.
-- Bluetooth serial transceiver connected to Arduino. I got one from Ebay with the BlueCore4 chipset. Search Ebay for Wireless Bluetooth Transceiver Module RS232 / TTL.
-- Bluetooth USB dongle to be connected to PC. I used an old MSI pc2pc Bluetooth as well as a Bollionton Bluetooth USB dongles and both worked fine. 
-- The 1.2K Ohms & 2.2K Ohms resistors will be used as voltage dividers to drop the Arduino's 5V to about 3.3V. You can substitute these with 10K Ohms & 20K Ohms resistors. If you know how to calculate voltage dividers, feel free to use other values for your resistors. 
-- Breadboard and jumper wires.
-- Power source. I used a 9V battery.
-- Any PC that supports Arduino IDE will be needed to program the Arduino microcontroller. 
-- Most PCs and  smartphone w/Bluetooth and a terminal emulator can be used to control the Arduino. 

SOFTWARE

-- Windows 7 64-bit. But this should work on other platforms supported by the Arduino IDE.
--  Arduino IDE 1.0
--  Tera Term Pro  terminal emulator but other similar emulators should work.
-- Tera Term by the original author of the software

Step 2: Load the Arduino Test Sketches

NOTE: When uploading sketches from the Arduino IDE to the Arduino microcontroller, make sure your Bluetooth transceiver TX pin/wire is not connected to the Arduino's RX pin (pin 0) . Else, this may prevent your PC from sending sketches to the Arduino microcontroller.

Check the video to see how these demo sketches work. 

I have two Arduino test sketches. The first one is a "send test." The Arduino microcontroller sends numbers to the PC over serial Bluetooth. So if you have a terminal emulator running on your PC, such as Tera Term, you will see a list of numbers rolling down your emulator's screen.

I have done almost no error trapping in my code to keep the code clear and simple. I trust the developers will add it per their requirement. 

The second Arduino test sketch is a "get test." If you type 1 on your keyboard, from the terminal emulator application such as Tera Term, the Arduino's pin 13 LED will turn on. If you click 0 on your keyboard, the LED will turn off.

//////////////////////////////////////////////////////////////////////////////////
// REMIXED BY: TECHBITAR (HAZIM BITAR)
// LICENSE: PUBLIC DOMAIN
// DATE: MAY 2, 2012
// CONTACT: techbitar at gmail dot com

int counter =0;

void setup() {
  Serial.begin(9600); 
  delay(50);
}

void loop() {
  counter++;
  Serial.print("Arduino counter: ");
  Serial.println(counter);
  delay(500); // wait half a sec
}

//////////////////////////////////////////////////////////////////////////////////

// REMIXED BY: TECHBITAR (HAZIM BITAR)
// LICENSE: PUBLIC DOMAIN
// DATE: MAY 2, 2012
// CONTACT: techbitar at gmail dot com

char INBYTE;
int  LED = 13; // LED on pin 13

void setup() {
  Serial.begin(9600); 
  pinMode(LED, OUTPUT);
}

void loop() {
  Serial.println("Press 1 to turn Arduino pin 13 LED ON or 0 to turn it OFF:");
  while (!Serial.available());   // stay here so long as COM port is empty   
  INBYTE = Serial.read();        // read next available byte
  if( INBYTE == '0' ) digitalWrite(LED, LOW);  // if it's a 0 (zero) tun LED off
  if( INBYTE == '1' ) digitalWrite(LED, HIGH); // if it's a 1 (one) turn LED on
  delay(50);
}

Step 3: Wiring the Arduino + Bluetooth Transceiver

WARNING: MY BLUETOOTH MODULE OPERATES AT +3.3V DC. THE ARDUINO UNO IO PINS OUTPUT 5V. SO AVOID CONNECTING THE ARDUINO 5V OUTPUT PINS TO THIS TRANSCEIVER WITHOUT A VOLTAGE DIVIDER.

However since the Bluetooth pins output 3.3V, this won't hurt the Arduino pins which tolerate 5V and will treat a 3.3V signal from the Bluetooth serial transceiver as a logical high. This is why I did not use a voltage divider for the connection between the Bluetooth transmission/TX pin (rated 3.3v) and the Arduino receive/RX pin 0 (rated 5V.)

START WIRING

1) Solder 4 wires to the Bluetooth module: TX, RX, GND, Vcc
2) Assemble the voltage divider. I have lots of photos to help with this step.
3) Wire the Bluetooth module to the Arduino Uno according to this:

Bluetooth TX  -----> Arduino Uno RX (Pin 0)
Bluetooth RX  -----> Arduino Uno TX (Pin 1) via the voltage divider!
Bluetooth GND -----> Arduino GND pin
Bluetooth Vcc  -----> Arduino 3.3V pin but NOT the 5V pin. 

4) Power the circuit. I used a 9V battery.

Keep a mobile phone or a Bluetooth device handy to detect whether your Bluetooth transceiver is available.

At this moment, your Bluetooth serial transceiver should come to live and other Bluetooth devices should see it. If you don't see it, check the wiring again. 

My Bluetooth serial transceiver has a default name of HC-05 and a default code of 1234 and speed of 9600. Check your vendor documentation for your devices name and password/pairing code.  You can change all these defaults with the AT commands.

5) Plug the Bluetooth USB dongle into your PC and move along to the next section.

Step 4: Set Up Your PC for Serial Bluetooth Communication

When you insert the Bluetooth dongle into the USB port of your PC, Windows will install the necessary drivers automatically. When it's done, it will display a system message stating the installation was a success.

You will then see the Bluetooth icon in your system tray or on your desktop. Click on it to see a menu with a number of options such as Show Bluetooth Devices. Click on it and follow the slides.

Select Add Devices or Show Bluetooth Devices. 

If your Arduino Bluetooth serial transceiver is wired properly, your device name should show up on the list. Click on it and then click Next.

You will be prompted to enter your Bluetooth devices' pairing code/password. The default for most Bluetooth devices is either 1234 or 0000.  Click Next. 

If the pairing is successful, you will see a system message saying so. 

Now, both your PC's Bluetooth and the Arduino's Bluetooth are connected as if by serial cable. 

Run Tera Term on your PC (or any similar terminal emulator) and select the COM port number specified by the pairing. 

FORGOT WHICH COM PORT?

If you forgot the Bluetooth COM port used for the paired Bluetooth transceivers, right click on the Bluetooth icon on your System Icon area and select "Show Bluetooth Devices." You will see a list of Bluetooth devices.  

Right click on your Bluetooth device and select "Properties."

Then click on the "Services" tab. There you will see the COM port number. 

When you can't make a connection/pairing even though you are certain your Bluetooth devices are running normally, delete your Bluetooth device and start the process from the top. That seems to reset the connection. 

RUN TERA TERM

Once the pairing is done, run Tera Term to start communicating with your Arduino. Tera Term will prompt you to pick either Serial or TCP/IP. Select Serial and make sure Tera Term shows the COM port number from the previous steps. Also make sure the settings are the same for both Bluetooth serial modules. In this case: 9600, N, 8,1

If you have uploaded the get test sketch, then type either 1 (one) or 0 (zero) to turn pin 13 LED on the Arduino on or off. If you uploaded the send test sketch, you will see a growing list of ascending numbers on the Tera Term screen sent from Arduino over serial Bluetooth.

Step 5: References

Special thanks to my good friend and top notch maker Jafar Qutaineh for his input and to the developers of the many helpful Bluetooth projects that I used as a foundation for this project such as the ones listed here:

Wireless communication with PC and Arduino board using Bluetooth
http://arduino.cc/playground/Learning/Tutorial01

Androino! Control an Arduino from your Android device using a cheap bluetooth module.
https://www.instructables.com/id/Androino-Talk-with-an-Arduino-from-your-Android-d/

how to Control arduino by bluetooth from (PC, pocket PC PDA)
https://www.instructables.com/id/how-to-Control-arduino-by-bluetooth-from-PC-pock/

USE THIS GUIDE AT YOUR OWN RISK

Share

Recommendations

  • Make it Glow Contest 2018

    Make it Glow Contest 2018
  • Optics Contest

    Optics Contest
  • Plastics Contest

    Plastics Contest

76 Discussions

0
None
asdftghju

10 months ago

thanks but can i do it from my pc like an application

0
None
DavidB552

1 year ago

anyone know a good app that does what terra term does for andriod ?

0
None
pbedyn

1 year ago

hi techbitar,

Thanks for your tutorial. All worked great on teensy 3.2 and Windows8.

0
None
praveensb

2 years ago

hey i,m not able to download pdf

0
None
vanyatka

3 years ago

Any idea why iPhone does not see the device?

It works fine with Mac OS X, though.

3 replies
0
None
xepicxmonkeyxvanyatka

Reply 2 years ago

Apple are too profit hungry to allow the treachery of using Bluetooth profiles other than their MFi.

0
None
botronicsvanyatka

Reply 2 years ago

The protocol is different with iOS. I got s low cost Android tablet to experiment with.

0
None
MR_Hunsvanyatka

Reply 2 years ago

http://www.eevblog.com/forum/beginners/hc05-bluetooth-and-iphone/

0
None
dimitrakis1992

2 years ago

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


The bluetooth that i use is HC-05

My code:

#include <Servo.h>

Servo SERVO_1; // Initialize Servo1

// Motor Control Variables
int PWM1 = 9;
int ENABLE1 = 8;
int PWM2 = 5;
int ENABLE2 = 7;
int PWM3 = 3;
int ENABLE3 = 4;
int PWM4 = 6;
int ENABLE4 = 12;
int STATE=2;


void setup() {
SERVO_1.attach(10);
Serial.begin(9600);
pinMode(ENABLE1, OUTPUT); //Δήλωση όλων των μεταβλητών ως έξοδος
pinMode(ENABLE2, OUTPUT); //Δήλωση όλων των μεταβλητών ως έξοδος
pinMode(ENABLE3, OUTPUT); //Δήλωση όλων των μεταβλητών ως έξοδος
pinMode(ENABLE4, OUTPUT); //Δήλωση όλων των μεταβλητών ως έξοδος
pinMode(STATE, INPUT);
}

void loop() {

if(digitalRead(STATE)== HIGH)

// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
int incomingByte = Serial.read();
// action depending on the instruction
// as well as sending a confirmation back to the app
switch (incomingByte) {
case 'F':
moveForward();
Serial.println("Going forward");
break;
case 'L' : // Case 'L' is received,
SERVO_1.write (180); // Στρίψε Αριστερά.
SERVO_1.attach(10);
break;
case 'N':
turnright();
Serial.println("Turning right");
break;
case 'M':
turnleft();
Serial.println("Turning left");
break;
case 'O' : // Case 'L' is received,
SERVO_1.write (0); // Στρίψε Αριστερά.
SERVO_1.attach(10);
break;
case 'B':
moveBackward();
Serial.println("Going forward");
break;
case 'P':
SERVO_1.write(90); // Στρίψε Αριστερά.
SERVO_1.attach(10);
break;
case 'S':
moveNone();
Serial.println("Stopping");
break;
default:
// if nothing matches, do nothing
break;
}
}
}

void moveForward() {
// turn the driving motor on to go forwards at set speed
digitalWrite(ENABLE1, HIGH);
digitalWrite(ENABLE2, HIGH);
digitalWrite(ENABLE3, HIGH);
digitalWrite(ENABLE4, HIGH);
analogWrite(PWM1, 255);
analogWrite(PWM2, 255);
analogWrite(PWM3, 255);
analogWrite(PWM4, 255);

}

void moveBackward() {
// turn the driving motor on to go backwards at set speed
digitalWrite(ENABLE1, LOW);
digitalWrite(ENABLE2, LOW);
digitalWrite(ENABLE3, LOW);
digitalWrite(ENABLE4, LOW);
analogWrite(PWM1, 255);
analogWrite(PWM2, 255);
analogWrite(PWM3, 255);
analogWrite(PWM4, 255);
}
void turnright() {
digitalWrite(ENABLE1, HIGH);
digitalWrite(ENABLE2, HIGH);
digitalWrite(ENABLE3, LOW);
digitalWrite(ENABLE4, LOW);
analogWrite(PWM1, 255);
analogWrite(PWM2, 255);
analogWrite(PWM3, 255);
analogWrite(PWM4, 255);
}

void turnleft() {
digitalWrite(ENABLE1, LOW);
digitalWrite(ENABLE2, LOW);
digitalWrite(ENABLE3, HIGH);
digitalWrite(ENABLE4, HIGH);
analogWrite(PWM1, 255);
analogWrite(PWM2, 255);
analogWrite(PWM3, 255);
analogWrite(PWM4, 255);
}
void moveNone() {
// turn the driving motor off
digitalWrite(ENABLE1, 0);
digitalWrite(ENABLE2, 0);
digitalWrite(ENABLE3, 0);
digitalWrite(ENABLE4, 0);
analogWrite(PWM1, 0);
analogWrite(PWM2, 0);
analogWrite(PWM3, 0);
analogWrite(PWM4, 0);
SERVO_1.detach();
}

0
None
KellinC

2 years ago

What all can you do with this? I am looking for a way to communicate long-distance with a friend, I have almost all the tools and supplies needed, so can you actually make them "talk" with each other?

If so that would be great, but it was a great tutorial!

0
None
Fritzy28

2 years ago

Hello, i have a noob question,to use the HC05 must i go through any initial set ups? i followed you intructions, my pc already have a built in bluetooth. i connected to the HC-05 uploaded the code onto my arduino, then used a separate power source for the Arduino . i made sure to connect to the sending COM and when i try to create a connection from arduino to BT it fails . gives me avrdude: stk500_recv(): programmer is not responding

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

1 reply
0
None
RomninjaFritzy28

Reply 2 years ago

Would be cool if you didn't post your comment 10 times.

Anyway, i think your problem is not in the serial connection to your arduino,but programming your arduino.

0
None
sachin909111

2 years ago

If i want to connect BT 53 module. It has version 4.1, what will be the procedure to connect it?

0
None
Priun

3 years ago on Step 3

Thanks for your instructable. Any idea why it doesn't work on an Arduino Mega powered via 9V (not USB)?

When using SoftSerial (using other pins) or Serial1 it works, just not on the standard Serial port on pins 0 and 1.

I'm using a 2k and a 1k resistor.

0
None
fhovin

3 years ago on Step 5

This worked for me when testing, and installing and pairing worked fine without any errors. The bluetooth device is shown as HC-06 in Windows.

However, connecting to COM7: Standard serial over bluetooth (yes, COM7 is correct), both with tera term and other emulators, nothing happens.

Also, you have this at the end of your tutorial:
"Also make sure the settings are the same for both Bluetooth serial modules. In this case: 9600, N, 8,1"

9600 is correct, as it's the default speed. But where does "N, 8, 1" enter into the picture?

The only configuration options I can find are for the Serial connection in tera term, and they show the following:

Port: COM7
Baud rate: 9600
Data: 8 bit
Parity: none
Stop: 1 bit
Flow control: none

This was done with the USB cable still connected. When I disconnected this, the bluetooth device was still shown as connected and paired on port COM7, but this changed nothing.

Then I tried connecting my Android phone to it, and connection and pairing worked fine. I also ran a bluetooth terminal emulator on the phone, and it was successfull in connecting to the device.

However, sending 1 or 0 from the emulator did nothing, while it worked fine in the Serial monitor in Arduino.

Any ideas?

2 replies
0
None
nishant_panifhovin

Reply 3 years ago

Hi,

Just ensure your usb to serial rx is connected to hc05 tx and tx to rx... Opposite config... Should work fine :)

0
None
fhovinfhovin

Reply 3 years ago on Step 5

In short, it works when testing from the Arduino IDE Serial Monitor, but there's no reaction when connecting the terminal emulator(s) over bluetooth, in Windows or Android. No echo return, and no LED on/off.