My Cart

Tutorial: Bluetooth module PRO for Arduino.May 15, 2012


This tutorial describes some features of Bluetooth module PRO for Arduino which has been mainly designed to discover high amount of bluetooth devices in a variable area. Besides that, connection processes between two bluetooth modules are shown.
It has to be mentioned that inquiry processes of bluetooth module are anonymous due to only MAC address is obtained from the bluetooth remote device. No account or phone numbers are obtained. These facts allows saving privacy of bluetooth users.


Difficulty: Medium -medium
Preparation Time: 20 minutes

Steps Index

Step 1: Bluetooth module PRO:

Bluetooth module can be connected in a Xbee shield for Arduino.

Technical characteristics:

  • Chip: Bluegiga WT12
  • Bluetooth v2.1 + EDR. Class 2
  • TX Power: 7 Power levels [-27dBm, +3dBm]
  • RX sensitivity: -90 dBm
  • Antenna: 2dBi
  • Range: from 10 to 50 meters depending tx power and environment conditions.
  • Received Strength Signal Indicator (RSSI) for each scanned device
  • Class of Device (CoD) for each scanned device

Special features:
Bluetooth module integrates a firmware called Iwrap, developed by manufacturer which offers many possibilities. Refer to link & documentation section for more information.
Moreover, Libelium has developed a specific API to allow using this module with Waspmote. There are many useful functions which can be used as a guideline for other designs. Refer to Libelium web site for more information.

Power consumption
Bluetooth module has different power consumption according its operating state. Next table shows information about it.

Estate Power consumption
Sleep < 0.5 mA
ON (IDLE state) 2 mA
Inquiry at minimum power 33.5 mA
Inquiry at maximum power 36.5 mA


Step 2 : Device discovery:

For a device discovery example connect bluetooth module PRO in Gateway mode. An Arduino and a Xbee shield will be needed. Microcontroller (Atmega328) must be removed from Arduino to use it in gateway mode and also jumpers must be set to USB position.

Using gateway mode, commands can be sent from our PC to bluetooth module. The module has and integrated firmware called IWRAP which allows several possibilities. See links & documentation section to see where you can find a description of all supported commands of bluetooth module and IWRAP firmware. Commands are not case sensitive.
Once gateway is ready let's open a serial monitor (Cutecom in this case) and open serial port with parameters 38400 bps, 8 data bits,parity none and 1 stop bit. To test communication you can simply type “AT” command and “OK” will be returned.
The command used to carry out a device discovery is “INQUIRY {timeout}”. Timeout can be a number between 1 and 48 and it will determine time spent searching for devices. The module will answer with a list of discovered devices as in shown in picture below.

In this case, module has discovered three devices, showing each one in a different line with next data fields:

  • MAC address, which is a unique identification number of a bluetooth device. It has 12 hexadecimal digits separated by “:”. One example could be “12:34:56:aa:bb”.
  • CoD (Class of Device): Bluetooth devices are classified according to the device which they are integrated. Therefore a vehicle hands free device will belong to a different class than a pedestrian mobile phone. This parameter has 6 hexadecimal digit and it allows distinguish if detected bluetooth device is a vehicle, a pedestrian, and so on.
  • RSSI (Received Signal Strength Indicator): This parameters shows quality of the radio link. It can be used to know distance between bluetooth module and inquired device. It is shown as a negative value rounding -40 dBm (close devices) and -90 dBm (far devices)

By default, bluetooth module PRO is in visible mode, so you are able to discover it with other bluetooth modules. If you want to change to NOT visible mode use command “SET BT PAGEMODE 0” and if you want to make it visible again just use “SET BT PAGEMODE 4”.
If the user wants to know also “friendly name” of remote devices, the inquiry command must include “NAME” flag following timeout parameter, for instance “INQUIRY 5 NAME”, and name will be shown at the end of module response. Next image shows an example of it.

It could be that a bluetooth device has friendly name property disabled, in this case bluetooth module will answer with an event like “NAME ERROR 0x104 {MAC} HCI_ERROR_PAGE_TIMEOUT”.
If the user wants to stop inquiry processes in a certain moment, IC should be used (Inquiry Cancel). It can be useful for example to limit number of discovered devices. However, this command has to be used before summary is given by module, and name resolution processes can not be canceled.
Furthermore, “SLEEP” command can be used to reduce power consumption of bluetooth module. It has to be taken into account that awaking module by UART will produce the lost of first byte sent, which is used to wake up the module. Other useful commands are “INFO” and “SET” which show information about module.
There is another command which uses the internal temperature sensor of bluetooth module. It has no relevance in bluetooth actions but it can be used as a reference of the approximated temperature surrounded module. Just type “TEMP” command and temperature will be answered in Celsius degrees. Take into account that refresh rate of temperature sensor is not very high.

