So I'm trying to build a telepresence robot that's controlled through bluetooth. I got the bluetooth working and it receives the input but if it's only powered by batteries (9V) the motor's status LED flash when input is given but if I have the arduino connected to the pc through USB and still send the input through bluetooth it receives it and acts on it properly. I tried adding a battery to the arduino dc power jack, so there would be one 9V battery on the motor shield and another on the arduino and I still get the same result. Any ideas?
Here's the code in case it's software related:
char val;
int dirB = 13;
int dirA = 12;
int pwmB = 11;
int pwmA = 3;
int breakA = 9;
int breakB = 8;
void setup(){
pinMode(dirB, OUTPUT);
pinMode(dirA, OUTPUT);
pinMode(pwmB, OUTPUT);
pinMode(pwmA, OUTPUT);
pinMode(breakA, OUTPUT);
pinMode(breakB, OUTPUT);
Serial.begin(9600);
}
void loop(){
if( Serial.available() )
{
val = Serial.read();
Serial.print(val);
}
if(val == '0'){ //Robot is breaking
digitalWrite(breakA, HIGH);
digitalWrite(breakB, HIGH);
analogWrite(pwmA, 0);
analogWrite(pwmB, 0);
}
if(val == '1'){ //Robot is going Foward
digitalWrite(breakA, LOW);
digitalWrite(breakB, LOW);
digitalWrite(dirA, HIGH);
digitalWrite(dirB, LOW);
analogWrite(pwmA, 255);
analogWrite(pwmB, 255);
}
if (val == '2'){ //Robot is going Backwards
digitalWrite(breakA, LOW);
digitalWrite(breakB, LOW);
digitalWrite(dirA, LOW);
digitalWrite(dirB, HIGH);
analogWrite(pwmA, 255);
analogWrite(pwmB, 255);
}
if (val == '3'){ //Robot is going Right
digitalWrite(breakA, LOW);
digitalWrite(breakB, LOW);
digitalWrite(dirA, HIGH);
digitalWrite(dirB, HIGH);
analogWrite(pwmA, 255);
analogWrite(pwmB, 255);
}
if (val == '4'){ //Robot is going Left
digitalWrite(breakA, LOW);
digitalWrite(breakB, LOW);
digitalWrite(dirA, LOW);
digitalWrite(dirB, LOW);
analogWrite(pwmA, 255);
analogWrite(pwmB, 255);
}
}