Controlling Arduino with Bluetooth

By markvillacampa on March 18, 2012 — 2 mins read

Who likes cables? Nobody likes cables. They limit your range of action, they get tangled up and they are simply ugly.

Thats why we invented wireless technologies, like bluetooth. So lets get our hands dirty.

What you need for this simple demo is:*An
Arduino (UNO, Mega, Duemilanove, etc.).

  • A led.
  • A bluetooth module (You can buy it on
    Dealextreme or just do a quick
    Ebay search)
  • A USB Bluetooth dongle in case your computer doesn’t have built-in bluetooth.
    This one from Dealextreme is just fine for $1.80.
  • Mac OS X or Linux.
    Once you have all of this we can start.

First we have to wire the Bluetooth module and Arduino. Do it as shown in the picture:

  • The Rx pin of the Bluetooth to the Tx pin of the Arduino
  • The Tx pin of the Bluetooth to the Rx pin of the Arduino
  • The Vcc pin of the Bluetooth to the 3.3V pin of the Arduino
  • The Gnd pin of the Bluetooth to the Gnd pin of the Arduino

Then connect the Arduino to your PC through USB. The red led of the Bluetooth should start blinking.That means it hasn’t got any active connection.

Now we have to pair our computer to the Bluetooth module. Lets open the Bluetooth assistant of your choice. I’m going to use the one that comes built-in with Mac OS X.

Your Bluetooth might have a different name. In a future post I will explain how to change it but for now lets just use the default one.

Try to attach it and you might get an error. That means you have to enter a different pin. It will be either 0000 or 1234.

Congratulations youre now paired with Arduino. You can check it by opening a terminal window and running the following command

ls /dev/tty.*

You will get a list of the active serial connections. Mine is “/dev/tty.linvor-DevB” and your’s should look similar to this one, containing the name of your Bluetooth module.

Now lets try it. Open Arduino IDE 1.0, and upload this piece of code to your arduino (You might have to disconnect the Bluetooth module from the 3.3V pin in order to upload the code, I was getting an error and this solved it).

void setup() {
  // initialize serial:
  // initialize the led pin
  pinMode(13, OUTPUT);

void loop() {
  while (Serial.available()) {
    char inChar = (char);
    switch(inChar) {
      case '1':
        digitalWrite(13, HIGH);
      case '0':
        digitalWrite(13, LOW);

And connect your Led to the pin 13 and the Gnd next to it of your Arduino (remember, the long pin of the led to pin 13 and the short one to Gnd).

Now go back to Arduino IDE, and choose your Bluetooth serial port under the “Tools > Serial port” menu.

Now open the serial monitor (Tools > Serial monitor). You should notice that the red led of the bluetooth module has stopped blinking. That means we are connected!!

Now when you send a “1” the led on the pin 13 should turn ON, and if you send a “0” it should turn off. Also, it echoes back to the serial monitor whatever you send to the bluetooth module.

You can check that is it really sending your messages through bluetooth and not through the USB by connecting your Arduino to another computer.

This is a very simple example, but now you can control any of your Arduino projects wirelessly, which is way cooler than having wires all around, and for just the $8.20 of a Bluetooth module.