Instructables

how do you program a arduino motor shield?

i have an arduino motor shield from seeed studio and i have to learn how to program it in two weeks from today today is 12/31/12 well i barley know how to program arduino but i will learn step by step by the way it is an arduino uno not rev 3. PS if this link is any use to you here you go http://www.seeedstudio.com/wiki/Motor_Shield_V1.0

Picture of how do you program a arduino motor shield?
IMG0003.jpg
I have this shield as well. It is the Seeed Studio Motor Shield, version 1.0. It is not the version 2.0.
You can see the example programs and pictures here,
http://www.seeedstudio.com/wiki/Motor_Shield_V1.0
on how to run either
a) 1 or 2 motors simultaneously, these are 2 wire motors.
b) 2 Phase, 4 wire stepper motors.
You can't run a) and b) together with this Motor Shield.
c) If you want to run 3 wire stepper motors you need to connect to one of the white ports's pins correctly, and use + modify this code here http://arduino.cc/en/Tutorial/Knob or http://arduino.cc/en/Tutorial/Sweep
And learn how to use Arduino at Arduino.cc
You can use Arduino UNO revision 3 or below i.e. rev 2, no problems with Motor Shield V1.0
Good luck!
Oh... the example code for the 2 wire motors... here:
// From: http://www.seeedstudio.com/wiki/Motor_Shield_V1.0
// Notes by Steven Khong YF: If the Jumper J4 is connected / not removed form the board, then
// you can just power the motor using the USB cable from the PC.
// Then if you unplug the USB cable, then you can power both the Arduino UNO
// and the motor using the power supply terminals i.e. 9V battery
// as the internal regulator will regulate the voltage to 5V for the Arduino.
// With the USB port opposite you / facing the other way, you are facing the
// black heatsink with the L298N CZOPC209 chip,
// Green terminal: Leftmost = Ground = Negative / Black Cable to your power supply
// Rightmost = Positive / Red Cable to your power supply
//
// With the USB port facing you, the Green motor connectors are:
// Left = Out 4 = M2 positive / Red cable to the Motor #2,
// Out 3 / Step Motor = M2 negative / Ground / Black cable to the Motor #2
// Out 2 / Step Motor = M1 positive / Red cable to the Motor #1,
// Rightmost = Out 1 = M1 negative / Ground / Black cable to the Motor #1
//. Motor driver shield- 2012 Copyright (c) Seeed Technology Inc.
//
// Original Author: Jimbo.we
// Contribution: LG
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

int pinI1=8;//define I1 interface
int pinI2=11;//define I2 interface
int speedpinA=9;//enable motor A
int pinI3=12;//define I3 interface
int pinI4=13;//define I4 interface
int speedpinB=10;//enable motor B
int spead =127;//define the spead of motor

void setup()
{
pinMode(pinI1,OUTPUT);
pinMode(pinI2,OUTPUT);
pinMode(speedpinA,OUTPUT);
pinMode(pinI3,OUTPUT);
pinMode(pinI4,OUTPUT);
pinMode(speedpinB,OUTPUT);
}

void forward()
{
analogWrite(speedpinA,spead);//input a simulation value to set the speed
analogWrite(speedpinB,spead);
digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
digitalWrite(pinI3,LOW);
digitalWrite(pinI2,LOW);//turn DC Motor A move anticlockwise
digitalWrite(pinI1,HIGH);
}
void backward()//
{
analogWrite(speedpinA,spead);//input a simulation value to set the speed
analogWrite(speedpinB,spead);
digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise
digitalWrite(pinI3,HIGH);
digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
digitalWrite(pinI1,LOW);
}
void left()//
{
analogWrite(speedpinA,spead);//input a simulation value to set the speed
analogWrite(speedpinB,spead);
digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
digitalWrite(pinI3,LOW);
digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
digitalWrite(pinI1,LOW);
}
void right()//
{
analogWrite(speedpinA,spead);//input a simulation value to set the speed
analogWrite(speedpinB,spead);
digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise
digitalWrite(pinI3,HIGH);
digitalWrite(pinI2,LOW);//turn DC Motor A move clockwise
digitalWrite(pinI1,HIGH);
}
void stop()//
{
digitalWrite(speedpinA,LOW);// Unenble the pin, to stop the motor. this should be done to avid damaging the motor.
digitalWrite(speedpinB,LOW);
delay(1000);

}

void loop()
{
left();
delay(2000);
stop();
right();
delay(2000);
stop();
// delay(2000);
forward();
delay(2000);
stop();
backward();
delay(2000);
stop();
}
sgupta954 months ago

Can someone tell me what does the line "spead = 127;" mean? I know it sets the speed of motor but can it be changed?

mibz man1 year ago
i have the exact same shield, but the link seems to be broken. for whatever reason i cant get at any sample and i have no idea where to begin! could somebody copy/paste the code here so i could get a feel of how to use it? any help would be amazing!
frollard1 year ago
I see a motor shield...I don't see an arduino. Please confirm you have the microcontroller board to go with the motor shield? (you mention the uno but we need to be sure).

Most motor shields are exactly that, heavy duty transistors that turn on and off with various digital io pins.

You sometimes use a library with the shield so that some functions are already done for you.

http://www.seeedstudio.com/wiki/images/9/96/Grobe-_Motor_Shield_Demo_Code.zip refers to an example piece of code to work with 2 motors.
kjsrocks (author)  frollard1 year ago
thanks that helped alot