Introduction: Arduino Motor Shield Tutorial

The Arduino Motor Shield allows you to easily control motor direction and speed using an Arduino. By allowing you to simply address Arduino pins, it makes it very simple to incorporate a motor into your project. It also allows you to be able to power a motor with a separate power supply of up to 12v. Best of all, the shield is very easy to find. Aside from being sold a number of places online, they are now stocked by most Radioshack stores. For all of these reasons, the Arduino Motor Shield if a cool little to have in your arsenal for rapid prototyping, and general experimenting.

Step 1: Install

The pins of the official Arduino motor shield will only align with Arduino Uno Rev. 3.

In order to make it work with older versions of the Arduino, you will need to trim a few pins off the motor shield. However, this is not, at all, recommended.

Insert the motor shield pins into the socket of the Arduino Uno.

Step 2: Shield Features

The motor shield has 2 channels, which allows for the control of two DC motors, or 1 stepper motor.

It also has 6 headers for the attachment of Tinkerkit inputs, outputs, and communication lines. The use of these pins is somewhat limited, and therefor not covered in this tutorial.

With an external power supply, the motor shield can safely supply up to 12V and 2A per motor channel (or 4A to a single channel).

There are pins on the Arduino that are always in use by the shield. By addressing these pins you can select a motor channel to initiate, specify the motor direction (polarity), set motor speed (PWM), stop and start the motor, and monitor the current absorption of each channel .

The pin breakdown is as follows:

FunctionChannel AChannel B
Direction Digital 12 Digital 13
Speed (PWM) Digital 3 Digital 11
Brake Digital 9 Digital 8
Current Sensing Analog 0 Analog 1

For more information about the technical specs, check out the motor shield's official page on the Arduino site.

Step 3: Program

Plug the Arduino into your computer's USB port and open the Arduino development environment.

In order to get the board to do anything, you need to initialize the motor channel by toggling three parameters:
  1. First you need to set the motor direction (polarity of the power supply) by setting it either HIGH or LOW.
  2. Then you need to disengage the brake pin for the motor channel by setting it to LOW.
  3. Finally, to get the motor to start moving, you need to set the speed by sending a PWM command (analogWrite) to the appropriate pin.

If you do not do all three of these things, the motor will not turn on.

In the following steps are some common examples of common motor setups.

Step 4: One Motor

To control a motor using the Arduino Motor Shield, first plug the motor's positive (red) wire into Channel A's + terminal on the motor shield, and the motor's ground (black) wire into Channel A's - terminal on the shield.

An external power supply is not always necessary, but it drastically improves the motor's performance. It is recommended that you always use one.

To connect your external power supply, connect the positive (red) wire from the power supply to the "Vin" terminal, and the ground (black) wire to the "GND" terminal.

Finally, upload the code to control the Motor Shield to the Arduino.

Here is the code for controlling one motor:

Step 5: Two Motors

Interfacing with two motors is pretty much the same as interfacing with one motor. Simply plug the motor into Channel B.

The only difference code-wise is that you need to engage a second channel to control the second motor.

Here is code for controlling two motors:

Step 6: Stepper Motor

There are a number of different types of stepper motors, but in this tutorial we will specifically be addressing bipolar stepper motors. Bipolar stepper motors typically have 4 pins, which correspond to two coils. To use a stepper, you need to power these two coils in phase with alternating polarity.

To figure out which two pins make up a single coil, insert an LED into any two pins on its socket and rotate the motor shaft. If the LED lights up, you found one coil. The other two pins should make up the other coil.

To make a bipolar motor spin:
  1. Power the first coil.
  2. Next power the second coil with reverse polarity.
  3. Then power the first coil with reverse polarity.
  4. Finally, power the second coil.
To reverse the motor direction of a bipolar stepper, simply reverse the polarity of the second coil.

Here is code to make the stepper spin in one direction:

Here is code to make the stepper spin in the opposite direction:


cademis made it! (author)2017-07-02

Thanks for that tutorial which makes it possible to drive my stepper w/o any libraries. I re-use your program to control a linear drive and it works perfectly!

Tahalilm made it! (author)2017-03-03

Why is it the digitalWrite is specifying 12, 9 and 3?

cyborg2006 made it! (author)2017-02-23

This is working. Thanks for this example.

