Adafruit Motor Shield PDF
Adafruit Motor Shield PDF
Adafruit Motor Shield PDF
Guide Contents 2
Overview 4
FAQ 6
How many motors can I use with this shield? 6
Can I connect more motors? 6
HELP! My motor doesnt work! - HELP! My motor doesnt work!...But the servos work FINE! 6
What is the LED for? 6
I'm trying to build this robot and it doesn't seem to run on a 9V battery.... 6
Can this shield control small 3V motors? 6
What is the power connector on the shield for? How do I power my motors? 6
My Arduino freaks out when the motors are running! Is the shield broken? 6
I have good solid power supplies, but the DC motors seem to 'cut out' or 'skip'. 6
What if I need more than 600mA per motor? 6
What pins are not used on the motor shield? 6
Which pins are connected to the DC/Stepper motors? 7
Huh? I don't understand... 7
How can I connect to the unused pins? 7
I get the following error trying to run the example code: "error: AFMotor.h: No such file or directory...." 7
How do I install the library? 7
I have two stepper motors and I want to run them simulaneously but the example code can only control one and
then the other? 7
What are some 'suggested motors'? 8
Is the motor shield compatible with the UNO R3 or Mega R3? What about the extra pins? 8
I'm using a 4WD robot platform and I can't get anything to work. 8
But my motor already has a capacitor on it and it still doesn't work. 8
Why don't you just design capacitors into the shield? 8
Make It! 10
Lets go! 10
Preparation 11
Tutorials 11
Tools 11
Parts List 16
Solder It 17
Use It! 34
Library Install 35
First Install the Arduino Library 35
Power Usage 36
Powering your DC motors, voltage and current requirements 36
How to set up the Arduino + Shield for powering motors 36
Using RC Servos 38
Using Stepper Motors 39
Using DC Motors 41
DC motors are used for all sort of robotic projects. 41
AF_DCMotor Class 43
AF_DCMotor motorname(portnum, freq) 43
Arduino is a great starting point for electronics, and with a motor shield it can also be a nice tidy platform for robotics
and mechatronics. Here is a design for a full-featured motor shield that will be able to power many simple to medium-
complexity projects.
2 connections for 5V 'hobby' servos connected to the Arduino's high-resolution dedicated timer - no jitter!
Up to 4 bi-directional DC motors with individual 8-bit speed selection (so, about 0.5% resolution)
Up to 2 stepper motors (unipolar or bipolar) with single coil, double coil, interleaved or micro-stepping.
4 H-Bridges: L293D chipset provides 0.6A per bridge (1.2A peak) with thermal shutdown protection, 4.5V to 25V
Pull down resistors keep motors disabled during power-up
Big terminal block connectors to easily hook up wires (10-22AWG) and power
Arduino reset button brought up top
2-pin terminal block to connect external power, for seperate logic/motor supplies
Tested compatible with Mega, Diecimila, & Duemilanove
Full kit available for purchase from the Adafruit shop. (http://adafru.it/81)
Download the easy-to-use Arduino software libraries and you're ready to go! (https://adafru.it/aON)
HELP! My motor doesnt work! - HELP! My motor doesnt work!...But the servos work FINE!
Is the LED lit? The Stepper and DC motor connections wont do a single thing if the LED is not lit
Don't bother writing up uploading code or wiring up motors if the LED doesn't light up, its not going to work.
I'm trying to build this robot and it doesn't seem to run on a 9V battery....
Please read the user manual for information about appropriate power supplies.
What is the power connector on the shield for? How do I power my motors?
Please read the user manual for information about appropriate power supplies.
My Arduino freaks out when the motors are running! Is the shield broken?
Motors take a lot of power, and can cause 'brownouts' that reset the Arduino. For that reason the shield is designed
for seperate (split) supplies - one for the electronics and one for the motor. Doing this will prevent brownouts.
Please read the user manual for information about appropriate power supplies.
I have good solid power supplies, but the DC motors seem to 'cut out' or 'skip'.
Try soldering a ceramic or disc 0.1uF capacitor between the motor tabs (on the motor itself!) this will reduce noise
that could be feeding back into the circuit (thanks macegr!)
The following pins are in use only if the DC/Stepper noted is in use:
Digital pin 11: DC Motor #1 / Stepper #1 (activation/speed control)
Digital pin 3: DC Motor #2 / Stepper #1 (activation/speed control)
Digital pin 5: DC Motor #3 / Stepper #2 (activation/speed control)
Digital pin 6: DC Motor #4 / Stepper #2 (activation/speed control)
The following pins are used only if that particular servo is in use:
Digitals pin 9: Servo #1 control
Digital pin 10: Servo #2 control
Pin 2 has a small breakout since its the only truly unused pin
The remaining pins are not broken out because they could be used by the motor shield. If you are sure that you are
not using those pins then you can connect to them by using stacking headers when assembling the kit or soldering
onto the top of the header with wires, or using a "Wing shield"
I get the following error trying to run the example code: "error: AFMotor.h: No such file or directory...."
Make sure you have installed the AFMotor library
I have two stepper motors and I want to run them simulaneously but the example code can only control one and
then the other?
The stepper motor library step() routine does not have the ability to run both motors at a time. Instead, you will have
to 'interleave' the calls. For example, to have both motors step forward 100 times you must write code like this:
If you want more intelligent control, check out the AccelStepper library (in the Downloads section) which has some
However, since its a popular question, I suggest buying motors from Pololu (DC Servos, DC motors) or Jameco (all
sorts!) As well as the many surplus webshops.
Is the motor shield compatible with the UNO R3 or Mega R3? What about the extra pins?
The motor shield is compatible with the R3 UNO and MEGA. The R3s have 2 extra pins on each header. These are
duplicates of other pins on the header and are not needed by the shield.
I'm using a 4WD robot platform and I can't get anything to work.
The motors used in the 4WD robot platforms from Maker Shed, DF Robotics, Jameco and others have a lot of
"brush noise". This feeds back into the Arduino circuitry and causes unstable operation. This problem can be
solved by soldering 3 noise suppression capacitors to the motor. 1 between the motor terminals, and one from each
terminal to the motor casing.
Lets go!
This is a vey easy kit to make, just go through each of these steps to build the kit
1. Tools and preparation (https://adafru.it/aOv)
2. Check the parts list (https://adafru.it/aOw)
3. Solder it (https://adafru.it/aOx)
Tutorials
Learn how to solder with tons of tutorials! (https://adafru.it/aOm)
(https://adafru.it/aOm)
Don't forget to learn how to use your multimeter too! (https://adafru.it/aOy)
Tools
There are a few tools that are required for assembly. None of these tools are included. If you don't have them, now
would be a good time to borrow or purchase them. They are very very handy whenever assembling/fixing/modifying
electronic devices! I provide links to buy them, but of course, you should get them where ever is most
convenient/inexpensive. Many of these parts are available in a place like Radio Shack or other (higher quality) DIY
electronics stores.
Solder Sucker
74HC595N
IC3 74HC595N 1
Serial to parallel output latch
16 pin sockets (OPTIONAL!)
First, check that you have all the parts! Look over the
parts list here (https://adafru.it/aOw) and shown on the
left.
Using your soldering iron tip, heat the resistor wire lead
and the metal ring (pad) at the same time, after a few
seconds, poke a little solder in so that it melts into a
nice cone. Remove the solder and then remove the
soldering iron. Do this for all 4 wires.
Bend the leads out just like you did with the resistors.
Solder all 6 wires, then clip them as you did with the
resistors.
Also, place the 3 large screw terminals for the motor and
external motor-power wires. If you received only 2 and
3-position terminal blocks, slide them together so that
you have 2 5-position terminals and 1 2-position
terminal.
You're done!
The Adafruit Motor Shield kit is a great motor controller for Arduino, but it does a little care to make sure it's used
correctly. Please read through all the User manual sections at left, especially the section about library installation and
power requirements!
Current requirements: The second thing to figure out is how much current your motor will need. The motor driver chips
that come with the kit are designed to provide up to 600 mA per motor, with 1.2A peak current. Note that once you
head towards 1A you'll probably want to put a heatsink on the motor driver, otherwise you will get thermal failure,
possibly burning out the chip.
On using the SN754410: Some people use the SN754410 (https://adafru.it/aOB) motor driver chip because it is pin-
compatible, has output diodes and can provide 1A per motor, 2A peak. After careful reading of the datasheet and
discussion with TI tech support and power engineers it appears that the output diodes were designed for ESD
protection only and that using them as kickback-protection is a hack and not guaranteed for performance. For that
reason the kit does not come with the SN754410 and instead uses the L293D with integrated kickback-protection
diodes. If you're willing to risk it, and need the extra currrent, feel free to buy SN754410's and replace the provided
chips.
Need more power? Buy another set of L293D drivers and solder them right on top of the ones on the board
(piggyback) (https://adafru.it/aOC). Voila, double the current capability! You can solder 2 more chips on top before it
probably isnt going to get you much benefit
You can't run motors off of a 9V battery so don't even waste your time/batteries! Use a big Lead Acid or NiMH battery
pack. Its also very much suggested that you set up two power supplies (split supply) one for the Arduino and one for
the motors. 99% of 'weird motor problems' are due to noise on the power line from sharing power supplies and/or not
having a powerful enough supply!
There are two places you can get your motor 'high voltage supply' from. One is the DC jack on the Arduino board and
the other is the 2-terminal block on the shield that is labeled EXT_PWR. The DC Jack on the Arduino has a protection
diode so you won't be able to mess things up too bad if you plug in the wrong kind of power. However the EXT_PWR
terminals on the shield do not have a protection diode (for a fairly good reason). Be utterly careful not to plug it in
backwards or you will destroy the motor shield and/or your Arduino!
If you would like to have the Arduino powered off of USB and the motors powered off of a DC power supply, plug in
the USB cable. Then connect the motor supply to the PWR_EXT block on the shield. Do not place the jumper on the
shield. This is a suggested method of powering your motor project
(If you have a Diecimila Arduino, don't forget to set the Arduino power jumper to USB. If you have a Diecimila, you can
alternately do the following: plug the DC power supply into the Arduino, and place the jumper on the motor shield.)
If you would like to have 2 seperate DC power supplies for the Arduino and motors. Plug in the supply for the Arduino
into the DC jack, and connect the motor supply to the PWR_EXT block. Make sure the jumper is removed from the
motor shield.
If you have a Diecimila Arduino, set the Arduino jumper to EXT. This is a suggested method of powering your motor
project
Either way, if you want to use the DC motor/Stepper system the motor shield LED should be lit indicating good motor
power
Hobby servos are the easiest way to get going with motor control. They have a 3-pin 0.1" female header connection
with +5V, ground and signal inputs. The motor shield simply brings out the 16bit PWM output lines to two 3-pin headers
so that its easy to plug in and go. They can take a lot of power so a 9V battery wont last more than a few minutes!
The nice thing about using the onboard PWM is that its very precise and goes about its business in the background.
You can use the built in Servo library
Using the servos is easy, please read the official Arduino documentation for how to use them and see the example
Servo sketches in the IDE (https://adafru.it/aOD).
Power for the Servos comes from the Arduino's on-board 5V regulator, powered directly from the USB or DC power
jack on the Arduino. If you need an external supply, cut the trace right below the servo pins (on v1.2 boards) and
connect a 5V or 6V DC supply directly. Using an external supply is for advanced users as you can accidentally destroy
the servos by connecting a power supply incorrectly!
When using the external supply header for servos, take care that the bottom of the header pins do not
contact the metal USB port housing on the Arduino. A piece of electrical tape on the housing will protect
against shorts.
Stepper motors are great for (semi-)precise control, perfect for many robot and CNC projects. This motor shield
supports up to 2 stepper motors. The library works identically for bi-polar and uni-polar motors
For unipolar motors: to connect up the stepper, first figure out which pins connected to which coil, and which pins are
the center taps. If its a 5-wire motor then there will be 1 that is the center tap for both coils. Theres plenty of tutorials
online on how to reverse engineer the coils pinout. (https://adafru.it/aOO) The center taps should both be connected
together to the GND terminal on the motor shield output block. then coil 1 should connect to one motor port (say M1 or
M3) and coil 2 should connect to the other motor port (M2 or M4).
For bipolar motors: its just like unipolar motors except theres no 5th wire to connect to ground. The code is exactly the
same.
Running a stepper is a little more intricate than running a DC motor but its still very easy
1. Make sure you #include <AFMotor.h>
2. Create the stepper motor object with AF_Stepper(steps, stepper#) to setup the motor H-bridge and latches.
Steps indicates how many steps per revolution the motor has. a 7.5degree/step motor has 360/7.5 = 48 steps.
Stepper# is which port it is connected to. If you're using M1 and M2, its port 1. If you're using M3 and M4 it's port 2
3. Set the speed of the motor using setSpeed(rpm) where rpm is how many revolutions per minute you want the
stepper to turn.
4. Then every time you want the motor to move, call the step(#steps, direction, steptype) procedure.#steps is how
many steps you'd like it to take. direction is either FORWARD or BACKWARD and the step type is SINGLE,
#include <AFMotor.h>
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Stepper test!");
motor.setSpeed(10); // 10 rpm
void loop() {
motor.step(100, FORWARD, SINGLE);
motor.step(100, BACKWARD, SINGLE);
Note that the H-bridge chip is not meant for driving loads over 0.6A or that peak over 1.2A so this is for small motors.
Check the datasheet for information about the motor to verify its OK.
To connect a motor, simply solder two wires to the terminals and then connect them to either the M1, M2, M3, or M4.
Then follow these steps in your sketch
#include <AFMotor.h>
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Motor test!");
void loop() {
Serial.print("tick");
Serial.print("tock");
motor.run(BACKWARD); // the other way
delay(1000);
Serial.print("tack");
motor.run(RELEASE); // stopped
delay(1000);
}
The AF_DCMotor class provides speed and direction control for up to four DC motors when used with the Adafruit
Motor Shield. To use this in a sketch you must first add the following line at the beginning of your sketch:
#include <AFMotor.h>
Parameters:
port num - selects which channel (1-4) of the motor controller the motor will be connected to
freq - selects the PWM frequency. If no frequency is specified, 1KHz is used by default.
MOTOR12_64KHZ
MOTOR12_8KHZ
MOTOR12_2KHZ
MOTOR12_1KHZ
MOTOR34_64KHZ
Example:
Note: Higher frequencies will produce less audible hum in operation, but may result in lower torque with some
motors.
setSpeed(speed)
Sets the speed of the motor.
Parameters:
speed- Valid values for 'speed' are between 0 and 255 with 0 being off and 255 as full throttle.
Example:
Note: DC Motor response is not typically linear, and so the actual RPM will not necessarily be proportional to the
programmed speed.
run(cmd)
Sets the run-mode of the motor.
Parameters:
Example:
motor.run(FORWARD);
delay(1000); // run forward for 1 second
motor.run(RELEASE);
delay(100); // 'coast' for 1/10 second
motor.run(BACKWARDS); // run in reverse
The AF_Stepper class provides single and multi-step control for up to 2 stepper motors when used with the Adafruit
Motor Shield. To use this in a sketch you must first add the following line at the beginning of your sketch:
#include <AFMotor.h>
Parameters:
steps - declare the number of steps per revolution for your motor.
num - declare how the motor will be wired to the shield.
Valid values for 'num' are 1 (channels 1 & 2) and 2 (channels 3 & 4).
Example:
Parameters:
Note: Step is a synchronous command and will not return until all steps have completed. For concurrent motion of two
motors, you must handle the step timing for both motors and use the "onestep()" function below.
Stepper1.step(100, FORWARD, DOUBLE); // 100 steps forward using double coil stepping
Stepper2.step(100, BACKWARD, MICROSTEP); // 100 steps backward using double microstepping
setSpeed(RPMspeed)
Parameters:
Note: The resulting step speed is based on the 'steps' parameter in the constructor. If this does not match the number
of steps for your motor, you actual speed will be off as well.
Example:
onestep(direction, stepstyle)
Single step the motor.
Parameters:
Example:
Stepper1.onestep(FORWARD, DOUBLE); // take one step forward using double coil stepping
release()
Release the holding torque on the motor. This reduces heating and current demand, but the motor will not actively
resist rotation.
Example:
Firmware
Arduino Stepper/Servo software library with microstepping support (https://adafru.it/aOK).
To install, click on Downloads in the middle of the page, select Download as zip and uncompress the folder.
Rename the folder to AFmotor (check that the renamed folder contains the .cpp and .h files) and install into the
Arduinosketches/libraries folder. For information how to use and install libraries, see our
tutorial (https://adafru.it/aYG)! This version now works with with the Mega. Public domain!
AccelStepper library (https://adafru.it/aOL) with AFMotor support. This library allows for advanced stepper control
including accelleration and decelleration, and concurrent stepper control! You still need AFmotor above!
To install, click on Download in the middle of the page, select Download as zip and uncompress the folder.
Rename the folder to AccelStepper (check that the renamed folder contains the .cpp and .h files) and install into
the Arduinosketches/libraries folder. For information how to use and install libraries, see our
tutorial (https://adafru.it/aYG)!
Forums
Forums (https://adafru.it/aOM)