loading
Picture of Bluetooth Controlled Arduino RC Car
This Project is something i started for my Microcontroller class. We were tasked with picking either Arduino or Raspberry pi and then get the MCU to control an RC car or do something fancy with an RC car; Then once we decided what we were going to do we were to make a tutorial so that we too could show others what we were doing. I chose to control the remote control car using my Android phone via bluetooth.

For this project you will need these parts(A link to place where to get them will be provided if possible):
1 x Arduino UNO R3 || http://www.adafruit.com/products/170
1 x Motor Shield || http://www.adafruit.com/products/1438
RC Car or Motor or Alternative || Hobbyist Store, Adafruit, Toy Store
RC Car Battery 5v+ || Should come with the RC car if you buy one.
1 x HC-06 Bluetooth Module or Similar || Hobbyist Store, Ebay
1 x Female to female 4 pin cable || N/A, mine came with the bluetooth module
Jumper Cables || Hobbyist Store, Ebay
9v Battery pack || http://www.adafruit.com/products/67
Android Device
 
Remove these adsRemove these ads by Signing Up

Step 1: The Motor shield.

Picture of the Motor shield.
First of all we need to setup the Arduino and Motor shield. If you bought the motor shield you're going to have to solder, Grab your solder and you soldering iron and follow this tutorial: http://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/install-headers
  

Step 2: Setting up the Arduino Board

Picture of Setting up the Arduino Board
2013-11-15 09.25.27.jpg
Now that you have got your motor shield stack it on top of the Arduino board. Once you have done this you need to setup the HC-06 the correct pins. Attach the female to female jumper cable to the HC-06, than put jumper cables into the other end. on the bottom of the HC-06 there's directions for what goes where VCC And GND are for power, and TXD and RXD are for transmitting and receiving. On the Arduino board; The VCC goes into either the 3v or 5v pin, and the GND goes into the GND PIN, thus powering your bluetooth module. now for the TXD and RXD, the TXD goes into the 2nd digital pin, and the RXD goes into the 3rd digital pin.

Attach motors to M1 header and M3 header. Now plug in power for the Arduino and the car battery to the power header, don't forget to take off the VIN Jumper so that the motor shield is powered separately!

Step 3: The Arduino Code part 1

Picture of The Arduino Code part 1
The Arduino Code is Relatively simple to understand, once we have declared the things such as motors and pins we can start making serial connections for the bluetooth serial connection; And we can set speeds and turn the motors on, this is all done in the setup function. it should look a little like this so far: 

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
#include <SoftwareSerial.h>

int bluetoothTx = 2;
int bluetoothRx = 3;

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *backMotor = AFMS.getMotor(1);
Adafruit_DCMotor *frontMotor = AFMS.getMotor(3);

void setup()
{
  //Setup usb serial connection to computer
  Serial.begin(9600);

  //Setup Bluetooth serial connection to android
  bluetooth.begin(115200);
  bluetooth.print("$$$");
  delay(100);
  bluetooth.println("U,9600,N");
  bluetooth.begin(9600);


  AFMS.begin();  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz

  // Set the speed to start, from 0 (off) to 255 (max speed)
  backMotor->setSpeed(255);
  backMotor->run(FORWARD);
  // turn on motor
  backMotor->run(RELEASE);

  frontMotor->setSpeed(255);
  frontMotor->run(FORWARD);
  // turn on motor
  frontMotor->run(RELEASE);

}


Now we're a step closer to being able to receive messages from our android device. Firstly to start reading the message send via bluetooth and writing to usb serial and it looks a something like this

void loop()
{
  //Read from bluetooth and write to usb serial
  if(bluetooth.available())
  {
    char toSend = (char)bluetooth.read();
    Serial.print(toSend);
  }

// Only really used to test to see if the Arduino is receiving the correct message
//Read from usb serial to bluetooth
if(Serial.available())
  {
    char toSend = (char)Serial.read();
    bluetooth.print(toSend);

  }
}

A summary for what our code does so far is: Receives a message from an android device that is running the correct app  via Bluetooth and then prints it to the serial monitor.  we'll touch on getting the motors to work in part Two of the Arduino code

Step 4: The Arduino code part 2

Picture of The Arduino code part 2
to get motors working for you need to add code to the if(Bluetooth.available) code so it will look like this:

if(bluetooth.available())
  {
    char toSend = (char)bluetooth.read();
    Serial.print(toSend);


    // After the android device sends the data the arduino takes the information and reads it as a char,
    // This code is here to read that data and turn it into actions for the motors.
    if(toSend == 'f'){
      backMotor->run(FORWARD);
    }

    if(toSend == 'b'){
      backMotor->run(BACKWARD);
    }

    if(toSend == 'l'){
      frontMotor->run(FORWARD);
    }

    if(toSend == 'r'){
      frontMotor->run(BACKWARD);
    }

    if(toSend == 'rf'){
      frontMotor->run(BACKWARD);
      backMotor->run(FORWARD);
    }

    if(toSend == 'lf'){
      frontMotor->run(FORWARD);
      backMotor->run(FORWARD);
    }

    if(toSend == 'rb'){
      frontMotor->run(BACKWARD);
      backMotor->run(BACKWARD);
    }

    if(toSend == 'lb'){
      frontMotor->run(FORWARD);
      backMotor->run(BACKWARD);
    }

    if (toSend == 's'){
      frontMotor->run(RELEASE);
      backMotor->run(RELEASE);
    }

  }

in the if statements that turn the motors there are letters such as "f" for this first if statement, this is the message that is received from pressing the forward button on the Android App! Now that we can read a message sent from an Android device we can run an app to send these messages!


Step 5: Android App!

Picture of Android App!
Unfortunately due to time constraints I'm not providing a tutorial on the android app, however i will provide the .apk and the java project for it so you can see what i have done. to open the java project you're required to have java and the Android SDK tools
you can download it as a bundle here: http://developer.android.com/sdk/index.html

the app itself is easy to use, simply pair your Android device and the Bluetooth module you used together; once you have paired to two devices together launch the app and enter the name of the paired device, hit the Connect Button or the "C" Button wait for a message to say that the devices are connected. Now that its connected you can control your Arduino RC car with your Android Device!!

Step 6: Hopefully this helped!

Well hopefully this helped, it sure would have helped me if i had it when i was making the RC car!

Here are some links that are useful and for the code!
http://www.mediafire.com/download/0sf50f7vp5csn6c/bluetoothRC.apk
http://www.mediafire.com/download/batlk0hit55yoz8/blueToothRC.zip
http://www.mediafire.com/download/hzi93iigvbwrtr8/ArduinoRCcar.ino
http://www.adafruit.com/
http://developer.android.com/sdk/index.html
http://arduino.cc/



Thank you for reading my tutorial or guide, Constructive criticism is welcomed! Thanks again! 
uralliboo4 months ago

Adafruit Motor Shield.h libraries ??

shahreenr4 months ago

i need help in android application as i am new for this. I am not able to download .apk file.

help me.

sfc.renales4 months ago

can i also use arduino atmega 168 ?

ishan5536 months ago
ishan5536 months ago

i keep getting the error message

'Adafruit_MotorShield' does not name a type

can you please help me

and btw im using this (http://www.channypicture.com/pic/Uploadfile/6/SKU113900/13CDCFCE33CECD330361CE3353C8CEC8C9033BC7A023.JPG) shield

one more link

http://www.ebay.com/itm/Motor-Drive-Expansion-Shield-Board-Module-L293D-For-Arduino-Duemilanove-Mega-UNO-/221605183415?pt=LH_DefaultDomain_0&hash=item3398b2bfb7

plz help me I'm a complete beginner.

MelodicGhost8 months ago

Please someone, post links to the libraries that we need to have for this to work.

louie_yo1 year ago
hi there! awesome project. instead of arduino uno, can i use arduino leonard? sorry for the noob question. Thanks!

Yes, yes you can

I use BlueTerm app. It works just fine!

I use BlueTerm app. It works just fine!

fordchick11 months ago

awesome how you get it to do bluetooth control

Can anyone help me with this errors please ..its my first project with the arduino

ArduinoRCcar.ino:3:45: error: utility/Adafruit_PWMServoDriver.h: No such file or directory

ArduinoRCcar:10: error: 'Adafruit_MotorShield' does not name a type

ArduinoRCcar:11: error: expected constructor, destructor, or type conversion before '*' token

ArduinoRCcar:12: error: expected constructor, destructor, or type conversion before '*' token

ArduinoRCcar.ino: In function 'void setup()':

ArduinoRCcar:27: error: 'AFMS' was not declared in this scope

ArduinoRCcar:31: error: 'backMotor' was not declared in this scope

ArduinoRCcar:32: error: 'FORWARD' was not declared in this scope

ArduinoRCcar:34: error: 'RELEASE' was not declared in this scope

ArduinoRCcar:36: error: 'frontMotor' was not declared in this scope

ArduinoRCcar.ino: In function 'void loop()':

ArduinoRCcar:55: error: 'backMotor' was not declared in this scope

ArduinoRCcar:55: error: 'FORWARD' was not declared in this scope

ArduinoRCcar:59: error: 'backMotor' was not declared in this scope

ArduinoRCcar:59: error: 'BACKWARD' was not declared in this scope

ArduinoRCcar:63: error: 'frontMotor' was not declared in this scope

ArduinoRCcar:63: error: 'FORWARD' was not declared in this scope

ArduinoRCcar:67: error: 'frontMotor' was not declared in this scope

ArduinoRCcar:67: error: 'BACKWARD' was not declared in this scope

ArduinoRCcar:71: error: 'frontMotor' was not declared in this scope

ArduinoRCcar:71: error: 'BACKWARD' was not declared in this scope

ArduinoRCcar:72: error: 'backMotor' was not declared in this scope

ArduinoRCcar:72: error: 'FORWARD' was not declared in this scope

ArduinoRCcar:76: error: 'frontMotor' was not declared in this scope

ArduinoRCcar:76: error: 'FORWARD' was not declared in this scope

ArduinoRCcar:77: error: 'backMotor' was not declared in this scope

ArduinoRCcar:81: error: 'frontMotor' was not declared in this scope

ArduinoRCcar:81: error: 'BACKWARD' was not declared in this scope

ArduinoRCcar:82: error: 'backMotor' was not declared in this scope

ArduinoRCcar:86: error: 'frontMotor' was not declared in this scope

ArduinoRCcar:86: error: 'FORWARD' was not declared in this scope

ArduinoRCcar:87: error: 'backMotor' was not declared in this scope

ArduinoRCcar:87: error: 'BACKWARD' was not declared in this scope

ArduinoRCcar:91: error: 'frontMotor' was not declared in this scope

ArduinoRCcar:91: error: 'RELEASE' was not declared in this scope

ArduinoRCcar:92: error: 'backMotor' was not declared in this scope

I can't find the BluetoothRCController app on my Sony Xperia S ..any suggestions please?