Working with Bluetooth

The Bluetooth Mate Gold and Bluetooth Mate Silver are handy wireless modules that can plug directly into your Lilypad Arduino or Arduino Mini Pro. While they are rather pricey, they save you the trouble of configuring the radio, wiring up extra components, and they can connect to any other device that is bluetooth enabled such as a laptop or smart phone. For most applications the Silver will do just fine (it’s range is 330′) and it is significantly cheaper than the Gold.

To get started, this is a very helpful tutorial:

ITP/NYU Tutorial

For the last step, I recommend using this slightly altered version of the code which displays the sensor value in the bottom of the Processing window and maps the light level to the brightness of the rectangle. Simple tweak, but makes the changes in sensor value more apparent:

//Processing code from ITP Bluetooth Tutorial
//modified by Kate Hartman 3.17.11

import processing.serial.*;

Serial myPort;  // Create object from Serial class
int val;      // Data received from the serial port

void setup()
size(200, 200);
println(Serial.list());  //list all the available serial ports
//replace the 8 in the next line with your serial port number from the list above.
String portName = Serial.list()[8]; //My device is using “port 8” on my laptop
myPort = new Serial(this, portName, 115200); //115200 is the data rate associated with this Bluetooth module

void draw()
if ( myPort.available() > 0) {  // If data is available,
String myString = myPort.readStringUntil(‘\n’);  //reads serial port until end of line
if (myString != null) { //checks if myString is null
myString = trim(myString);
val = int(myString);  //converts string to integer
background(255);             // Set background to white
/*if (val < 150) {              // If the serial value is 0,
fill(0);                   // set fill to black
else {                       // If the serial value is not 0,
fill(204);                 // set fill to light gray
fill(val); //set the color according to the sensor value
rect(50, 50, 100, 100);

For getting started with Processing, there’s actually a great book called “Getting Started with Processing”, which is available at Creatron and on Amazon. The examples from it are included in the Example menu in the Processing program.

You can find some other notes on the Bluetooth modules here:

Finally, the most important thing to remember when adapting a piece of code to work with these modules is CHECK YOUR BAUD RATE. It must be set to 115200 unless you want to reconfigure the radio. This must be changed in both your Arduino and Processing code.

Yay wireless!

Leave a Reply

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.