Arduino Motor Control.jpg
Jamiever6 made it! (author)2016-12-29

Excellent tutorial, thank you. I just salvaged a stepper motor from an old scanner and few DC motors. Looking forward to use them in a new project.

File 2016-12-29, 16 24 13.png
aqeelkhan4772 made it! (author)2016-11-16

hie everyone! i have a problem ... i need help in arduino project .i am using lcd shield and stepper motor at the same time but the problem is that these both device had the common pin pin 8 and 9 on arduino board can i change the pin of stepper motor to used other pin

mail id

adele14 made it! (author)2016-10-04


I am working on an arduino system using a stepper motor (4SM42HT38-1684A) and a motor shield. I wanted to make the motor turn in one direction, stop and then turn in the other directions. I used the two codes above in two loops but the motor is still going in the same direction (i am sure that the 2nd loop is running but it is still the same direction). Could you help me please ? Is there anything to adapt in theses codes to make them run together ?

Thanks a lot,



msgat made it! (author)2016-10-03

Thankyou for your tutorial.

I am trying to drive a stepper motor 42SH47 - M RS No 535-0401.
I have cut the vin link and supplied the motor separately.

Using the code to move in one direction , I find that the motor is oscillating rather than rotating in one direction only.

Do you have any suggestions as to what I might be doing wrong ?

Thanks for your time



randofo made it! (author)randofo2016-10-03

The motor does not have a V-in link. It should have 4 wires. These comprise two separate pairs of motor drive coils which need to be powered in sequence. Each pair needs to be correctly attached to each channel.

msgat made it! (author)msgat2016-10-04


I decided to up the voltage to the motor.
When I got to 3.3 V it started to rotate correctly.
The manufacturer states 2.8V supply!!

I will contact the manufacturer to see if we can explain!.
Thanks again for your help and the article.



Johnson Selva made it! (author)2016-10-02

nice article man it helped me a lot.... sweet and short...

will you able to explain other pins too (OUT6 OUT5 etc.,)

HARI6 made it! (author)2016-09-30


Kit Lorenz made it! (author)2016-09-23

Just one more question, servos will also work the same way right?

randofo made it! (author)randofo2016-09-26

No. Servos work differently than DC motors. They need a control signal.

Kit Lorenz made it! (author)2016-09-22

Can one also put another shield on top of the first one to support 4 dc motors?

randofo made it! (author)randofo2016-09-22

I don't know if that would work.

However, if that worked at all, you would end up with two sets of synchronized motors. Basically, each channel on each shield would end up being controlled the same.

Kit Lorenz made it! (author)Kit Lorenz2016-09-23

ok, thanks!

bsolar made it! (author)2016-08-13

Thanks for the help:) this is such a good tutorial! It really made it clear what you can do with this shield. I have been searching all over the internet and have only found incomplete tutorials. Typos aside, this is a great tutorial! (sorry for typos, I'm swedish...

AshwinT5 made it! (author)2016-07-15

const int motorPin1 = A0;

const int motorPin2 = A3;

void setup()


pinMode(motorPin1, HIGH);

pinMode(motorPin2, LOW);


void loop()


analogWrite(motorPin1, 255);

analogWrite(motorPin2, 254);


can it work for full speed

tinyweasel made it! (author)2016-07-10

Thanks for the Instructable! I noticed a little typo in your code, thought I'd let you know.

digitalWrite(9, HIGH); //Engage the Brake for Channel A
digitalWrite(9, HIGH); //Engage the Brake for Channel B

Should be pin 8 for Channel B. Just in case anyone copied and pasted and is getting weird results. :)

AgentMess made it! (author)2016-05-06

Nice instructable. I really like the idea of connecting an LED to the stepper motor to figure out what pins belong to the same coil.

firephotoputer made it! (author)2012-04-10

For the stepper motor code, what is the difference between the two versions that makes them spin the motor in opposite directions? The two code sets look the same to me, but since I am just starting with this, I can easily be overlooking the critical difference. And is "delaylegnth" supposed to be "delaylength" (as I said, just starting, so I am not familiar with the syntax quirks). Thanks!

randofo made it! (author)randofo2012-04-10

delaylegnth is a variable, so it was defined (misspelled) by me. If you correct one instance of the spelling, just be sure to correct all of them in the code.

