How to Control an Arduino Car Via Bluetooth (for Beginners)

161K299177

Intro: How to Control an Arduino Car Via Bluetooth (for Beginners)

All we know that Arduino is an excellent prototyping platform, principally because it uses a friendly programming language and there are a lot of extra incredible components that provide us great experiences.
We can integrate the Arduino with differents shields or modules and build fantastic things. In this project i will show you how use the Bluetooth module to control a robot platform through commands coming from a smartphone.

STEP 1: Parts

Hardware:

  1. Arduino Uno
  2. Motor Shield L293D Driver
  3. Bluetooth Module
  4. Robot platform

Software:

  1. Arduino IDE
  2. Bluetooth RC Controller (you can download this app here)

STEP 2: Mount the Hardware

The mounting of the robotic platform is very easy. If you buy one like that, you will receive a manual with all steps.

To connect the electric circuit, you have to fit the shield on the Arduino and then connecting the motors to the shield. After that you have to connect the bluetooth module. The module pins depends on what you are using, but basically it has: VCC (connected to the 5V pin of the Arduino), GND (connected on GND on Arduino), RX (connected to the TX pin of the arduino) and TX (connected to the RX pin of the Arduino).

STEP 3: Software

The code is also uncomplicated.

- To control the motors, i used the library <AFMotor.h>.

- The communication between the smartphone and the Bluetooth module was done using the serial communication arduino.

- The app "Bluetooth RC Controller" send to the bluetooth module the following commands:

  • Forward -> F
  • Back -> B
  • Left -> L
  • Right -> R
  • Forward Left -> G
  • Forward Right -> I
  • Back Left -> H
  • Back Right -> J
  • Stop -> S
  • Front Lights On -> W
  • Front Lights Off -> w
  • Back Lights On -> U
  • Back Lighst Off -> u
  • Horn On -> V
  • Horn Off -> v
  • Extra On -> X
  • Extra Off -> x
  • Speed 0 -> 0
  • Speed 10 -> 1
  • Speed 20 -> 2
  • Speed 30 -> 3
  • .
  • .
  • .
  • Speed 90 -> 9
  • Speed 100 -> q
  • Stop All -> D

In this project was used just the basic commands: Forward, Back, Left and Right.

The entire code is available for you to download.

STEP 4: You Are Done


Now you have all you need to build your own robot controlled by a smartphone via Bluetooth. Easy and Funny.

THANK YOU

150 Comments

Please tell me the connections between Arduino ,hc 05 and other

i using the same things like you did, however my bluetooth module havent "blink" for should i said it not on. i connect the Vcc and GND the way it should be but the RX and TX are the one that i didnt understan. i using a arduino mega and its have 3 port of both RX and TX and i connected it at RX1 and TX1. still nothing happen. can you help me out ??

ok i just solve that, my mistake. but now the robot didnt move even its already be connected

Bro at the end of each code you entered the word "end", what will happen if u dont used "end" ? Will the mortors will keep on running
please add diagram of connection of cables

I'm getting these characters on the serial monitor when I press the arrows:
Y
รพ
Y
Y
Y
Y
Does anyone know why?

Hi, when I compile the sketch I get a lot of error messages. Could you please help me?

Arduino: 1.8.1 (Windows 7), Board: "Arduino/Genuino Uno"

C:\Users\user\Documents\Arduino\libraries\arduino_723047\src\Temboo.cpp: In member function 'int TembooChoreo::run(IPAddress, uint16_t, uint16_t)':

C:\Users\user\Documents\Arduino\libraries\arduino_723047\src\Temboo.cpp:281:52: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

