Motor shield problems

I have a Duemilanove which I am using with a motor shield purchased from NKC off of Amazon. Not sure what version.

I have it connected to a twin-motor gear box (tamiya 70097) which is mounted on a tracked vehicle chassis (tamiya 70108).

If I tell the motors to go in one direction everything is fine, but once I try to reverse directions in the same program one side tweaks out and cannot decide what way it want to turn.

I am powering everything off of the 9V through the board and shield.

Any ideas?

here is my code if it helps

int dirB = 12; // Direction pin for motor B is Digital 12
int speedB = 9; // Speed pin for motor B is Digital 9 (PWM)

int dirA = 13;   //Diretion pin for motor A is Digital 13
int speedA = 10; //Speed pin or motor A is Digital 10 (PWM)

int speed = 230;
int speed2 = 255;

int front = 0;
int back = 1;

void setup()
  pinMode (dirA, OUTPUT);
  pinMode (dirB, OUTPUT);
  pinMode (speedA, OUTPUT);
  pinMode (speedB, OUTPUT);

void loop()
  delay(4000); // 4 second
  delay(4000); // 4 second


void setspeed()
  analogWrite(speedB, speed); // set speed (PWM) 
  analogWrite(speedA, speed2); // set speed (PWM) 

void forward()
  digitalWrite(dirB,front); // set direction
  analogWrite(speedB, speed); // set speed (PWM) 
  digitalWrite(dirA,front); // set direction
  analogWrite(speedA, speed2); // set speed (PWM) 


void backward()
  digitalWrite(dirB,back); // set direction
  analogWrite(speedB, speed); // set speed (PWM) 
  digitalWrite(dirA,back); // set direction
  analogWrite(speedA, speed); // set speed (PWM) 

void right()
  digitalWrite(dirB,front); // set direction
  analogWrite(speedB, speed); // set speed (PWM) 
  digitalWrite(dirA,back); // set direction
  analogWrite(speedA, speed2); // set speed (PWM) 

new fine when powered through USB but not with the battery. Must be a power issue...I will try to separate the motor power supply from the boards.

9v batteries cannot provide very much current at all to a circuit so that will be your problem. I advise a li-ion (li-poly) cell of a ni-mh pack. I also had a problem with 9v current draw in a recent project. I'm not sure if my rechargeable 8.4V ni-mh PP3 will be any better. I need to try it...


I would try this:

  1. Use a 7.2 volt NiMH RC car battery pack for the drive motors - they're cheap, plentiful, and easy to recharge.

  2. Power the motors off of the pack (make sure to have filter caps across the motor terminals).

  3. Power the Arduino off of a separate 9V battery or LiPoly/LiIon pack.

  4. Make sure the grounds are tied together (common ground).

I realized that this post is in the wrong section :-[

I solved the power problem by using a 4xAA pack to the motor supply pins of the shield.

Now I am having a new problem, one motor spins faster than the other. Is this just a result of crappy motors or is there another under lying problem?

In my code I try to compensate for this but I am not sure this is the best way.

Any ideas?

Is this just a result of crappy motors

Most likely!


Anyone have any sources for good quality miniature DC motors, the kind sold with the arduino starter kits,

and seen in this link

I am using a twin-motor gear box (tamiya 70097) that only accepts the miniature DC motors.

got it working with the crappy motors I got.

It is a cool little light seeker!!!

Now I need to add some capabilities and weaponize.

What is the kind of sensors out there to avoid walls and/or follow something around?

Its not "crappy motors", its just the way things are with open-loop control.

You see, you don't have any feedback to the arduino as to how fast and how far the motors have turned. So, you need to incorporate feedback, and then in your program, interpret the feedback so that if one of the motors is going faster than the other, slow it down, until both match.

There are several approaches to how this could be done - the easiest being an optical slit encoder. Basically, that is a disk that is mounted to the output shaft (which is typically connected to a wheel - but you're using a tracked system - but its the same principle) that has slits or dark/light patches, that with an optical detector, you can detect those HIGH/LOW transitions - the frequency of the transition being the speed of the output shaft (this is simple encoder - using a quadrature encoder you can detect direction of rotation as well).

You can see an example of such an encoder (plus a lot of other info) here:

In the above example, they are using a light/dark wheel, and a "sideways looking" optical sensor (there is also what is called a slit sensor, which looks like a U-shaped piece of plastic holding the IR LED on one side, and a photo-transistor on the other - the wheel has a series of slits, and as they pass the sensor, they block/let-thru the IR light to trip the sensor - the old non-optical mice used this method; this is also a good and easy way to get such encoders).

As you can tell, the sideways looking type can be easily printed with a laser or inkjet printer (a slit version can be printed too, on transparency "paper" - but you don't see it often; commercial slit encoder wheels are typically made of plastic or metal).

Also - check the following article out, it shows an example of how to build such encoders:

(NOTE: The Seattle Robotics Society is one of the oldest hobbyist robotics clubs in existence; check out their site!).

As far as wall avoidance, you might want to check out ultra-sonic sensors (like the Parallax PING - there are other variants as well), as well as the Sharp IR distance sensors. For following something around, I suppose you could mount one of the Sharp IR sensors on a servo and "scan" the area for a particular frequency of IR light, and follow toward that based on the angle of the servo...

Good luck!


thanks. looks like I got some researching to do.

Tamiya Tracked Vehicle Chassis Kit Item #70108 :

I just purchased an adafruit motor shield and cant seem to get it working... I powered the Arduino with the USB cable and powered the motors with a 9 volt battery... I used code examples given for the motor shield. code seemed to compile and upload to Arduino like normal.

I tried a small dc motor no luck and then tried a small stepper and no luck ...

If I connect the dc motor stright to 9v battery it runs at a medium sort of speed.

Do you think I also have issue that the 9v battery can not power the board and the motor? I expected that at least something would happen, but I only get the light on the motor shield to light up indicating it has power. I removed the little shunt on the motor shield that would make the power come from the motor shield IIRC.

Thanks Bradley Arkansas USA

How big is your motor? The motor shield can only power small low power motors.


Connect a multimeter to the screwterminals for the motor then run your sketch. If your shield works normal you should see the delivered voltage !