Let's Make Robots!

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;

}

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Why are you not using 4AA batteries? 

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

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

 

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 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/product/791 but I'd be happy to skip voltage regulators. It says that it can handle 2A... So 6V wouldn't fry anyhting?

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 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 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. 

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).

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