Introduction: Arduino From Android Over Bluetooth

As my first instructable, I'd like to show how to connect to an arduino for I/O from an android device quickly and easily.

For the following steps we'll need:

  • An arduino compatible device
  • An HC-05, HC-06 or similar bluetooth to serial module. Be sure to get one with the breakout board and the pin header to connect to. You can find these from a number of suppliers.
  • A solderless breadboard (you can solder the connections if you want of course, but for the tutorial I'll be using a breadboard)
  • You'll also need a 1 kiloohm resistor and a 2 kiloohm resistor. I'm using a 2.2 k resistor because it's all I had lying around, I think it will be close enough for this purpose.

Step 1: Connect the HC-05

Plug the HC-05 into the breadboard such that you'll have enough room to make all your connections. We're going to use the 1 and 2 k resistors to make a voltage divider on the breadboard. That will prevent the 5 V logic levels of the arduino from damaging the 3.3 V HC-05 module.

Step 2: Make the Voltage Divider Step 1

Connect the RX pin of the HC-05 to the GND pin, using the 1k resistor.

Step 3: Making the Voltage Divider Step 2

Connect the RX pin of the HC-05 to another part of the breadboard using the 1k resistor. This is where the TX pin of the Arduino will be connected.

Step 4: Connect the Arduino to the Breadboard

You will have to make the following connections:

  • Arduino RX pin -> HC-05 TX pin
  • Arduino TX pin -> 1 kOhm resistor on the breadboard
  • Arduino 5V pin -> HC-05 VCC pin
  • Arduino GND pin -> HC-05 GND pin

Step 5: Download the BlueDentist Library and ToothFairy Free App

You can download the library I'm going to use here:

BlueDentist Downloads

Download the BlueDentist arduino library and unzip it. You will have a folder that you can copy into your arduino/libraries directory. It if arduino IDE is open, restart it now. BlueDentist should show up for you to import into your sketches now.

Next you will need the app to connect to the arduino using the library you just installed. I put the free version of the app for this tutorial on the google Play Store:

ToothFairy Free

In the free version your interface is limited to 3 widgets, if you decide you want the full version it's also on the play store: ToothFairy

Step 6: Create an Arduino Sketch

Make a new arduino sketch. I have a "Hello World" sketch I created for this instructable. If you want to just download the file it is at instructable.ino.

#include

BlueDentist *myDent; BDLogField *myLog; BDBTN *myBtn;

void setup() {

myDent = new BlueDentist(9600); //9600 Baud, default for HC-05 change if your module is a different baud rate

myLog = new BDLogField("log");//name is log, but this can be anything. Remember widget names must be unique,

//and should be as short as possible. For more details on that read the documentation at avrthing.com/toothfairy

myBtn = new BDBTN("Hello");

myDent->add(myLog);

myDent->add(myBtn);

}

void loop() {

if(myBtn->getPresses())

{

myBtn->reset();

myLog->println("hello world");

}

myDent->run();

}

Step 7: Upload the Sketch

Depending on your device you may have to disconnect the HC-05 module to upload correctly. Mine worked fine with it still connected, but if you do disconnect it the easiest way is to pull the whole module out of the breadboard, and leave the wires in place.

Step 8: Pair the Bluetooth Module to Your Phone

In Settings->Bluetooth you should see a list of available devices. As long as your HC-05 module is powered, it will show up as HC-05. I changed the name of my module using the AT commands, so my module is showing up as "FREEZERTRON". Select your module to pair the device. It will ask you for a PIN, the default for the HC-05 is 1234.

Step 9: Launch ToothFairy

Launch the ToothFairy app. You will see a screen with two buttons. One says enable bluetooth, that button won't do anything right now, since in the last step we enabled bluetooth and paired the device. The other button will say "choose device".

Step 10: Select Your Device

After pressing the "Choose Device" button you will see a list of paired bluetooth devices. Select your arduino module.

Step 11: Play With the Hello World Sketch

You will see a button, every time you press it, "Hello world" will print into a text field above the button. Once the text field is 7 lines it will stop getting bigger, and become scrollable.

Now that you can control your projects from your phone, do something cool and post an instructable about it!