Motor Shield Newbie

I'm sure the answer is here somewhere but I can't seem to find it! :slight_smile:
I have an Arduino Uno and an Arduino Motor Shield Rev 3. I'm looking for some very basic directions on how to use the Motor Shield. I see how to hook it up but surely there's somewhere I can get some sample code to demonstrate how to program it. Is there a library I need to download? I'm simply hooking up a little 6V DC Motor and a 6V battery. I'd like to see some simple code that shows me how to control its speed and direction. Braking and Current monitoring would be a bonus.

Please point me at something to get me started?

Thanks for your help.

Hi, sounds as tho you're where I'm at... I found this video which is helpful... I'm struggling with limit switch right now

This one is a quick hookup guide, but the code worked for me Nema 17 Stepper Motor with Arduino CNC Sheild V3 (A4988 Driver) | 100% Working Arduino Code - YouTube

This one goes into more detail, tho it's not quite the same as my 3 axis shield

Good luck

I didn’t find any information on the use of the Motor Shield, but I think I figured it out. In case anyone stumbles on this post, here is the sample code. With the motor I have, I can’t really tell if the brake works.

//Arduino Motor Shield Test
int motor1DirPin = 12;      // Motor direction 
int motor1SpeedPin = 3;    // Motor speed 
int motor1BrakePin = 9;   // Motor Brake
int motor1CurrentPin = A0;   // Motor Current
int motor2DirPin = 13;      // Motor direction 
int motor2SpeedPin = 11;    // Motor speed 
int motor2BrakePin = 8;   // Motor Brake
int motor2CurrentPin = A1;   // Motor Current

int current1Value = 0;
int current2Value = 0;
float current1 = 0;
float current2 = 0;

int RampDel = 20;
int ShortDel = 500; 
int LongDel = 10000;

void setup()
  pinMode(motor1DirPin, OUTPUT);       // sets the pin as output
  pinMode(motor1SpeedPin, OUTPUT);     // sets the pin as output
  pinMode(motor1BrakePin , OUTPUT);     // sets the pin as output
  pinMode(motor1CurrentPin , INPUT);     // sets the pin as input

  digitalWrite(motor1DirPin, LOW);     // sets the default dir to be forward
  digitalWrite(motor1SpeedPin, LOW);   // sets the default speed to be off
  digitalWrite(motor1BrakePin, LOW);   // sets the default brake to be off


void loop()
  digitalWrite(motor1DirPin, LOW);   // Set the motor direction to forward  
  delay (3000);
  digitalWrite(motor1DirPin, HIGH);   // Set the motor direction to reverse

void go()
  // Ramp the motor speed up
   Serial.println("Ramp Up");
   analogWrite(motor1BrakePin, LOW);  // Brake Off
   for (int x = 79 ; x< 256; x++)    // 79 is minimum to start motor
    analogWrite(motor1SpeedPin, x);    // motor off

   Serial.println("Ramp Down ");
  // Ramp the motor speed down
  for (int x = 255; x>=79; x--)
    analogWrite(motor1SpeedPin, x);   
  analogWrite(motor1SpeedPin, 0);   
  analogWrite(motor1BrakePin, HIGH);  // Brake On

void getCurrent()
  float current1 = 0;
  float voltage1 = 0;
  for (int z = 0 ; z< 5; z++)
  current1Value = analogRead(motor1CurrentPin);
  Serial.print("Value1 = ");
  voltage1 = 0.0032227 * current1Value;
  voltage1 = 0.0032227 * current1Value;
  Serial.print("   Voltage 1 =  ");
  current1 = 0.6061 * voltage1;
  Serial.print("   Current 1 =  ");
  Serial.println(" ");


Please use code tags as explained in the links below.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Thanks for your help. There's so much to learn when you're just starting! I'll endeavor to do better.