2012-08-01



Having trouble getting your Bluetooth module or Bluetooth Mate to work with Arduino?
This tutorial will help you, and it won't take long!

I will explain 3 major steps:

Getting the module paired with your computer.

Getting your arduino board to communicate with the computer over bluetooth.

Uploading sketches to your arduino board over bluetooth, using the bootloader.

Hardware

RN-42 Bluetooth module (This is also valid for the Bluetooth Mate)
Arduino Pro Mini
FTDI USB to Serial converter
Bluetooth Dongle

Before we start, here is my setup.
The Bluetooth Module is directly connected to the Arduino Pro Mini, and the whole thing is powered from the FTDI USB to Serial Converter.



Getting the module associated with your computer

The Arduino Pro Mini and the Bluetooth module connect directly.

Step 1: Power the module

You will have the orange LED blinking twice per second, the one you want to convert to a fixed green!

Step 2: Plug the Bluetooth Dongle to your computer

Drivers should install automatically. I am using Windows Seven, so I don't really know how it will work on other OS, but it shouldn't be that different.
A Bluetooth icon should have appeared.

Step 3: Open the Bluetooth Menu

Right click on the Bluetooth icon and select "Show Bluetooth Devices".
My Windows Screenshots will be in French, but you will obviously have the same layout.



Step 4: Click on Add a Device

 

Step 5: Pair the Device!

Wait until the Bluetooth Module is discovered, then double click on it or select it and press Next.

Next thing Windows asks you, is how you want to pair the device.
Select this option:

Step 6: Done!

Your Bluetooth Module is now paired. Close the window, and now onto part 2!

Getting your arduino board to communicate with the computer over bluetooth

Step 1: Know the given COM port of your module

Go back to your Bluetooth Devices (Right click on the Bluetooth Icon, then Show Bluetooth Devices).

Right click on your newly associated Bluetooth Module and select Properties.
Select the Services tab. The "SPP" (Serial Port Profile) service and its associated COM port are what you will be using.
Remember the number of the COM port as we will use it to communicate with the module later.

Note: The following windows screenshots will be in French, but the layout and logic remain the same.

Step 2: Launch Arduino IDE

At this point, since Arduino tries to communicate with the open COM ports on startup, you should be told that a Bluetooth Device is trying to connect.
Click on the pop-up message.

Then type in 1234 for the code (this is the default Roving Networks bluetooth modules PIN) and hit Next.

It should succeed and your Bluetooth Module is now ready to be used with Arduino!

Step 3: Upload this small program to your Arduino board

I disconnected the Bluetooth Module for that, and uploaded the sketch using the FTDI USB to Serial converter, plugged directly into the Arduino Pro Mini. (Make sure you select the right board and COM port in the Tools menu.)

Step 4: Try the Bluetooth!

If you disconnected the Bluetooth Module, put that back together (like in the setup shown in the picture at the beginning of this tutorial).
In Arduino, in the Tools menu, select the COM port associated with your Bluetooth Module SPP profile ( COM6 in my case).

Note: I noticed that the Arduino Tools menu responds very slowly when a bluetooth module is actively associated with the computer. Just be patient, the menu will show up eventually.

Now open the Arduino Serial Monitor. It might take a few seconds, but once it does, take a look at your Bluetooth Module.

The Green LED is ON!!

Now type in anything you want in the Serial Monitor, hit Send and you will see it looped back to you!

Uploading sketches to your arduino board over bluetooth using the bootloader

It wasn't that hard, was it?
Now we will take it to the next step, which is remotely configuring the Bluetooth Module and uploading your Arduino Sketches to your Arduino board over Bluetooth!

Sound exciting? Let's do it!

Step 1: Enter the Bluetooth Module command mode

If the Arduino Serial Monitor is still open, close it. You might want to wait a few seconds for the COM port to be freed.

We will open the Serial Monitor again. But wait. By default, the Bluetooth Module allows you to enter command mode up to 60s after a connection is made.
So, you will have 60s to send this text after opening the Serial Monitor:
$$$

IMPORTANT: You MUST have "No line ending" and "115200 baud" selected

Hit Send,and you should receive the acknowledgement from the Bluetooth Module, and the onboard Orange LED should blink at a rate of 10 times/second.

Now you have all the time you want to configure it. There are a lot of configurable options!

Step 2: Change the Baud Rate

IMPORTANT: Now you MUST have "Newline" selected

The thing that we want changed right now is the baud rate, because the Pro Mini bootloader has a defined baudrate of 57600.
Send:
SU,57
and hit Send (with "Newline" selected, this is important)
You should receive "AOK".

Now send
D
You will receive a bunch of basic bluetooth configuration parameters. Make sure that the Baud Rate is now 57,6. Your screen should then look like that:

Step 3: Upload sketches over Bluetooth

Close the Serial Monitor.
Modify the previous Arduino code so that the baudrate will now be 57600, and let's put a different message:

You will have to hit upload in Arduino, and you will have to manually press the Reset button on your Arduino board.
The time when you will have to press that Reset button depends on your board, and you will have to experiment until you get it right.

My best advice would be: Don't be hasty.
For my setup, I press it just after the Green LED lights up for the second time.

Alright, I guess that's it!
Jayconsystems and myself hope that we have helped a lot, and saved you some valuable time!
Make sure you check the Bluetooth User Manual for all available commands! And don't forget, no added character (No line ending) with $$$ to enter command mode, and then a line return to validate every command.

Have fun with your bluetooth module! And we would be happy to hear back from you, and your amazing projects on our forum!

 

Show more