if (!m_client.findUntil("HTTP/1.", HTTP_EOL)) {

^

C:\Users\user\Documents\Arduino\libraries\arduino_723047\src\Temboo.cpp:301:62: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

if (m_client.findUntil("x-temboo-time:", HTTP_EOH)) {

^

C:\Users\user\AppData\Local\Temp\cchwJani.ltrans0.ltrans.o: In function `__static_initialization_and_destruction_0':

C:\Users\user\Documents\Arduino\FOF4YFTIA0WX947/FOF4YFTIA0WX947.ino:7: undefined reference to `AF_DCMotor::AF_DCMotor(unsigned char, unsigned char)'

C:\Users\user\Documents\Arduino\FOF4YFTIA0WX947/FOF4YFTIA0WX947.ino:8: undefined reference to `AF_DCMotor::AF_DCMotor(unsigned char, unsigned char)'

C:\Users\user\AppData\Local\Temp\cchwJani.ltrans0.ltrans.o: In function `Stop':

C:\Users\user\Documents\Arduino\FOF4YFTIA0WX947/FOF4YFTIA0WX947.ino:74: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'

C:\Users\user\Documents\Arduino\FOF4YFTIA0WX947/FOF4YFTIA0WX947.ino:75: undefined reference to `AF_DCMotor::run(unsigned char)'

C:\Users\user\Documents\Arduino\FOF4YFTIA0WX947/FOF4YFTIA0WX947.ino:76: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'

C:\Users\user\Documents\Arduino\FOF4YFTIA0WX947/FOF4YFTIA0WX947.ino:77: undefined reference to `AF_DCMotor::run(unsigned char)'

C:\Users\user\AppData\Local\Temp\cchwJani.ltrans0.ltrans.o: In function `back':

C:\Users\user\Documents\Arduino\FOF4YFTIA0WX947/FOF4YFTIA0WX947.ino:50: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'

C:\Users\user\Documents\Arduino\FOF4YFTIA0WX947/FOF4YFTIA0WX947.ino:51: undefined reference to `AF_DCMotor::run(unsigned char)'

C:\Users\user\Documents\Arduino\FOF4YFTIA0WX947/FOF4YFTIA0WX947.ino:52: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'

C:\Users\user\AppData\Local\Temp\cchwJani.ltrans0.ltrans.o: In function `right':

C:\Users\user\Documents\Arduino\FOF4YFTIA0WX947/FOF4YFTIA0WX947.ino:66: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'

C:\Users\user\AppData\Local\Temp\cchwJani.ltrans0.ltrans.o: In function `forward':

C:\Users\user\Documents\Arduino\FOF4YFTIA0WX947/FOF4YFTIA0WX947.ino:42: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'

C:\Users\user\AppData\Local\Temp\cchwJani.ltrans0.ltrans.o: In function `left':

Multiple libraries were found for "AFMotor.h"

C:\Users\user\Documents\Arduino\FOF4YFTIA0WX947/FOF4YFTIA0WX947.ino:58: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'

Used: C:\Users\user\Documents\Arduino\libraries\arduino_723047

Not used: C:\Users\user\Documents\Arduino\libraries\arduino_668460

Not used: C:\Users\user\Documents\Arduino\libraries\arduino_668460

C:\Users\user\Documents\Arduino\FOF4YFTIA0WX947/FOF4YFTIA0WX947.ino:59: undefined reference to `AF_DCMotor::run(unsigned char)'

Not used: C:\Users\user\Documents\Arduino\libraries\arduino_668460

Not used: C:\Users\user\Documents\Arduino\libraries\arduino_668460

C:\Users\user\Documents\Arduino\FOF4YFTIA0WX947/FOF4YFTIA0WX947.ino:60: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'

C:\Users\user\AppData\Local\Temp\cchwJani.ltrans0.ltrans.o: In function `right':

C:\Users\user\Documents\Arduino\FOF4YFTIA0WX947/FOF4YFTIA0WX947.ino:67: undefined reference to `AF_DCMotor::run(unsigned char)'

C:\Users\user\Documents\Arduino\FOF4YFTIA0WX947/FOF4YFTIA0WX947.ino:68: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'

C:\Users\user\Documents\Arduino\FOF4YFTIA0WX947/FOF4YFTIA0WX947.ino:69: undefined reference to `AF_DCMotor::run(unsigned char)'

collect2.exe: error: ld returned 1 exit status

exit status 1

Error compiling for board Arduino/Genuino Uno.

This report would have more information with

"Show verbose output during compilation"

option enabled in File -> Preferences.

make sure to disconnect RX and TX pin when you compile, it is a common problem ;)

you need to install the library

Hello guys! I have a problem with the project's supply. I've been using a 9V battery and circuit turns on and i can connect my device with the bluetooth, but a few seconds after the bluetooth turn off itself and disconnect from my device. I have a AC adapter which has a 12V and 2A output and works perfectly. But i really need a wireless supply. What can i do? Please help me!! .. Thanks to all.

is it a new 9v battery? if it is nog it can be that it lost some of it's capacity and doesnt provide enough to run motors and drivers at the same time

Hey man, have resolved! Just put in serie two pair of battery AA, alkaline it's preffer and the connect it to the power of arduino.

Hi i had follow your built instruction and everything is working fine (thanks!). the control of my car with the app works great, except that my car stop after moving for about 100cm. then i let it rest for about 1 minute, and it can move again. same as turning and spinning. I am suspecting is my battery problem. i am powering my arduino board with a 9v Li-ion rechargeable and another 9v li-ion rechargeable for the adafruit motorshield v1. The power jumper on the motor shield is remove so that it only received power directly from 2nd power source and not from arduino board.

I am using 2 6v-9v motor with Tamiya Dual Gear Box. any idea why it stop and need to rest to continue? Thanks

probably cause your motors use a little to high current for the drivers, which causes them to heat very quickly. To prevent burning them they have an auto shutdown build in. There are 3 solutions here. First and easiest (but less likely to succeed) add heatsinks or active cooling to the chips. Second solution is piggybacking 2 of the same chips on top of each other which enlarges the current they can switch. option numer 3 is install motors that draw less current.

added some lines to the code tho

//*** 1- Documentation

//This program is used to control a robot car using a app that communicates with Arduino trough a bluetooth module

#include <AFMotor.h>

//creates two objects to control the terminal 3 and 4 of motor shield

AF_DCMotor motor1(2);

AF_DCMotor motor2(1);

char command;

void setup()

{

Serial.begin(9600); //Set the baud rate to your Bluetooth module.

}

void loop(){

if(Serial.available() > 0){

command = Serial.read();

Stop(); //initialize with motors stoped

//Change pin mode only if new command is different from previous.

//Serial.println(command);

switch(command){

case 'F':

forward();

break;

case 'B':

back();

break;

case 'L':

left();

break;

case 'R':

right();

break;

case 'G':

Forleft();

break;

case 'I':

Forright ();

break;

case 'H':

Backleft();

break;

case 'J':

Backright ();

break;

}

}

}

void forward()

{

motor1.setSpeed(255); //Define maximum velocity

motor1.run(FORWARD); //rotate the motor clockwise

motor2.setSpeed(255); //Define maximum velocity

motor2.run(FORWARD); //rotate the motor clockwise

}

void back()

{

motor1.setSpeed(255);

motor1.run(BACKWARD); //rotate the motor counterclockwise

motor2.setSpeed(255);

motor2.run(BACKWARD); //rotate the motor counterclockwise

}

void left()

{

motor1.setSpeed(255); //Define maximum velocity

motor1.run(FORWARD); //rotate the motor clockwise

motor2.setSpeed(0);

motor2.run(RELEASE); //turn motor2 off

}

void right()

{

motor1.setSpeed(0);

motor1.run(RELEASE); //turn motor1 off

motor2.setSpeed(255); //Define maximum velocity

motor2.run(FORWARD); //rotate the motor clockwise

}

void Stop()

{

motor1.setSpeed(0);

motor2.run(RELEASE); //turn motor1 off

motor2.setSpeed(0);

motor2.run(RELEASE); //turn motor2 off

}

void Forright()

{

motor1.setSpeed(140);

motor1.run(FORWARD); //turn motor1 off

motor2.setSpeed(255);

motor2.run(FORWARD); //turn motor2 off

}

void Forleft()

{

motor1.setSpeed(255);

motor1.run(FORWARD); //turn motor1 off

motor2.setSpeed(140);

motor2.run(FORWARD); //turn motor2 off

}

void Backright()

{

motor1.setSpeed(140);

motor1.run(BACKWARD); //turn motor1 off

motor2.setSpeed(255);

motor2.run(BACKWARD); //turn motor2 off

}

void Backleft()

{

motor1.setSpeed(255);

motor1.run(BACKWARD); //turn motor1 off

motor2.setSpeed(140);

motor2.run(BACKWARD); //turn motor2 off

}

the code is not compiling for arduino uno

Hii
I have made a car but i am unable to upload the code.
Help bro
More Comments