Bluetooth Module HC06 for Arduino/Raspberry

December 13, 2015

Recently I bought a Bluetooth HC06 module for getting into wireless projects. The HC06 is a well known module that has been out for a while now. Most of the topics are covered in the documentation that is scattered all over the internet. That was my motivation to get started into my bluetooth adventures.

First a warning: There is absolutely no reason why you want to buy a HC06 module! Look for a HC05 module which is the same price but can do much more. More on that later.

Besides …. there is nothing wrong with the HC06 module.

The HC06 module - hardware/specs

HC06 topview

HC06 bottom

Folks, these are the spec that apply to my HC06 module. Yours can vary, please check all the information that you can find with your module. If you are stuck, check if pins are matching, images are matching, etc. I’ve included some HIRES images of my module at the end of this article.

Specifications

Specs
Built-in CSR company Bluetooth chip BC417143
Bluetooth® Technology v2.0 + EDR
Coverage up to 30 ft / 10 m
Built in antenna
Power input: +3.6VDC - 6VDC (bluetooth module)
Signal input: +3.3VDC
Default serial settings: 9600, N, 8, 1 (can be changed)
Bluetooth Pairing pin: 1234 (can be changed)
Bluetooth device name: HC06 (can be changed)
Firmware version: linvorV1.8

Misc topics and bluetooth

The HC06 module converts serial output e.g. from COM ports to data which can be sent over a bluetooth connection using the Serial Protocol over Bluetooth protocol (SPP). You don’t have to do something special to use it, there are no specific drivers or libraries neither programming required. You just connect the 4 required pins of your serial device or connection and you are ready to go. No magic included - look mom, no hands!

Before you can start you need a basic understanding of using Bluetooth devices. There are two different types of Bluetooth devices: slaves and masters. A slave module can be contacted by a master module, a master can connect to a slave but can’t be connected to. The HC06 can act as slave device only.

What does this mean to your project?

Simple, that means the HC06 will provide an endpoint which you can connect to and get something back. It will, however, never ever connect to something and pushes the data. You need to have a master device somewhere (such as a computer or a mobile phone) that connects to your project. For example: Having an Arduino connected to the HC06 that collects weather data - use a Raspberry PI with a Bluetooth module that connects to the HC06 and gets a sample.

Tip: There is a module named HC05 available that does the same but can run in master mode, too. Same price but more flexibility for your project. Get one of those if you can.

FAQ: As iOS devices such as iPads or iPhones don’t support SPP, there is no way to send data from the HC06 module to that devices. Android, however, works without any issues.

The pinout diagramm

There are several different designs of this wonderful module out in the field with different pinouts. Mine are - luckily - labeled on the back of the chip.

Configuration with AT commands

This module behaves in an interesting way. When you connect it to your computer using a USB to serial cable it powers up and goes to a command mode immediately. You can send several different AT commands to it, however there are some things to mention. The commands have to been sent within 1 second. If the module can’t understand the command, nothing happens.

I’ve used the Arduino IDE with it’s serial monitor to access the module and used it to send my AT commands. Here is a reference about the AT command that this module understands. Please note - there are no blanks when you enter the commands and the parameters. The AT commands don’t need a CR/LF sequence. All the AT commands can only be sent in wired mode aka connected to it’s pins, not via Bluetooth. As soon as this device has a bluetooth connection established the AT command mode is abandoned.

AT command Module reply Comment
AT OK Checks if the module is there
AT+BAUDn OK9600 Changes baud speed (here: 9600)
AT+NAMEbox OKsetname Changes name to box
AT+PINnnnn OKsetPIN Changes the PIN to nnnn
AT+Pn OK None Changes parity (here set to N)
AT+VERSION linvorV1.8 Displays the firmware version

Possible baud settings

Changing the baud setting will be stored inside the module and is persistent.

Parameter baud
1 1200
2 2400
3 4800
4 9600 (default)
5 19200
6 38400
7 57600
8 115200
9 230400
A 460800
B 921600
C 1382400

Possible parity settings

This requires firmware >= 1.5

Code Parity change
N no parity
O odd parity
E even parity

Pinout / Using my USB to serial cable

I have a (fake) Prolific USB to Serial cable which I can use to connect to the HC06 module directly. It features a step down converter which reduces the voltage from USB down to 3.3 Volt. Therefore it’s safe to use it with the module.

Please check before you wire your module to any USB2Serial cable out there. Better safe than sorry!

Cable (Prolific 2303HX [fake]) HC06 Bluetooth module
red VCC
black GND
white TXD
green RXD

Ready to get started?

