Manual control of an Arduino based robot using Android

This project incorporates a simple 2WD robot, a bluetooth module (HC-05/06), and an Android phone to manually control the robots movement. 

IMG_0259

For this example, we are using a “Turtle Bot” with 2 motors, controlled by Arduino pins 6,7,8 and 9 (2 motors, 2 rotation directions each). The Rx and Tx pins for the bluetooth module are controlled by pins 0 and 1, respectively.

The motor driver we will be using is the L298 Dual H Bridge DC Motor Driver. First, connect the motors and voltage source to the L298.

A simple wiring diagram can be found below.

L298N-3x

Connect pins IN1, IN2, IN3, and IN4 to arduino pins 8, 9, 6, and 7.

Note that ENA or ENB are not used in this example. These pins are the step input pins, and are used in combination with IN1/2/3/4 to control speed.

Next, connect the HC-05/06 Bluetooth module to the Arduino Board.

IMG_0254

*****For more detailed info on how to interface the HC-05/06 module with Arduino, Click Here.*****

Copy and paste this into the Arduino IDE:

#include <SoftwareSerial.h>;

SoftwareSerial bluetooth(0, 1); // RX, TX

int BluetoothData;

int Motor1CW = 8;
int Motor1CCW = 9;
int Motor2CW = 6;
int Motor2CCW = 7; 

void setup()
{
 bluetooth.begin(9600);
 pinMode(Motor1CW,OUTPUT);
 pinMode(Motor1CCW,OUTPUT);
 pinMode(Motor2CW,OUTPUT);
 pinMode(Motor2CCW,OUTPUT);
}

void loop()
{
 if (bluetooth.available())
 {
 BluetoothData=bluetooth.read();

 if(BluetoothData=='8')
 {
 digitalWrite(Motor1CW,1);
 bluetooth.println("Motor 1 Forward");
 }

 if(BluetoothData=='9')
 {
 digitalWrite(Motor1CCW,1);
 bluetooth.println("Motor 1 Reverse");
 }

 if(BluetoothData=='6')
 {
 digitalWrite(Motor2CW,1);
 bluetooth.println("Motor 2 Forward");
 }

 if(BluetoothData=='7')
 {
 digitalWrite(Motor2CCW,1);
 bluetooth.println("Motor 2 Reverse");
 }

 if (BluetoothData=='0')
 {
 digitalWrite(Motor1CW,0);
 digitalWrite(Motor1CCW,0);
 digitalWrite(Motor2CW,0);
 digitalWrite(Motor2CCW,0);
 bluetooth.println("MOTORS OFF");
 }

 }
 delay(100);
}

We are now ready to connect your Arduino to your Android!

To get started, download “Arduino Bluetooth Controller” on the Google Play store (free). To pair with the HC-05/06 module:

  1. Open the app.
  2. Type in the passcode (either “1234” or “0000”)
  3. When paired, click on “Controller Mode”

You should now see this:

Screenshot_2015-02-23-13-52-27

In the upper right corner, touch the menu button and input the following commands:

Screenshot_2015-02-23-15-50-44

Hit the “back” button. Now you’ll be able to drive your pet crazy simply by touching the up, down, left, and right arrows on your Android! Hit triangle to stop all movement.

Feel free to leave any questions/comments below. More tutorials coming soon!
TurtleBot

make animated gifs like this at MakeAGif
Advertisements