//first , you need to insstall the motor driver for L293D motor driver
// Go to Sketch-> Include Librabry-> Manage Library-> Search for Adafruit
Motor Shield V1
#include <AFMotor.h>
#include <SoftwareSerial.h>
SoftwareSerial HC05(9, 10); // RX, TX
//initial motors pin
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);
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
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](FORWARD); //rotate the motor clockwise
[Link](50); //Define lower velocity
[Link](FORWARD); //rotate the motor clockwise
[Link](255); //Define maximum velocity
[Link](FORWARD); //rotate the motor clockwise
[Link](50); // Define lower velocity
[Link](FORWARD); //rotate the motor clockwise
}
void right()
{
[Link](50); //Define lower velocity
[Link](FORWARD); //rotate the motor clockwise
[Link](255); //Define maximum velocity
[Link](FORWARD); //rotate the motor clockwise
[Link](50); //Define lower velocity
[Link](FORWARD); //rotate the motor clockwise
[Link](255); //Define maximum velocity
[Link](FORWARD); //rotate the motor 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
}