Need help setting A4990 Dual Motor Shield onto Arduino Uno

Hi, I need help in setting up A4990 Dual Motor Shield onto the Arduino uno rev 3. The dual motor shield has m1a, m1b, m2a, m2b. I’m not sure which positive and negative wire from the motor is supposed to go to which pin.

Hello.

You can use the pin identifications on the silkscreen to help align our A4990 Dual Motor Driver Shield for Arduino as shown in this picture on the A4990 shield’s product page.

You can connect one pair of motor terminals to M1A and M1B and another pair of motor terminals to the M2A and M2B pins. If after connecting your motors to those terminals you find one of them is turning in the wrong direction for your purposes, you can simply switch the polarity of that motor’s connections to change the direction. The VIN and GND terminals supply the motor power.

-Derrill

Hi, I’m unable to see the picture you’ve linked

Hello.

I am sorry about that. I broke the link to that picture by mistake. It should be fine now.

-Derrill

Hi, thank you for the help. I am fairly new to using arduino and everything and am currently working on building a car that uses an ultra sonic sensor to avoid collision. Is it possible to post Arduino code snippet on these forums for assistance?

Hello.

You can post code using code tags ([ code ][ /code ] - without spaces). If you need help with your code, I suggest posting the simplest version of the code that demonstrates the problem along with a clear description of what is happening and what you want to happen.

-Derrill

thank you for replying

If I’m understanding this correctly, in order to control the two motors with the dual motor shield I need to have the a4990’s files in my libraby? I have uploaded the demo from the examples folder and I would like to make both motors move forward and stop if the sensor senses an object about 15 cm away.

void loop() {

 for (int speed = 0; speed <= 400; speed++)
  {
    motors.setM1Speed(speed);
    stopIfFault();
    delay(2);
  }

 for (int speed = 0; speed <= 400; speed++)
  {
    motors.setM2Speed(speed);
    stopIfFault();
    delay(2);
  }
if(distance >= limitDistance)
{
  moveStop();
}

void moveStop(){
  {
    speed = 0;
    motors.setM1Speed(speed);
    motors.setM2Speed(speed);
    delay(2);
  }
}

I’m not exactly sure how to keep the 2 motors running until it senses an object within its limit then have the car stop

If you want to use the Arduino libraries we provide, you should install the A4990 libraries in the Arduino IDE “libraries” folder. The “Software” section of our Pololu A4990 Dual Motor Driver Shield for Arduino GitHub page covers how to install those files.

Once you set the motor speed, it will continue at that speed until another speed command changes it. One simple way to get the behavior you wants would be to set the speed in the setup function, then in the loop ( ) function check the sensor and command the motors to stop if the distance condition is met.

If you are new to the Arduino, you might look at this tutorial to get started. Alternatively, you might do your own search for Arduino programming tutorials.

-Derrill

Hi, thanks for replying.

Car is now successfully working with being able to stop when the car senses a certain distance. Really impressed by this small motor shield