This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.


Create Bluetooth object


B = Bluetooth('RemoteName', Channel)
B = Bluetooth('RemoteID', Channel)
B = Bluetooth('RemoteID', Channel, 'P1',V1,'P2',V2,...)


The Instrument Control Toolbox™ Bluetooth® interface lets you connect to devices over the Bluetooth interface and to transmit and receive ASCII and binary data. Instrument Control Toolbox supports the Bluetooth Serial Port Profile (SPP). You can identify any SPP Bluetooth device and establish a two-way connection with that device.

B = Bluetooth('RemoteName', Channel) constructs a Bluetooth object associated with the RemoteName and Channel. RemoteName is a friendly way to identify the RemoteID. If a channel is not specified, it will default to 0.

B = Bluetooth('RemoteID', Channel) constructs a Bluetooth object directly from the RemoteID and Channel.

In order to communicate with the Bluetooth device, use the fopen function. When the Bluetooth object is constructed, the object's status property is closed. Once the object is connected to the remote device with the fopen function, the status property is configured to open.

B = Bluetooth('RemoteID', Channel, 'P1',V1,'P2',V2,...) constructs a Bluetooth object associated with the RemoteID, Channel and with the specified property values. If an invalid property name or property value is specified the object will not be created. The property value pairs can be in any format supported by the set function, i.e., param-value character vector pairs, structures, and param-value cell array pairs.

For information on other functions that can be used with Bluetooth, a full example using the Bluetooth interface, events and callbacks, and usage guidelines see Bluetooth Interface Overview.

Properties that can be used with the Bluetooth object include:

ChannelUse to specify a channel if the device has channels. If none is provided, it defaults to 0.
RemoteName“Friendly name” for the Bluetooth device. For example, in the case of an iPhone, it might be simply 'iPhone' or a name like 'Zor'.

This property is a character vector and can be empty. If it is empty, you must use the RemoteID to communicate with the device.

RemoteIDInternal ID of the Bluetooth device, equivalent to the Device ID. This is usually a 12-digit character vector that starts with btspp://. For example, 'btspp://0016530FD65F'

This property is a character vector and every device has one. You can use this or the RemoteName to communicate with the device.


To get a list of options you can use on a function, press the Tab key after entering a function on the MATLAB® command line. The list expands, and you can scroll to choose a property or value. For information about using this advanced tab completion feature, see Using Tab Completion for Functions.


Find available Bluetooth devices.

 instrhwinfo('Bluetooth', RemoteName); 

Construct a Bluetooth object called b using channel 3 of a Lego Mindstorm robot with RemoteName of NXT.

b = Bluetooth('NXT', 3);

Connect to the remote device.


Send a message to the remote device using the fwrite function.

fwrite(b, uint8([2,0,1,155]));

Read data from the remote device using the fread function.

name = fread(b,35);

Disconnect the Bluetooth device.


Clean up by deleting and clearing the object.


Introduced in R2011b

Was this topic helpful?