Hi there,
I´m trying to create a toy car that´s controlled by bluetooth. This is my first proyect.
I´ve have some issues trying to connect the arduino mega 2560 t my adafruit motor shield. Yes, I know (now
that there are better, cheapper, more efficient ways to connect the arduino to those DC motors. But for now, I´m trying to connect the whole thing using the motor shield (at least until I buy the other stuff, anyway... Why this DC motor won´t power up with these AA batteries? - Motors, Mechanics, Power and CNC - Arduino Forum).
I have some issues:
As the arduino doesn´t have enough power to move 2 DC motors, I´ve tried adding three AA batteries... that were not enough. So I´ve finally used a 9v battery. Which it doesn´t make any difference either: the DC motors are still not moving.
The commands works, but ony "sometimes". How can that be? I think I have everything connected ok, because it worked at first, but now it doesn´t, and don´t undertand why.
This is the code that I´ve used, and I´ve atteched the schematics.
Thanks for your insight!!
#include <AFMotor.h>
//seteos iniciales de variables cada motor va conectado al M1 y M2 de la placa de control
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
int rojo1Bluetooth=22;
int rojo2Bluetooth=30;
int rojo3Bluetooth=38;
int rojo4Bluetooth=46;
int verdeBluetooth=52;
int ledPrueba=35;
void setup() {
//seteamos los pines, si son input o output
pinMode(rojo1Bluetooth,OUTPUT);
pinMode(rojo2Bluetooth,OUTPUT);
pinMode(rojo3Bluetooth,OUTPUT);
pinMode(rojo4Bluetooth,OUTPUT);
pinMode(verdeBluetooth,OUTPUT);
pinMode(ledPrueba,OUTPUT);
Serial.begin(9600);
}
void loop() {
char c = Serial.read();
if (c == 'q'){
digitalWrite(rojo1Bluetooth,HIGH);
digitalWrite(rojo2Bluetooth,HIGH);
digitalWrite(rojo3Bluetooth,HIGH);
digitalWrite(rojo4Bluetooth,HIGH);
motor1.setSpeed(20000);
motor1.run(BACKWARD); //los motores están al revés, por lo que backward es para ir hacia adelante
motor2.setSpeed(20000);
motor2.run(BACKWARD);
}
if (c == 'w'){
digitalWrite(verdeBluetooth,HIGH);
digitalWrite(rojo1Bluetooth,LOW);
digitalWrite(rojo2Bluetooth,LOW);
digitalWrite(rojo3Bluetooth,LOW);
digitalWrite(rojo4Bluetooth,LOW);
motor1.setSpeed(0);
motor1.run(RELEASE);
motor2.setSpeed(0);
motor2.run(RELEASE);
}
if (c == 'z') digitalWrite(ledPrueba,HIGH);
if (c == 'x') digitalWrite(ledPrueba,LOW);
delay(1000);
}//cerramos el loop
Thinking that maybe the bluetooth has a problem of some sort, I tried this simple test, using only one of the leds:
#include <AFMotor.h>
int ledPrueba=35;
void setup() {
pinMode(ledPrueba,OUTPUT);
Serial.begin(9600);
}
void loop() {
char c = Serial.read();
if (c == 'z') digitalWrite(ledPrueba,HIGH);
if (c == 'x') digitalWrite(ledPrueba,LOW);
delay(1000);
}//cerramos el loop
After that I tried using the S2 bluetooth android app to connect my tablet to the blotooth slave, but nothing happens when I type "z". If I use the "Monitor Serial" that comes with the arduino software, it does light up.
Again, thanks for your help and insight!
Rosamunda
