//Arduino Bluetooth Controlled Car
//Before uploading the code you have to install the necessary library
//Note - Disconnect the Bluetooth Module before hiting the upload button otherwise you'll get
compilation error message.
//AFMotor Library [Link]
//After downloading the library open Arduino IDE >> go to sketch >> Include Libray >> ADD. ZIP
Libray >> Select the downloaded
//ZIP File >> Open it >> Done
//Now You Can Upload the Code without any problem but make sure the bt module isn't
connected with Arduino while uploading code
#include <AFMotor.h>
//initial motors pin
AF_DCMotor motor1(1, MOTOR12_1KHZ);
AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);
char command;
void setup()
[Link](9600); //Set the baud rate to your Bluetooth module.
void loop(){
if([Link]() > 0){
command = [Link]();
Stop(); //initialize with motors stoped
//Change pin mode only if new command is different from previous.
//[Link](command);
switch(command){
case 'F':
forward();
break;
case 'B':
back();
break;
case 'L':
left();
break;
case 'R':
right();
break;
void forward()
[Link](255); //Define maximum velocity
[Link](FORWARD); //rotate the motor clockwise
[Link](255); //Define maximum velocity
[Link](FORWARD); //rotate the motor clockwise
[Link](255);//Define maximum velocity
[Link](FORWARD); //rotate the motor clockwise
[Link](255);//Define maximum velocity
[Link](FORWARD); //rotate the motor clockwise
}
void back()
[Link](255); //Define maximum velocity
[Link](BACKWARD); //rotate the motor anti-clockwise
[Link](255); //Define maximum velocity
[Link](BACKWARD); //rotate the motor anti-clockwise
[Link](255); //Define maximum velocity
[Link](BACKWARD); //rotate the motor anti-clockwise
[Link](255); //Define maximum velocity
[Link](BACKWARD); //rotate the motor anti-clockwise
void left()
[Link](255); //Define maximum velocity
[Link](BACKWARD); //rotate the motor anti-clockwise
[Link](255); //Define maximum velocity
[Link](BACKWARD); //rotate the motor anti-clockwise
[Link](255); //Define maximum velocity
[Link](FORWARD); //rotate the motor clockwise
[Link](255); //Define maximum velocity
[Link](FORWARD); //rotate the motor clockwise
void right()
[Link](255); //Define maximum velocity
[Link](FORWARD); //rotate the motor clockwise
[Link](255); //Define maximum velocity
[Link](FORWARD); //rotate the motor clockwise
[Link](255); //Define maximum velocity
[Link](BACKWARD); //rotate the motor anti-clockwise
[Link](255); //Define maximum velocity
[Link](BACKWARD); //rotate the motor anti-clockwise
void Stop()
[Link](0); //Define minimum velocity
[Link](RELEASE); //stop the motor when release the button
[Link](0); //Define minimum velocity
[Link](RELEASE); //rotate the motor clockwise
[Link](0); //Define minimum velocity
[Link](RELEASE); //stop the motor when release the button
[Link](0); //Define minimum velocity
[Link](RELEASE); //stop the motor when release the button