Arduino reseting/not following code

When I connect the FTDI cable to Arduino, the whole robot starts working and executes a basic object-avoidance code. When I take it off and connect the power source, the robot starts to execute bits of code in a random sequence. The Arduino isn't resetting, but the red light is varying in intensity. Sometimes it almost goes out. I'm using an Arduino Pro Mini. Because the green light doesn't blink, I suppose the 2AA batteries aren't good enough to dish out 2A or more (I use 2 GM9 motors and I geard Arduino can use up to 1A). The motors are running faster and firmer whith the cable, but they struggle without. Here's the code:

 

 

 

 

const int pingPin = 9;

int Ain1 = 11;

int Ain2 = 12;

int Bin1 = 7;

int Bin2 = 8;

int Pwma = 6;

int Pwmb = 5;

int Stby = 10;

void setup() {

   pinMode(Ain1, OUTPUT);

  pinMode(Ain2, OUTPUT);

  pinMode(Bin1, OUTPUT);

  pinMode(Bin2, OUTPUT);

  pinMode(Pwma, OUTPUT);

  pinMode(Pwmb, OUTPUT);

  pinMode(Stby, OUTPUT);

 

 

  digitalWrite(Stby, HIGH);

  analogWrite(Pwma, 255);

  analogWrite(Pwmb, 255);

  Serial.begin(9600);

}

 

void loop()

{

  long duration, inches, cm;

 

 

  pinMode(pingPin, OUTPUT);

  digitalWrite(pingPin, LOW);

  delayMicroseconds(2);

  digitalWrite(pingPin, HIGH);

  delayMicroseconds(5);

  digitalWrite(pingPin, LOW);

 

  pinMode(pingPin, INPUT);

  duration = pulseIn(pingPin, HIGH);

 

  inches = microsecondsToInches(duration);

  cm = microsecondsToCentimeters(duration);

  delay(500);

  if(cm < 15)

  {  

   digitalWrite(Ain1, HIGH);

  digitalWrite(Ain2, LOW);

  digitalWrite(Bin1, HIGH);

  digitalWrite(Bin2, LOW);

 

 

 

  delay(1000);

 

   digitalWrite(Ain1, HIGH);

  digitalWrite(Ain2, LOW);

  digitalWrite(Bin1, LOW);

  digitalWrite(Bin2, HIGH);

 

 

 

  delay(500);

 

   digitalWrite(Ain1, LOW);

  digitalWrite(Ain2, LOW);

  digitalWrite(Bin1, LOW);

  digitalWrite(Bin2, LOW);

 

 

}

    else 

{    

 

  digitalWrite(Ain1, LOW);

  digitalWrite(Ain2, HIGH);

  digitalWrite(Bin1, LOW);

  digitalWrite(Bin2, HIGH);

 

 

  delay(100);

}

}

 

long microsecondsToInches(long microseconds)

{

 

  return microseconds / 74 / 2;

}

 

long microsecondsToCentimeters(long microseconds)

{

 

  return microseconds / 29 / 2;

}

When I stall both motors,

When I stall both motors, the red light on the Arduino Mini Pro goes out almost completely. The voltage regulator is rated for 2A as well, so it might be the problem?

Why are you not using 4AA

Why are you not using 4AA batteries? 

Well I tried to connect 4AA

Well I tried to connect 4AA in parallel but it wasn’t any better.

Not parallel, series. Are

Not parallel, series. Are you using a 3.3v arduino or 5v? 2AA won’t cut it for a 5v one.

 

Which version did you

Which version did you get?
From what I’ve read there’s a 5V and a 3.3V version of the Arduino Pro Mini… 2 x AA will only give you ~3V at best, and the voltage will drop when loads such as the motors are connected.

I’m using 2AA with a voltage

I’m using 2AA with a voltage regulator that gives me 5V. I’m using a 5V Arduino. And 4AA in series, wouldn’t that give 6V? 

Ah a boost regulator. Do you

Ah a boost regulator. Do you have a link to the one you have? It may not be able to deliver the current needed. 6v will work fine.

http://www.pololu.com/catalog

http://www.pololu.com/catalog/product/791 but I’d be happy to skip voltage regulators. It says that it can handle 2A… So 6V wouldn’t fry anyhting?

Oh just figured out my motor

Oh just figured out my motor driver can only handle 1A… but the motors still work with the FTDI cable so it actually handles the GM9 motors (670 mA at stall).

https://www.robotshop.com/ca/pololu-dual-dc-motor-driver-1a-4-5v-3-5v-tb6612fng-3.html

Pololu says:the maximum

Pololu says:

the maximum available current will be approximately 800 mA when doubling the input voltage

You are noy quite doubling it, but you will not be getting 2A that is for sure.

I am pretty sure most of us use 4AA on many things with no worry. I always have. If you use rechargeables, even better.

Ok then. Thanks a lot! I

Ok then. Thanks a lot! I never thought it was possible to surpass the 5V margin. I should’ve thought about 4NiMH though, especially that the voltage stays constant. Thanks again!

You could also probably do

You could also probably do 3AA and the boost regulator set to 5v. That would be able to deliver more current than using 2AA with the booster set to 5v.