Introduction: MIT Android App Using the Bluetooth HC06 to Connect to an Arduino Uno

Special Thanks to these Online Resources for getting me started...

Step 1: Materials:

HC-06 Bluetooth device

Android Phone --- I have an HTC 8, emulators for iPhones are available but I didn't go that route so I'm not sure.

MIT app inventor

Arduino Uno

Potentiometer --- get the signal using analogRead()

Button --- get the signal using digitalRead() ---view the text ("HIGH" or "LOW")

LED --- send a signal using digitalWrite() ---press a button on the phone to turn on the LED

RGB --- send a signal using analogWrite() ---use the slider on the phone to adjust the color of the RGB LED

Step 2: Bluetooth HC - 06

Bluetooth Tutorial:

1) How does it work?

  • It has a Receiver...which acts as a good listener for any incoming signals.
  • It has a Transmitter...which acts as a good speaker for sending outgoing signals from the device

2) Make sure that the connection is Rx to Tx for both devices. Why?

    • The Tx (good speaker) on the bluetooth should talk to the Rx (good listener) on the arduino.
      • yellow wire
    • The Tx (good speaker) on the arduino should talk to the Rx (good listener) on the bluetooth.
      • green wire
    • If both sides talk, its hard to interpret the signal.
    • If both sides listen, no signal is being sent.

3) Before you upload the code, remove the Tx and Rx wires from the arduino. When you removed the wires, upload the code. When its done uploading, you need to plug the wires back into the arduino.

Step 3: Wiring the Circuit

Button with 10K resistor --- digitalRead --- pin 2

Potentiometer with 10K resistor --- analogRead --- pin A0

LED with 220 resistor --- digitalWrite --- pin 13

RGB LED with three 220 resistors on each terminal --- analogWrite --- pin A2, A1, A0 for red, green, blue

Step 4: Arduino Code

Step 5: MIT App Inventor - Make the GUI

I created a GUI on MIT App inventor. I've found it useful to start with the GUI so that I understand what I want to do and think through how before I write the block code.

Phone --> Bluetooth --> Arduino

I used digitalWrite for pins 12 and 13 using buttons to turn the LED's on/off. I also used sliders to analogWrite for pins A0, A1, A2. This tool could be used for controlling an RGB, a servo for a robot, or whatever you're mind thinks up.

Arduino --> Bluetooth --> Phone

The bottom section is my analogRead on pin A5. In my arduino code, I simply write Serial.print to send the data between both units. You could very easily write some arduino code that does something similar for digitalRead and add another label to the GUI.

The non-visible components of this GUI are:

  • bluetooth
  • clock
  • web

You will need these components to find all the functions that I used in the block code above.

Step 6: MIT App Inventor - Write the Block Code

1) Set up the Bluetooth Connection.

  • If the search button is pressed on your phone, it will create a listpicker (dropdown list) of all the bluetooth signals that it picks up. You can choose one of the items on your phone.
  • If the connect button is pressed on your phone, After you select an item from the listpicker, it will call the function .connectAddress to connect you to your phone to the bluetooth device. The state of the button is changed to different texts and colors to help visibility on the GUI.

2) digitalWrite

  • The code uses the password (A or a) to signify ON/OFF. This uses bluetooth.sendText to transmit a unique signal to the arduino. We wrote arduino code that looked for either an A or a. It will do what we say because this code is found in both places.

3) analogRead and digitalRead

  • Use bluetooth.receiveText to get the current value from an analog signal or digital signal. Assign the label.text as the current value so that you get a constant update of values.

4) analogWrite

  • The code only shows only the X analogRead value. You will need to replicate that code for all three X, Y, Z. if you want to control the RGB or multiple sensors. The arduino code is written with these specific id's so that communication is interpreted correctly.