The difference between the two is the direction of Channel B in each of the codes. Look at the difference of sequence for: digitalWrite(13, HIGH); //Sets direction of CH B

Ana CecíliaM made it! (author)Ana CecíliaM2016-04-21

Hi there,

I know this is a long shot that you'll even see this but I tried both codes (for both directions) and they both spin the motor in the same direction...

I've been trying hard to understand what I should do, but there is little to no documentation supporting the motor shield. Help?! :)

Ofibro made it! (author)Ofibro2015-06-09

hi great project


i have a problem with my external power supply

i tried everything, from disconnecting and connecting the bridge under the board right below the VIN pin i tried using a 9v jack i connected the 9v battery to the arduino's VIN pin directly.




to make matters worse, i bought another one yet still no use i borrowed two of them from my friend yet STILL no use


im deeply in need of you


P.S i know how to program it really good my problem lies on the power supply




Ofibro made it! (author)Ofibro2015-06-10


just to the point of giving up I FINNALY got it.

all that it needed was amps.

I was using an lakline 9V battery which supplied 500mAh, which of course wasnt enough..

so i bought a couple of rechargeable batteries and VOLA it worked

keep in mind that those rechargeable batteries were 2200mAh @ 1.2 volts x5 so that was enough to get those motors moving!!

thanks anyways and great project.


GabrielR28 made it! (author)GabrielR282015-10-21

I do not speak English. friend you could upload some pictures of the connection to external source. as is the connection of the bridge. Thank you

SantitheGreat made it! (author)SantitheGreat2015-09-20

u have to use a regular battery pack for the arduino itself, then an extra 9v battery.

firephotoputer made it! (author)firephotoputer2012-04-10

Now that you have pointed it out, the difference between the versions is obvious. Thank you!

DavidH469 made it! (author)2016-04-09

Hey hey, try someone to use this motorshield with arduino duemilanove? If yes can you help me with it? I am beginner.

Thanks a lot!

kibble01 made it! (author)2016-03-10

How would you go about using the code above with a switch to stop the stepper motor kind of like a endstop.

so far I have it stopping but it will stop after the loop is completed, is there a way to stop it right away?



YaddyVirus made it! (author)2016-03-08

Will this work on the Arduino Mega 2560 R3? I want to use this in a obstacle avoiding robot.

And the link to the motor shield is broken

UtsavC made it! (author)2016-02-22

I want my motor to move in all direction. and also want to stop and start it any time not fixed I am connecting arduino with bluetooth module so I want codes for 2motors

can any one help me

UtsavC made it! (author)2016-02-22

I have ordered same motor driver shield for my project
I have a doubt that can we move 2 motors and 1 stepper sinultaneously???

BorisP12 made it! (author)2016-02-07

Can you help me. i have an OSEPP Motor and Servo sheild that is Arduino compatiable but i have no idea how to work it...any thoughts?

planetoid127 made it! (author)2016-02-02

Thanks for the tutorial, I made it and it was great! I also like the way you put in the code meaning and code.

Alok Shaw made it! (author)2016-01-05

i am using arduino adafruit motor control shield V1 ,for controlling 4 12v dc motors....but i am confused about the power supply for the motor shield as i read on the manual of adafruit fruit that 9v supply will not work(why no idea)!! what sort of power supply other than lipo can i supply?? and how much should i supply..for the 4 dc geared motors(12V,300rpm)

darkstar1899 made it! (author)darkstar18992016-01-05

A different power supply and some relays might prove useful. Note the relays are to be controlled by the board but the 12 V power source should not be grounded to the board itself.

LawrenceM8 made it! (author)2015-09-07

I followed the instructions, and it worked fine. When I installed a remote control, the receiver did not pick up any signal or pick up wrong signal when the motor is spinning. When the motor is not spinning, it could pick up signal and everything worked. This is the same effect as of before installing the motorshield. Does anyone else have this problem?

Alok Shaw made it! (author)Alok Shaw2016-01-05

to which pin , you connected the IR reciever??

AdityaP25 made it! (author)2015-10-11

Harshvardhan and Javier I think both of your code will not work as in both of your codes you have chosen pins 2,3,4,5 which actually are not PWM pins so your code will not work as analogWrite function only works with the PWM pins

Harshvardhan Singh made it! (author)2015-09-30

is this code ok to drive 2 motors front right back and left.

