The Controller sketch allows you to turn your BLE-enabled iOS or Android device in a hand-held controller or an external data source, taking advantage of the wealth of sensors on your phone or tablet.

You can take accelerometer or quaternion data from your phone, and push it out to your Arduino via BLE, or get the latest GPS co-ordinates for your device without having to purchase (or power!) any external HW.

Opening the Sketch

To open the Controller sketch, click on the File > Examples > Adafruit_BluefruitLE_nRF51 folder in the Arduino IDE and select controller:

This will open up a new instance of the example in the IDE, as shown below:


Check the Configuration! page earlier to set up the sketch for Software/Hardware UART or Software/Hardware SPI. The default is hardware SPI

If using software or hardware Serial UART:

  • This tutorial will also be easier to use if you wire up the MODE pin, you can use any pin but our tutorial has pin 12 by default. You can change this to any pin. If you do not set the MODE pin then make sure you have the mode switch in CMD mode
  • If you are using a Flora or otherwise don't want to wire up the Mode pin, set the BLUEFRUIT_UART_MODE_PIN to -1 in the configuration tab so that the sketch will use the +++ method to switch between Command and Data mode!
  • Don't forget to also connect the CTS pin on the Bluefruit to ground if you are not using it! (The Flora has this already done)

Running the Sketch

Once you upload the sketch to your board (via the arrow-shaped upload icon), and the upload process has finished, open up the Serial Monitor via Tools > Serial Monitor, and make sure that the baud rate in the lower right-hand corner is set to 115200:

Using Bluefruit LE Connect in Controller Mode

Once the sketch is running you can open Adafruit's Bluefruit LE Connect application (available for Android or iOS) and use the Controller application to interact with the sketch.  (If you're new to Bluefruit LE Connect, have a look at our dedicated Bluefruit LE Connect learning guide.)

On the welcome screen, select the Adafruit Bluefruit LE device from the list of BLE devices in range:

Then from the activity list select Controller:

This will bring up a list of data points you can send from your phone or tablet to your Bluefruit LE module, by enabling or disabling the appropriate sensor(s).

Streaming Sensor Data

You can take Quaternion (absolute orientation), Accelerometer, Gyroscope, Magnetometer or GPS Location data from your phone and send it directly to your Arduino from the Controller activity.

By enabling the Accelerometer field, for example, you should see accelerometer data update in the app:

The data is parsed in the example sketch and output to the Serial Monitor as follows:

Accel	0.20	-0.51	-0.76
Accel	0.22	-0.50	-0.83
Accel	0.25	-0.51	-0.83
Accel	0.21	-0.47	-0.76
Accel	0.27	-0.48	-0.82

Note that even though we only print 2 decimal points, the values are received from the App as a full 4-byte floating point.

Control Pad Module

You can also use the Control Pad Module to capture button presses and releases by selecting the appropriate menu item:

This will bring up the Control Pad panel, shown below:

Button presses and releases will all be logged to the Serial Monitor with the ID of the button used:

Button 8 pressed
Button 8 released
Button 3 pressed
Button 3 released

Color Picker Module

You can also send RGB color data via the Color Picker module, which presents the following color selection dialogue:

This will give you Hexadecimal color data in the following format:


You can combine the color picker and controller sample sketches to make color-configurable animations triggered by buttons in the mobile app-- very handy for wearables! Download this combined sample code (configured for Feather but easy to adapt to FLORA, BLE Micro, etc.) to get started:

This guide was first published on May 12, 2015. It was last updated on Mar 08, 2024.

This page (Controller) was last updated on May 13, 2015.

Text editor powered by tinymce.