Introduction: How to Use Your MotorShield With DC Motors

I wanted to help with giving the community a simpler to understand guide to using DC Motors with the Motorshield which can be attached to your Arduino.
So please grab your Arduino and MotorShield and I hope we can shed some light in how to properly prepare you in using your DC motors.

Step 1: The Items You Will Need

Here is a list of the items we need to work with the MotorShield

1. MotorShielf v 1.2 - https://www.adafruit.com/products/81

(Adafruits instructions: https://learn.adafruit.com/adafruit-motor-shield)

2. Arduino Uno

3. You will need to download the required Library to use the Motorshield

https://learn.adafruit.com/adafruit-motor-shield/l...

4. DC Motors

5. Philips screwdriver PH00x25

6. A Battery to power your Motorshield (sometimes you may need more power than you realize)

Step 2: Let's Install the Library

Once the library is downloaded:

C:/Programs Files/Arduino/libraries
in my case it was in Program Files (X86) - keep this in mind, as an alternative to Program Files

and copy the folder so that they can be accessed by your Arduino program.

Now that the Library is in place we can go to Arduino and install it.
To simply achieve this go to: Sketch -> Include Library -> Manage Library... Install the required libraries, such as Servo, Stepper, and Adafruit Motor Shield library

Step 3: The Code

Now that the batters are plugged in let's go over the code.

Before starting you must include the library into your code

#include <AFMotor.h>
This is the library that will be calling upon your Motors and help you designate them

AF_DCMotor motor(2, MOTOR12_64KHZ);
in order from left to right
designating DC Motor, name to use in code, ( pin, rate of motor speed)

motor.run(BACKWARD)
motor.run(FORWARD)
motor.run(RELEASE)
the .run function will give you the option to designate what you want to the motor to do, whether it will move forward backward or relase for pause.

motor.setSpeed(insert number)
This will let you set the speed you would like the motor to run at, however it is best to check your motors capabilities so that you are staying within the acceptable range

Step 4: Control Multiple Motor From Your Serial Monitor

you can name up to four motors
ex
AF_DCMotor motor1(1, MOTOR12_64KHZ); // create 1st motor
AF_DCMotor motor2(2, MOTOR12_64KHZ); // create 2nd motor

and you can control each motor separately, and even set each one with their own speed by calling their name with any of the options we discussed earlier.

Also we can create code that allows us to control these motors with input, as shown with the example code above.

Thank you for joining me with this, I hope it helps you in using DC motors

Step 5:

Comments

author
tomatoskins (author)2016-03-07

Really cool! Thanks for sharing and welcome to the community!

About This Instructable

1,546views

25favorites

License:

More by JosephL76:How to Use Your MotorShield With DC Motors
Add instructable to: