Hello guys. I am using an Arduino Leonardo and an L293D shield and 2 motors 3-6v each. I want to make a little car/robot and i am using an bluetooth 4.0 BLE CC2540 i think thats is ok. The code is working I think when i am in serial monitor i get a feedback from the forward function but the motors are not spinning or anithing and I think the wires are good connected. I am using 4AA bateries in series each 1.2v and I think that is the problem.
I am new in this and I need some feedback from you guys.
This is my code.
#include <AFMotor.h>
//initial motors pin
AF_DCMotor motor1(1, MOTOR12_1KHZ);
AF_DCMotor motor2(2, MOTOR12_1KHZ);
char data = 0;
char command;
void setup()
{
Serial.begin(9600); //Set the baud rate to your Bluetooth module.
Serial.println("Motor test !");
}
void loop()
{
if(Serial.available() > 0)
{
data = Serial.read();
//Serial.println(data);
Stop();
switch(data){
case 'a':
forward();
break;
case 'c':
back();
break;
case 'b':
right();
break;
case 'd':
left();
break;
}
}
}
void forward()
{
Serial.println("Going 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); //Define maximum velocity
motor1.run(BACKWARD); //rotate the motor anti-clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(BACKWARD); //rotate the motor anti-clockwise
}
void left()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(BACKWARD); //rotate the motor anti-clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(FORWARD); //rotate the motor anti-clockwise
}
void right()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(FORWARD); //rotate the motor clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(BACKWARD); //rotate the motor clockwise
}
void Stop()
{
motor1.setSpeed(0); //Define minimum velocity
motor1.run(RELEASE); //stop the motor when release the button
motor2.setSpeed(0); //Define minimum velocity
motor2.run(RELEASE); //rotate the motor clockwise
}