Introduction: Bluetooth Robot With Computer Interface

Control the motion of a two-wheeled robot wirelessly from a virtual remote on the computer screen. Using the bluetooth HC-06 receiver and two continuous rotation servos, an Arduino based robot can be programmed to receive values over bluetooth and control the robot accordingly. These control values will be sent to the Arduino from the Serial port on the open source app Processing.

Step 1: Getting the HC-06 Receiver Working

The Bluetooth module has two functions:

1. Receive data from the computer via Bluetooth

2. Send that data to the Arduino

When a Serial connection is initialized (Serial.begin ) and the Arduino is connected to the computer, by default the communication is between the computer and the Arduino via the USB-Arduino cable. However, pins 0(Rx) and 1(Tx) can instead be used for serial communication, overriding the serial connection with the computer. This is how the Bluetooth module HC-06 sends data to the Arduino that it has received from Bluetooth. After looking at the datasheet, the baud rate for the HC-06 module is 9600.

Connecting Bluetooth:

Connecting pins:

HC-06 pin: Arduino pin:

VCC 3.3V

GND GND

Rx Tx (pin 1)

Tx Rx (pin 0)

Code:

void setup() {

// initialize serial:

Serial.begin(9600);

// initialize the LED pin

pinMode(13, OUTPUT);

}

void loop() {

while (Serial.available()) {

char inChar = (char)Serial.read();

switch(inChar) {

case '1':

digitalWrite(13, HIGH);

break;

case '0':

digitalWrite(13, LOW);

break;

}

Serial.println(inChar);

}

}

* note: if you are having trouble uploading this program unplug the 3.3V wire while it is uploading

Now the Arduino and HC-06 are ready to read data and turn on and off an LED. To send data to the HC-06, use the Serial Monitor built into the Arduino software.

Go into settings and connect the HC-06 as a Bluetooth device (default password = 1234).

Once the sketch is uploaded to the Arduino via the USB Serial Port, change the Serial port on the Arduino software to the Bluetooth HC-06. (tools > Serial Port). Do not upload the sketch again. Open the Serial Port and you can type a 1 or a 0 to turn on or off the LED.

It is important to note that there is nothing inherently Arduino-specific about the Serial Monitor. It transmits data to the selected Serial Port. For uploading sketches and sending data directly to the Arduino, the USB port is used. However, the Serial Monitor software can write to and receive from any of the computer ports.

If you are having trouble…

http://markvillacampa.com/2012/03/18/controlling-arduino-with-bluetooth/

Step 2: Constructing the Robot

Materials:

2 continuous rotation Servos

Material for base ( I used poster board)

Tape and glue

Arduino

HC-06

9 volt battery and 9-volt battery connecter

Breadboard

Step 1: Wiring.

Follow the diagram. On the HC-06 connect the following pins.

Connecting pins:

HC-06 pin: Arduino pin:

VCC 3.3V

GND GND

Rx Tx (pin 1)

Tx Rx (pin 0)

Step 2: Constucting the robot.

Glue the two Servos to the sides of the poster board near the back. On the center of the board tape down the Arduino board, breadboard, HC-06, and battery however it fits. It helps to keep the weight centered around the wheels.

Step 3: Writing the Processing Code

Processing ™ is a programming environment with similar syntax to the Arduino IDE. It has the capabilities to interact with serial ports, create visual displays, receive user feedback, etc. We can use Processing™ to send data to the Arduino HC-06 Serial Port. The details of the processing language can be found athttps://www.processing.org/reference/

Instead of using the built-in Arduino Serial Monitor, the Serial Monitor of Processing can be used to write a character 0 through 5 based on which button is clicked. Make sure to change the name of the Bluetooth Serial port to the correct name. Refer to step 1 for help finding the name.

Step 4: Writing the Arduino Code

The Arduino Code is pretty straight forward. It uses the Serial Library to read data from the bluetooth module. Based on the value the Arduino is sent, it exectutes one of the 5 functions: forward, backwards, right, left, or stop.