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
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:
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
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)
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.
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
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
We have a be nice policy.
Please be positive and constructive.