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:

<p>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.</p>
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 &quot;delaylegnth&quot; supposed to be &quot;delaylength&quot; (as I said, just starting, so I am not familiar with the syntax quirks). Thanks!
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. <br /><br />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
<p>Hi there,</p><p>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...</p><p>I've been trying hard to understand what I should do, but there is little to no documentation supporting the motor shield. Help?! :)</p>
<p>hi great project</p><p>+_____+_________+_________+__________+__________+_________+</p><p>i have a problem with my external power supply</p><p>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.</p><p>============</p><p><strong><em>NO MATTER WHAT I TRY IT ONLY WORKS WITH THE USB POWER SUPPLY</em></strong></p><p>============</p><p>to make matters worse, i bought another one yet still no use i borrowed two of them from my friend yet STILL no use</p><p>============</p><p>im deeply in need of you</p><p>============</p><p>P.S i know how to program it really good my problem lies on the power supply </p><p> cheers</p><p> mwnllt</p><p>+___________+__________+___________+_____________+__________+______+</p>
<p>WOW,</p><p>just to the point of giving up I FINNALY got it.</p><p>all that it needed was amps.</p><p>I was using an lakline 9V battery which supplied 500mAh, which of course wasnt enough..</p><p>so i bought a couple of rechargeable batteries and VOLA it worked</p><p>keep in mind that those rechargeable batteries were 2200mAh @ 1.2 volts x5 so that was enough to get those motors moving!! </p><p>thanks anyways and great project.</p><p>cheers.</p>
<p>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</p>
<p>u have to use a regular battery pack for the arduino itself, then an extra 9v battery.</p>
Now that you have pointed it out, the difference between the versions is obvious. Thank you!
<p>Hey hey, try someone to use this motorshield with arduino duemilanove? If yes can you help me with it? I am beginner.</p><p>Thanks a lot!</p>
<p>How would you go about using the code above with a switch to stop the stepper motor kind of like a endstop.</p><p>so far I have it stopping but it will stop after the loop is completed, is there a way to stop it right away?</p><p>cheers</p><p>Dave</p>
<p>Will this work on the Arduino Mega 2560 R3? I want to use this in a obstacle avoiding robot.</p><p>And the link to the motor shield is broken</p>
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 <br><br><br><br>can any one help me<br>
I have ordered same motor driver shield for my project<br>I have a doubt that can we move 2 motors and 1 stepper sinultaneously???<br>
<p>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?</p>
<p>Thanks for the tutorial, I made it and it was great! I also like the way you put in the code meaning and code.</p>
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)
<p>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. </p>
<p>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?</p>
to which pin , you connected the IR reciever??
<p>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</p>
<p>is this code ok to drive 2 motors front right back and left.</p><p>void setup() {<br>pinMode (2,OUTPUT);//RIGHT MOTOR<br>pinMode (3, OUTPUT);//RIGHT MOTOR<br>pinMode (4,OUTPUT);//LEFT MOTOR<br>pinMode (5, OUTPUT);//LEFT MOTOR<br>}</p><p>void loop() {<br> //front <br> digitalWrite (2, LOW);//RIGHT MOTOR<br> analogWrite (3, 250);//RIGHT MOTOR<br> digitalWrite (4, LOW);//LEFT MOTOR<br> analogWrite (5, 250);//LEFT MOTOR<br> //left<br> digitalWrite (2, LOW);//RIGHT MOTOR<br> analogWrite (3, 150);//RIGHT MOTOR<br> digitalWrite (4, HIGH);//LEFT MOTOR<br> analogWrite (5, 105);//LEFT MOTOR<br> //back<br> digitalWrite (2, HIGH);//RIGHT MOTOR<br> analogWrite (3, 125);//RIGHT MOTOR<br> digitalWrite (4, HIGH);//LEFT MOTOR<br> analogWrite (5, 125);//LEFT MOTOR<br> //right<br> digitalWrite (2, HIGH);//RIGHT MOTOR<br> analogWrite (3, 105);//RIGHT MOTOR<br> digitalWrite (4, LOW);//LEFT MOTOR<br> analogWrite (5, 150);//LEFT MOTOR<br>}</p>
<p>Hi everybody,</p><p>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 http://www.gotronic.fr/pj-784.pdf).</p><p>I have been following the <a href="https://vimeo.com/digitalcoleman" rel="nofollow">Chris Coleman</a> tutorial on vimeo but i might have a problem with the setting of the pin.</p><p>From the arduino software, this code works:</p><p>int delaylegnth = 30;</p><p>void setup() {</p><p> //establish motor direction toggle pins</p><p> pinMode(12, OUTPUT); //CH A -- HIGH = forwards and LOW = backwards???</p><p> pinMode(13, OUTPUT); //CH B -- HIGH = forwards and LOW = backwards???</p><p> //establish motor brake pins</p><p> pinMode(9, OUTPUT); //brake (disable) CH A</p><p> pinMode(8, OUTPUT); //brake (disable) CH B</p><p>}</p><p>void loop(){</p><p> digitalWrite(9, LOW); //ENABLE CH A</p><p> digitalWrite(8, HIGH); //DISABLE CH B</p><p> digitalWrite(12, HIGH); //Sets direction of CH A</p><p> analogWrite(3, 255); //Moves CH A</p><p> delay(delaylegnth);</p><p> digitalWrite(9, HIGH); //DISABLE CH A</p><p> digitalWrite(8, LOW); //ENABLE CH B</p><p> digitalWrite(13, LOW); //Sets direction of CH B</p><p> analogWrite(11, 255); //Moves CH B</p><p> delay(delaylegnth);</p><p> digitalWrite(9, LOW); //ENABLE CH A</p><p> digitalWrite(8, HIGH); //DISABLE CH B</p><p> digitalWrite(12, LOW); //Sets direction of CH A</p><p> analogWrite(3, 255); //Moves CH A</p><p> delay(delaylegnth);</p><p> digitalWrite(9, HIGH); //DISABLE CH A</p><p> digitalWrite(8, LOW); //ENABLE CH B</p><p> digitalWrite(13, HIGH); //Sets direction of CH B</p><p> analogWrite(11, 255); //Moves CH B</p><p> delay(delaylegnth);</p><p>}</p><p>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.</p><p>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!</p><p>Pierre</p>
<p>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.??</p><p>plz reply..</p>
<p>i think the adafruit motor shield library would work fine for that, and they have a great website w/ tutorials (adafruit.com), but if it doesnt work just youtube or google sainsmart arduino motor shield tutorial</p>
I am stuck with the same problem
<p>go to adafruit.com </p>
<p>it is theirs</p>
<p>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??</p>
<p>yes u could, but you couldnt drive each of the four motors separately, only two at a time.</p>
<p>If your device requires more current and you are feeling rich you can just piggyback another motor shield on top and and join the connection block together.<br></p>
<p>You may try using &quot;<a href="https://processing.org/" rel="nofollow">https://processing.org/</a>&quot; which is an advanced arduino based PDE file writing app. If you are up to the programming aspects it should be able to allow you to create what you need. larystoy@yahoo.com</p>
<p>Did you ever get it figured out? This is what I'm trying to do as well.</p><p>train459 [at] gmail</p>
Podria alimentar el shield con 24 voltios para un canal a 2 amp para usar un solo motor. b_ playa1@hotmail.com muchas gracias
<p>Does it matter what order you connect the two coils? What if you reverse the two wire to one of the coils, will it still work?</p>
<p>For that matter, how do you connect a uni-polar stepper? Where does the fifth wire go?</p>
<p>I have a arduino motor shield, and I was using it with my arduino uno rev3.This birthday I bought a arduino mega 2560r3. So I just wanted to know if it would work with my shield</p>
<p>I have a arduino motor shield, and I was using it with my arduino uno rev3.This birthday I bought a arduino mega 2560r3. So I just wanted to know if it would work with my shield</p>
<p>What if i want to control 4 motors? what would be the possible solutions? thank you. :)</p>
<p>Hi there,</p><p>Thanks for this instructable, very good and clear</p><p>I have a problem with the power.</p><p>I have 2 motor, the arduino uno + motorshield v3</p><p>When i'm in USB, no need of external power, everything works.</p><p>If i put USB + shield external power -&gt;</p><p>But as soon as i unplug USB, no matter what, nothing works:</p><p>9v External Uno + 9v external motor shield -&gt; nothing happen</p><p>is there some specific wiring to do when using 2 external power supply?</p><p>Thanks again for your help</p>
<p>Hi </p><p>Do you have a solution and a code to control these two motors dc with an analog Joystick like <a href="http://www.robotshop.com/eu/fr/mini-capteur-manche-cytron.html" rel="nofollow">http://www.robotshop.com/eu/fr/mini-capteur-manche...</a></p><p>Thank you for your help</p>
<p>I am also looking for a solution to this. Please let me know if you find out.</p><p>Thanks </p>
<p>I find a system by software for can control one unipolar stepper motor using one Arduino Motor Shield R3</p><p><br>I use this and there are an example of 3 unipolar stepper motors using 3 Arduino Motor Shield R3 into my free APP &quot;Arduino CNC Controller&quot; I put instructions and pictures explain how to connect 3 boards, I use one Arduino Mega 2560 R3</p><p>Really there are 2 examples, the first example is using 3 bipolar stepper motors, that is normal example, and second example is using 3 unipolar/monopolar stepper motors.</p><p><br>Is free on Google Play: &quot;Arduino CNC Controller&quot;</p><p>https://play.google.com/store/apps/details?id=net.sourceforge.arduinocnccontroller</p><p><a href="https://play.google.com/store/apps/details?id=net.sourceforge.arduinocnccontroller" rel="nofollow">https://play.google.com/store/apps/details?id=net....</a><br><br>This APP have a Window of &quot;Help and documentation&quot; in witch you can read this source code example.<br><br>Or you can download on:</p><p><a href="http://sourceforge.net/projects/arduinocnccontroller/files/" rel="nofollow">http://sourceforge.net/projects/arduinocnccontroll...</a></p>

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:Hard Candy Recipe2-Ingredient CandyTeeth Candy
Add instructable to: