Motor Driver Shield

The Motor Driver Shield [Product Link] for Arduino Uno [Product Link] and Arduino Mega [Product Link]

Features

Motor Driver Shield
Motor Driver Shield
  • 2 3-pin headers for Servo motors
  • 2 5-pin connectors for Stepper motor
  • Each Stepper motor connecter can be used for 2 DC motors
  • 6 rows for connecting sensors to Analog ports
  • Input Voltage: 5-12V
  • Compatible with Arduino Uno and Mega
  • Switchable External/Internal Power Supply

Description

Servo

The digital pins 9 and 10 are set as servo pins on the Motor Driver Shield [Product Link]. To use these pins, include “Servo.h” header file, create servo objects, then attach your servo object to the desired pin, and use it according to your need.

One can attach the 2 servo motors at the upper left corner of the Shield marked as SERVO_1 and SERVO_2.


//In this code first motor rotates from zero to 180 degrees and then from 180 to zero degrees.
#include <Servo.h>

Servo jservo1;
Servo jservo2;
int pos = 0; // variable to store the servo position

void setup()
{
jservo1.attach(10); // attaches the servo on pin 10 to the servo object , this is for first connection on motor shield
jservo2.attach(9); // attaches the servo on pin 9 to the servo object , this is for second connection on motor shield
}

void loop()
{
for(pos = 0; pos <= 180; pos++) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
jservo1.write(pos);
jservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}

for(pos = 180; pos>=0; pos--) // goes from 180 degrees to 0 degrees
{
jservo1.write(pos);
jservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}

DC Motors

To use the 4 DC motor ports on the shield, make sure you include “AFMotor.h” library. Create the AF_DCMotor object with AF_DCMotor(motor#, frequency), to setup the motor H-bridge and latches. The constructor takes two arguments:
1. Port number the motor is connected to: 1, 2, 3 or 4.
2. Frequency is how fast the speed controlling signal is. For Motors 1 and 2 you can choose MOTOR12_64KHZ, MOTOR12_8KHZ, MOTOR12_2KHZ, or MOTOR12_1KHZ. Motors 3 & 4 are only possible to run at 1KHz and will ignore any setting given.

To set the speed of the motor, use setSpeed(speedval) where the speedval ranges from 0 (stopped) to 255 (full speed). You can set the speed whenever you want.

To run the motor, call run(direction) where direction is FORWARD, BACKWARD or RELEASE. Of course, theĀ  Motor Driver Shield [Product Link] doesn’t actually know if the motor is ‘forward’ or ‘backward’, so if you want to change which way it thinks is forward, simply swap the two wires from the motor to the shield.


#include &lt;JMotor.h&gt;

JM_DCMotor motor(2);

void setup()

{
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Motor test!");

// turn on motor
motor.setSpeed(200);

motor.run(STOP);
}

void loop()

{
uint8_t i;

Serial.print("tick");

motor.run(FORWARD);
for (i=0; i&lt;255; i++) {
motor.setSpeed(i);
delay(10);
}

for (i=255; i!=0; i--) {
motor.setSpeed(i);
delay(10);
}

Serial.print("tock");

motor.run(BACKWARD);
for (i=0; i&lt;255; i++) {
motor.setSpeed(i);
delay(10);
}

for (i=255; i!=0; i--) {
motor.setSpeed(i);
delay(10);
}

Serial.print("tech");
motor.run(STOP);
delay(1000);
}

<span style="line-height: 1.5;">}</span>

 

Stepper Motor

This Motor Driver Shield provides you the option to connect 2 stepper motors to it, if you remove all the 4 DC motors from the board. M1 and M2 are collectively used for 1 Stepper motor, and similarly, the second Stepper is connected across M3 and M4 pins of Motor Driver Shield.

In the program, while using JMotor.h library, you need to define the place where you are connecting your stepper motor. 1 becomes the port of M1 and M2, while 2 becomes the port of M3 and M4.


#include <JMotor.h>

// Connect a stepper motor with 48 steps per revolution (7.5 degree)
// to motor port #2 (M3 and M4)
JM_Stepper motor(48, 2);

void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Stepper test!");

motor.setSpeed(10); // 10 rpm
}

void loop() {
Serial.println("Single coil steps");
motor.step(100, FORWARD, SINGLE);
motor.step(100, BACKWARD, SINGLE);

Serial.println("Double coil steps");
motor.step(100, FORWARD, DOUBLE);
motor.step(100, BACKWARD, DOUBLE);

Serial.println("Interleave coil steps");
motor.step(100, FORWARD, INTERLEAVE);
motor.step(100, BACKWARD, INTERLEAVE);

Serial.println("Micrsostep steps");
motor.step(100, FORWARD, MICROSTEP);
motor.step(100, BACKWARD, MICROSTEP);
}

Comments

So empty here ... leave a comment!

Leave a Reply

Your email address will not be published. Required fields are marked *

Sidebar