Let's Make Robots!

Programming Arduino via bluetooth

Allows me to program my Arduino via bluetooth, USB not needed any more

I finally figured out how to program my Arduino controlled "Start Here Robot" clone without leaving my chair using bluetooth. Unfortunately it still only works when the Arduino IDE is running on a Linux box.

I ordered an other $6.49 bluetooth module on ebay, this time I payed attention on getting the right type, HC-05 to be precise. See my other bluetooth post to understand why I'm emphasize this.. (http://letsmakerobots.com/node/30345) The HC-05 is well documented, i easily found several PDF's in the Internet, which described the module in great detail. 

The module is quite small, 13x27mm which is a little more than 1/2x1 inch. And it features 34 terminals around. I mounted the module on a piece veroboard with a double sided sticky foam thingy. Then soldered thin wires between the 8 terminals needed and the veroboard. Also on the veroboard i have level shifters, 3.3v regulator and a reset circuit to trigger the Arduino bootloader. All in all I have build this:

Now I put a jumper on the mode pins to enable the onboard command processor, and then I connected the transmit and receive pins to my level shifter cable described here http://letsmakerobots.com/node/29207 and  fired up putty on my linux. Initially the module communicates at 38400 baud

Connected to the port where I put the cable and typed AT. The module went berserk, spraying ERROR all over my terminal. It seems that my putty is sending carriage return when I hit enter nut the module wants a line feed as well. A little reconfigure in putty fixed this.

Ok, now that I have established communication to the command processor on the bluetooth module it's time for the initial configuration. I sent the following list of commands to the module:


Some of these needs a little explanation. ORGL is a factory reset, ROLE is enter slave mode, POLAR configures pin32 to shift from high to low when link is established, UART sets the line speed to 57600 BAUD (but first when module is reset next time), INIT and INQ makes the module listen for incoming connections.

Now I reset the module and reconfigured putty to 57600 BAUD and checkedthat AT still responded with an OK. Leave the putty online, connected to the module via the serial link.

Now scan the ether for your module. On linux its hcitool scan which responds with the address of the module. My module has the address 00:11:11:28:06:25 which is the address you will need for the connection. The command sudo rfcomm bind 3 00:11:11:28:06:25 makes the linux "prepare" the connection. At this point the kernel prepares the device file /dev/rfcomm3, but no connection is established yet. Now fire up another putty and this time make a serial connection to the /dev/rcfomm3. If everything goes well your bluetooth manager will pop-up and request you a pin code. for the HC-05 it defaults to 1234. After you have entered the pin, the two puttys are connected, and I were able to send data from the one to the other.

Now, disconnect the serial cable and connect the bluetooth interface to your Arduino. Pin numbers are on the schematic. It helps if you have a program on the Arduino which slowly counts and outputs the result on the serial link. Something like this:

void setup()

void loop()
  static int i;

Now you should see the output of your program in the putty connected to /dev/rfcomm3. And when you close the putty and open it again it should trigger a reset, making the counter starting over.

Now its time for tweaking the Arduino IDE to program through the bluetooth link. This requires a little hack to the IDE, which I were not able to get working on the windows side, which is why this guide is considered linux only.Btw. I'm working in version 0022 of the IDE. I still don't like the new version 1 thing!

A little background info may be needed here. Then the OS, linux or windows, opens the bluetooth interface, the lower stuff in the system establishes the actual link. This is an automatic process. This also happens if the Arduino IDE opens the interface. Sounds good, but its not. Problem is that the IDE scans all serial ports on the system, and it does this by opening them. Just a fast open-close, but this is enough to trigger the automatic establish bluetooth link process, which takes a second or two. And since the scan is way faster than this it often clutters up the link.

On windows the bluetooth interface gets a serial port name, eg. COM21. and this gets detected, and smashed by the IDE. On linux the devices (thats what we call interfaces there) gets named /dev/rfcomm3, which the Arduino IDE DOES not find and hence wont smash! Perfect! Ok the IDE cannot select the port, how does I then actually program my Arduino though a port thats not visible in the IDE?? Hey its linux, it hackable!

I located the version of avrdude shipped with my Arduino IDE, it's under $ARDUINO_HOME/hardware/tools/avrdude. here I renamed the avrdude program to to avrdude-real and then put a little perl program there instead:

use strict;
use warnings;

foreach (@ARGV)