void setup() {
pinMode (5, OUTPUT);//LEFT MOTOR

void loop() {
digitalWrite (2, LOW);//RIGHT MOTOR
analogWrite (3, 250);//RIGHT MOTOR
digitalWrite (4, LOW);//LEFT MOTOR
analogWrite (5, 250);//LEFT MOTOR
digitalWrite (2, LOW);//RIGHT MOTOR
analogWrite (3, 150);//RIGHT MOTOR
digitalWrite (4, HIGH);//LEFT MOTOR
analogWrite (5, 105);//LEFT MOTOR
digitalWrite (2, HIGH);//RIGHT MOTOR
analogWrite (3, 125);//RIGHT MOTOR
digitalWrite (4, HIGH);//LEFT MOTOR
analogWrite (5, 125);//LEFT MOTOR
digitalWrite (2, HIGH);//RIGHT MOTOR
analogWrite (3, 105);//RIGHT MOTOR
digitalWrite (4, LOW);//LEFT MOTOR
analogWrite (5, 150);//LEFT MOTOR

JavierO5 made it! (author)2015-09-30

Hi everybody,

I have a Arduino uno connect to a Arduino Motor Shield r3, and i am trying to control a stepper motor from Maxuino (this one

I have been following the Chris Coleman tutorial on vimeo but i might have a problem with the setting of the pin.

From the arduino software, this code works:

int delaylegnth = 30;

void setup() {

//establish motor direction toggle pins

pinMode(12, OUTPUT); //CH A -- HIGH = forwards and LOW = backwards???

pinMode(13, OUTPUT); //CH B -- HIGH = forwards and LOW = backwards???

//establish motor brake pins

pinMode(9, OUTPUT); //brake (disable) CH A

pinMode(8, OUTPUT); //brake (disable) CH B


void loop(){

digitalWrite(9, LOW); //ENABLE CH A

digitalWrite(8, HIGH); //DISABLE CH B

digitalWrite(12, HIGH); //Sets direction of CH A

analogWrite(3, 255); //Moves CH A


digitalWrite(9, HIGH); //DISABLE CH A

digitalWrite(8, LOW); //ENABLE CH B

digitalWrite(13, LOW); //Sets direction of CH B

analogWrite(11, 255); //Moves CH B


digitalWrite(9, LOW); //ENABLE CH A

digitalWrite(8, HIGH); //DISABLE CH B

digitalWrite(12, LOW); //Sets direction of CH A

analogWrite(3, 255); //Moves CH A


digitalWrite(9, HIGH); //DISABLE CH A

digitalWrite(8, LOW); //ENABLE CH B

digitalWrite(13, HIGH); //Sets direction of CH B

analogWrite(11, 255); //Moves CH B



But in Maxuino it doesn't works. The lights on the motor shield board arent moving the same way, as if the pins wasn't setting up correctly, but i can't found how to solve it.

It is kind of an emergency, i'm trying to make it work for friday. If someone has any idea that could help me to understand whats going on, i will be glad to read it. Thanks in advance!


vsharma23 made it! (author)2014-10-10

I m new in Arduino and i m trying to make. i m using this motor controler can you plz help me how to connect it with arduino and dc motor.??

plz reply..

SantitheGreat made it! (author)SantitheGreat2015-09-20

i think the adafruit motor shield library would work fine for that, and they have a great website w/ tutorials (, but if it doesnt work just youtube or google sainsmart arduino motor shield tutorial

Arduino Tech made it! (author)Arduino Tech2014-10-30

I am stuck with the same problem

Ofibro made it! (author)Ofibro2015-06-10

go to

Ofibro made it! (author)Ofibro2015-06-10

it is theirs

CalvinC8 made it! (author)2015-08-24

I would like to know if i want to drive 4 motor, can i buy 2 motor shield and add those 2 shield togehter on arduino uno board??

SantitheGreat made it! (author)SantitheGreat2015-09-20

yes u could, but you couldnt drive each of the four motors separately, only two at a time.

myrddinstarhawk made it! (author)2015-08-10

About This Instructable




Bio: My name is Randy and I founded the Instructables Design Studio. I'm also the author of the books 'Simple Bots,' and '62 Projects to ... More »
More by randofo:Sponge BotSingle Motor BotChocolate Peanut Butter Fudge Recipe
Add instructable to: