How to spin motor backwards and where to plug it ?

Hello.
I have this motor shield "41468" Arduino L293D Motor Drive Shield - emartee.com
And I tried this code:

// ConstantSpeed.pde
// -*- mode: C++ -*-
//
// Shows how to run AccelStepper in the simplest,
// fixed speed mode with no accelerations
// Requires the AFMotor library (https://github.com/adafruit/Adafruit-Motor-Shield-library)
// And AccelStepper with AFMotor support (https://github.com/adafruit/AccelStepper)
// Public domain!

#include <AccelStepper.h>
#include <AFMotor.h>

AF_Stepper motor1(200, 1);


// you can change these to DOUBLE or INTERLEAVE or MICROSTEP!
void forwardstep() {  
  motor1.onestep(FORWARD, SINGLE);
}
void backwardstep() {  
  motor1.onestep(BACKWARD, SINGLE);
}

AccelStepper stepper(forwardstep, backwardstep); // use functions to step

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

void loop()
{  
   stepper.runSpeed();
}

Motor spins clockwise if I plug it to black+red wires and black+blue on the shield (image attached).

  • I am not sure what are the right connectors on the shield for the 2 wire motors.
  • How to make it spin in the other direction? Shield says it has "H bridges" which I understand is what I need.

Thank you.

The motor has only two wires so it isn't a stepper motor.

A DC motor connects to the two M1 (or M2, or M3, or M4) terminals. The H-bridge will switch those two terminals from +,- to -,+ to change direction.

See the instructions here for DC Motors: Arduino motor/stepper/servo control - How to use

The sample program uses the M3 connector:

#include <AFMotor.h>

AF_DCMotor motor(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor test!");
  
  motor.setSpeed(200);     // set the speed to 200/255
}

void loop() {
  Serial.print("tick");
  
  motor.run(FORWARD);      // turn it on going forward
  delay(1000);

  Serial.print("tock");
  motor.run(BACKWARD);     // the other way
  delay(1000);
  
  Serial.print("tack");
  motor.run(RELEASE);      // stopped
  delay(1000);
}

I don't understand how the connectors are grouped.
Which would be the two M1 connectors for example? Because they are grouped by 5 :~

If you look at the picture you took of your board, the Red and Blue wires are in the M1 terminals. Note the label "M1" just above them. The center terminal is a Ground terminal used for some types of stepper motors. The bottom two terminals are the M2 terminals. Note the label "M2" just to the right of them. The M3 and M4 terminals are on the other end of the board.

AF_DCMotor motor1(0, MOTOR12_64KHZ); // Control DC motor on M1 terminals. 64KHz pwm
AF_DCMotor motor2(1, MOTOR12_64KHZ); // Control DC motor on M2 terminals. 64KHz pwm
AF_DCMotor motor3(2, MOTOR12_64KHZ); // Control DC motor on M3 terminals. 64KHz pwm
AF_DCMotor motor4(3, MOTOR12_64KHZ); // Control DC motor on M4 terminals. 64KHz pwm

Yesterday with your code I kept testing on all pins and it only worked in one direction.
Today I connected the M1 you mentioned (blue+red) from image and replaced
AF_DCMotor motor(2, MOTOR12_64KHZ);
with
AF_DCMotor motor(1, MOTOR12_64KHZ);

And works nicely in both directions. Maybe the M2 is not one of the ones with H bridge, I test more later, M1 works in both directions.
Thanks for all your help :slight_smile:

With this code I am able to make motors 1,3,4 to work but the #2 doesn't move at all. Maybe I burned something when I tested the pins to use (weeks ago) :blush:.
Is there some part on the board that I could check/replace? Anything else that might cause M2 not to work when 1,3,4 work?
I used the code below and just edited this number: "AF_DCMotor motor(1"
Thank you.

#include <AFMotor.h>

AF_DCMotor motor(1, MOTOR12_1KHZ); // create motor #1, 64KHz pwm

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor test!");
  
  motor.setSpeed(200);     // set the speed to 200/255
}

void loop() {
  Serial.print("tick");
  
  motor.run(FORWARD);      // turn it on going forward
  delay(1000);

  Serial.print("tock");
  motor.run(BACKWARD);     // the other way
  delay(1000);
  
  Serial.print("tack");
  motor.run(RELEASE);      // stopped
  delay(1000);
}

If the M2 terminals don't work it is likely the L293D chip at that end of the board is fried. It's in a socket so it won't be hard to replace.

You can determine faulty L293D chip by replacing it between other channel and if only chip itself is faulty then channel 2 should work with chip taken other working channel.

Yes, I think most probably I burned one of the chips. Yesterday I stopped playing with it for a while, I will test that soon.
Thanks for the suggestions.