my @cmd = ("$0-real", @ARGV);

#exec @cmd;
system @cmd;
printf "Programming %s\n", $? ? 'FAILED' : 'SUCCESS'

Pay attention the the regexp substitute there. I replace the device /dev/ttyS0 with my bluetooth devicde. Now I simply tell my IDE to program an Arduino on /dev/ttyS0, the my wrapper program translates this to /dev/rfcomm3 and avrdude programs away.

Now what about the automatic reset triggering? Yes it woks. When avrdude opens the device, it gets blocked until the link is established, typically 1.2 second. And when link is ready, the bluetooth module lowers pin32, which through the cap triggers the reset pin on the Arduino. with 1uF, the timing seems to be just right!

Ok, the using a different port to keep the IDE from breakign everything is an ugly hack, but I have not been able to locate a better solution, and nor make it work in windows.

I see a few options here

  1. Fixing the IDE to not probing everything but taking the port to be used as a configuration parameter. Requires a JAVA hacker, which it NOT me!
  2. Using an other IDE than the official Arduino one. It have been done, but its not beginner friendly.
  3. Using Linux. Oh yes, thats the way to go anyway. ( yes, I'm a fanboy, I admit it!)




Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

great post..certainly helps a lot..Thanks mogul for posting this

I also made an experimental Android app.

It uses Google Blockly to generate a Arduino program.
The Arduino program is compiled using avr-gcc for Android.
Uploading to Arduino works over bluetooth with the STK500 rotocol.

Hi, whatever I do, the module responds OK to only the "AT" command.

all other commands end up with no response.

I'm using the HC-06 module, but it is the same except it can do only slave mode. any ideas?

The HC-06 is very different:

  1. AT commands don't have to end with \r\n (carriage return and line end)
  2. Connection status indicator LED is on pin 24
  3. Less configuration possibilities

Check for more info here: http://wiki.pinguino.cc/index.php/SPP_Bluetooth_Modules


I finally managed to get this working for my Arduino UNO aswell :)

Commands I used:
# to get the bluetooth device address, I will refer to it as <ardu-bt-addr>
$ hcitool scan
# to get your bluetooth device address, I will refer to it as <my-bt-addr>
$ hciconfig -a | grep "BD Address"
# to add the pincode of the bluetooth
$ echo "<ardu-bt-addr>
1234" > /var/lib/bluetooth/<my-bt-addr>/pincodes
# to bind the bluetooth to /dev/rfcomm0
$ rfcomm bind 0 <ardu-bt-addr>

Makefile I used:

Problems I got:

  1. The Arduino software serial library didn't work well, it gave weird output. I ended up using a 3.3V usb to serial board to configure the bluetooth with AT commands.
  2. I used a Makefile for Arduino that had "stty -F /dev/ttyACM0 hupcl" before the upload which didn't allow avrdude to connect to Arduino. I ended up removing this line.


Hi !

Congratulations for your post! I was looking for something like this around so it's great you posted it!

I found an offer of this HC-05 bluetooth module in eBay http://www.ebay.com/itm/180957186752 so I'm thinking about taking it and test it ;-)

Kind regards,


Hi !

Congratulations for your post! I was looking for something like this around so it's great you posted it!

I found an offer of this HC-05 bluetooth module in eBay http://www.ebay.com/itm/180957186752 so I'm thinking about taking it and test it ;-)

Kind regards,


Hi Mogul,

First off, Thank you for this wonderfull post.
I am in the possession of a HC-05, and a bluetooth 2.1 dongle with the toshiba stack installed for it.

I verified I'm able to communicate with the HC-05.

I have pin 32 of the HC-05 wired up to the reset pin of a avr tiny through a 1uF capacitor.
The weird thing is that it will reset when I disconnect from the HC-05 NOT when I pair with the HC-05.

Did you see similar behavior? I would expect this behavior since I was always under the impression that in order to reset the device you needed to deliver a LOW signal to the reset (which has been pulled high through a resistor).

So I'm really wondering how you got this to work? :) I'm really thinking about using a inverter, which I rather woudn't.

In the comments below see...

Yes, pin32. and AT+POLAR=1,0 reverses its way of working, making it suitable for use as a reset trigger.

Confirmed AT+POLAR=1,0 does indeed reverse the behavior.

Should have read better, thanks for pointing it out rogue.