Note: Pay attention when using configuration commands and always be sure of what you are doing. Otherwise bluetooth module can become unresponsive and blocked.

Step 3 : Connecting Arduino to another Arduino without security.

If the user wants to make a basic transparent link between two bluetooth modules, CALL command should be used. Destination address must be also included. Just connect the two bluetooth modules in gateway mode and open both serial monitors. Type on module 1 next command, with address of module 2:

CALL 00:07:80:4b:2b:c4 1101 RFCOMM

After sending this command you will see “CALL” event followed to link_ID of the call and “CONNECT” event on module 1 side and “RING” event on module 2 side. Next picture shows all this process carried out, whit module 1 serial monitor on the right and module 2 serial monitor on the left.
After this events all data sent through each serial monitor will be sent to the other one. If the user want to send a command to module, escape sequence of “+++” must be sent (without end of line characters) and then module will be listening for commands. At the end, the call can be ended using “CLOSE” command followed with link_ID, and events NO CARRIER 0 and ERROR 0 will be received if everything is OK.

(example code of an Arduino connecting with a bluetooth module in gateway mode and sending “hello word”)

Step 4 : Connecting Arduino to another Arduino with security:

Connecting with security means that a PIN code will be necessary to open a connection. If the user wants to connect two Arduino with bluetooth module PRO, next steps should be followed.
First of all, same PIN code must be set in each module (in this example “1234”) using the command “SET BT AUTH * 1234”. This command saves PIN code into non-volatile memory of bluetooth module and enables security for all connections. PIN code length is configurable from 0 to 16 digit. If PIN code is set OK, same command will be returned. Also PIN code can be read using “SET” command. If the user wants to delete PIN code, it can be done with “SET BT AUTH * ” (with no pin code).
After setting same PIN code on both sides, process is equal to previous section “connecting without security” except for one detail. Devices will be paired automatically if their connection is successful. This can be checked also using ”SET” command and reading line “SET BT PAIR ...”.
However, pairing process can be done manually using “PAIR {MAC ADDR}” and the paired device will become into a trusted device (if bluetooth devices has same PIN code, or both have no pin code set). Next image shows how to set PIN code, enabling security and also how to pair a trusted device.
After setting PIN code and pairing devices, just use “CALL” command as in previous section to open a transparent connection.

Step 5 : Connecting Arduino to a PC without security:

In this case, an standard bluetooth USB dongle will be connected with bluetooth module PRO inserted in Arduino (gateway mode). The PC runs under Linux.
First of all, connect USB dongle to PC, open a terminal window and use “hcitool” to scan for bluetooth module PRO typing “hcitool scan”. All discovered devices will be listed with MAC address and friendly name. In this point can be seen if USB dongle is able to detect Arduino with bluetooth PRO module.
After that, use “sdptool” to discover remote device services and channel used for RFCOMM, typing “sdptool search sp”. Search lines corresponding to Bluetooth PRO module and see rfcomm channel like in next picture.

Then, open a connection with Bluetooth module typing command “rfcomm connect 0 {MAC_ADDR} {Channel}” and answer will show rfcomm port where USB is connected (rfcomm0 in this case).
Finally, just go to a serial monitor and open port “\dev\rfcomm0”. Now there is a transparent connection between two bluetooth modules, as is shown below.

Other useful hcitool commands are:

  • hcitool dev: shows hci devices connected to PC.
  • hcitool name {mac_addr}: shows name of given mac address.

Moreover, “hciconfig” is also useful to configure some features of bluetooth modules. Some useful commands are:

  • hciconfig: show each hci device with its main features.
  • hciconfig hciX name Bluetooth_PRO: Set local device “X” name as bluetooth_PRO.
  • hciconfig hciX piscan: Makes device “X” visible for inquiries.

Instead of using Arduino in gateway mode, you can upload a code like next one and see how to make a transparent connection.

Step 6 : Connecting Arduino to a PC with security:

This step can be carried out in same way as step 5 processes. The only difference is that bluetooth module Pro should have set a PIN code (using SET BT AUTH * {PIN_CODE}), and this code will be prompted when “sdptool search sd” is typed into a terminal. Just enter same PIN code and both devices will be paired automatically and you can continue as in step 5 to open a transparent connection.

Fritzing Libraries:


Bluetooth module PRO for Arduino


Bluetooth Module PRO for Arduino has been mainly designed to discover high amount of bluetooth devices in a variable area. It can be connected in a Xbee shield for Arduino to work.

You can download our Fritzing libraries from this area.

Links and documentation:

NOTE: If you are searching for Wireless Sensor Networks devices (motes) you may be interested in our ready to market sensor platform: Waspmote which counts with more than 50 sensors available to use.

Leave a Reply