Hello i want to make a robot but i have problem with the Arduino code.I use the materials
Arduino Motor Shield
http://www.ebay.com/itm/Motor-Drive-Expansion-Shield-Board-Module-L293D-For-Arduino-Duemilanove-Mega-UNO-/221605183415?pt=LH_DefaultDomain_0&hash=item3398b2bfb7
and Bluetooth HC-05.
the code is this:
#include <AFMotor.h> //import your motor shield library
AF_DCMotor motor1(1, MOTOR12_64KHZ); // set up motors.
AF_DCMotor motor2(2, MOTOR12_8KHZ);
AF_DCMotor motor3(3, MOTOR34_64KHZ);
AF_DCMotor motor4(4, MOTOR34_8KHZ);
void setup() {
Serial.begin(9600); // begin serial communitication
//initial set up straight forward, no speed
motor1.setSpeed(0); //set the speed of the motors, between 0-255
motor2.setSpeed (0);
motor3.setSpeed (0);
motor4.setSpeed (0);
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
int incomingByte = Serial.read();
// action depending on the instruction
// as well as sending a confirmation back to the app
switch (incomingByte) {
case 'F':
moveForward(255, true);
Serial.println("Going forward");
break;
case 'R':
turn(255, true);
Serial.println("Turning right");
break;
case 'L':
turn(255, false);
Serial.println("Turning left");
break;
case 'B':
moveForward(255, false);
Serial.println("Going backwards");
break;
case 'S':
moveForward(0, true);
Serial.println("Stopping");
break;
default:
// if nothing matches, do nothing
break;
}
}
}
void moveForward(int speedBot, boolean forward) {
//boolean forward controls motor direction
if (forward) {
motor1.setSpeed(255); //set the speed of the motors, between 0-255
motor2.setSpeed (255);
motor3.setSpeed (255);
motor4.setSpeed (255);
}
else {
motor1.setSpeed(255); //set the speed of the motors, between 0-255
motor2.setSpeed (255);
motor3.setSpeed (255);
motor4.setSpeed (255);
}
motor1.setSpeed(255); //set the speed of the motors, between 0-255
motor2.setSpeed (255);
motor3.setSpeed (255);
motor4.setSpeed (255);
}
void turn(int speedBot, boolean right) {
//boolean right controls motor direction
if (right) {
motor1.setSpeed(255); //set the speed of the motors, between 0-255
motor2.setSpeed (255);
motor3.setSpeed (255);
motor4.setSpeed (255);
}
else {
motor1.setSpeed(255); //set the speed of the motors, between 0-255
motor2.setSpeed (255);
motor3.setSpeed (255);
motor4.setSpeed (255);
}
motor1.setSpeed(255); //set the speed of the motors, between 0-255
motor2.setSpeed (255);
motor3.setSpeed (255);
motor4.setSpeed (255);
}
I upload the sketch to the Arduino but nothing happens.Please help me, i need your help.Thanks in advnace