Ok, let’s wire this thing up - to something? Well, I suggest getting a USB2Serial cable like I did and connect the module to the correct pins properly. Once again, make sure that you are using the correct voltage!

The pairing process

Pairing with the device is pretty straightforward. Make sure the red led on the HC06 module is blinking. That means it’s in pairing mode and is waiting for a connection. Open your bluetooth control panel on your pairing device e.g. Android, Windows, Mac or Linux and look for the HC06. Usually this device is named HC06 unless you have changed it. The pairing code is ‘1234’ and that’s it. After a few seconds you will have a com port assigned to your computer. In my case there are 2 com ports - one for incoming and one for outgoing connections. As I am using the outgoing connection to connect to the HC06, I am looking for that com port.

The Windows way

The fastest way to open the settings is by entering the following line in a command prompt aka cmd window.

control bthprops.cpl

Make sure your Bluetooth is enabled on your computer. Click on the ‘extended bluetooth options’ at the bottom. This will open the Bluetooth settings. There is tab called ‘COM connections’ (or similar), if you click on this tab all your Bluetooth related COM ports are being displayed. Check the ‘outgoing’ COM port and remember the number.

Bluetooth properties windows

From this point we need to switch to the Arduino IDE. Choose tools -> port -> the COM port we just looked up. If you open your serial monitor from within the Arduino IDE you’ll notice that the red led on the Bluetooth module stopped flashing and turned into a solid red led. Congratulations, the pairing is done and you have a working connection. Nice! Ok, we have a connection using USB2Serial from our computer on a COM port in the Arduino IDE and we have a working bluetooth connection with a COM port. By using a program such as PuTTY we can connect to the COM port which has been assigned by the Bluetooth connection and can type something in the terminal window. The chars are being transferred using Bluetooth to the HC06 and will be transferred through the USB2Serial cable back in our computer in the Arduino IDE. Nice, we can write something to ourselves. If you are here - you got everything successfully connected and working.

I will add Linux and MacOS X instructions - maybe, however the progress is similar. Find the new com port - usually it’s something like ‘/dev/tt…’ and connect to it. On Linux and MacOSX there is a programm called ‘screen’ which will do the trick. Here is a commandline on how to use it.

screen /dev/rfcomm0 9600

The last number is the baud count which is needed to talk to the serial port properly.

Usage with an Arduino Micro

hang on - I am working on it

Usage with a Raspberry PI

Using this module on the Raspberry PI is incredible simple. The Raspberry PI sends out all the kernel message (aka boot messages) to the serial console which is reachable via the GPIO pins. If you set the Bluetooth module to the correct baudspeed (115200) using the AT+BAUD8 command it’s capable to transfer the console messages to any terminal which is connected via Bluetooth. Please keep in mind that the Raspberry has a signal level of 5 Volt on the TX pin and might damage the HC06 if you connect it directly. By using a voltage divider which can be easily assembled with 2 resistors you are safe.

I am pretty unsure about my HC06 module. I had it connected quite a few times without the voltage divider without any problems. Anyway - it’s your own risk, don’t blow it up. Resistors are cheap and are easy to purchase.

I’ll come with a plan for the cables soon - as it will be the same plan as for the Arduino.

Usage with an Android phone

There are some nice apps outside which allow something like a rapid prototyping. Basically, the Android device connects to the Bluetooth device using SPP and receives data over that line in a certain format - as a string. The app provides some sample elements such as graphs which will parse the incoming data and make use of it in the graph elements.

I have played around with the app called “Bluetooth Electronics” and made a nice graph out of an Arduino Micro with a DHT11 sensor connected to it. The data was transferred using Bluetooth HC06 module.

You can find the application here: https://play.google.com/store/apps/details?id=com.keuwl.arduinobluetooth

Check out this cool screenshot of the graph!

My first Android/Arduino app

Here is another one. It shows a thermometer on the left, on the right is a serial monitor which displays the incoming data. In this example only the first number before the comma is being used.

More Android graphs

The measure was taken outside, I am not used to sit at 11 °C for long. :)

Conclusion

13.12.2015 - I am still not done with everything. There is still so much to document on this page. Particularly the connection setup for the Arduino and the Raspberry. I haven’t decided about using Fritzing or not, actually I don’t enjoy using it that much. What’s nice about ordering toys from somewhere without any description is that you have to leave your comfort zone and challenge yourself. Get back into thinking, find out about connections, documentation, get in contact with other makers and be creative. Adafruit makes wonderful modules for the Arduino and for the Raspberry and they are worth every penny. However, sometimes you need to push your boundries and look into things.

Adafruit, it’s nice to come back - to working modules with datasheets, etc.

Comments

comments powered by Disqus