My motor shield is only controlling one motor when my code is for two

Hi, everyone. I received the Ardumoto L298P for a gift (, and I have found some code on the internet that was able to move two motors. The code turns motor b but not motor a. I have looked for errors in the code, but I haven't found any. I think my motor shield is broken because on the left side of my board, lights come on telling me what my motor is doing. On the left side of the board nothing is happening to the lights. Here is a link to the site.

Here is the code:

/* Ardumoto Example Sketch
  by: Jim Lindblom
  date: November 8, 2013
  license: Public domain. Please use, reuse, and modify this 

  Three useful functions are defined:
    setupArdumoto() -- Setup the Ardumoto Shield pins
    driveArdumoto([motor], [direction], [speed]) -- Drive [motor] 
      (0 for A, 1 for B) in [direction] (0 or 1) at a [speed]
      between 0 and 255. It will spin until told to stop.
    stopArdumoto([motor]) -- Stop driving [motor] (0 or 1).

  setupArdumoto() is called in the setup().
  The loop() demonstrates use of the motor driving functions.

// Clockwise and counter-clockwise definitions.
// Depending on how you wired your motors, you may need to swap.
#define CW  0
#define CCW 1

// Motor definitions to make life easier:
#define MOTOR_A 0
#define MOTOR_B 1

// Pin Assignments //
// Don't change these! These pins are statically defined by shield layout
const byte PWMA = 3;  // PWM control (speed) for motor A
const byte PWMB = 11; // PWM control (speed) for motor B
const byte DIRA = 12; // Direction control for motor A
const byte DIRB = 13; // Direction control for motor B

void setup()
  setupArdumoto(); // Set all pins as outputs

void loop()
  // Drive motor A (and only motor A) at various speeds, then stop.
  driveArdumoto(MOTOR_A, CCW, 255); // Set motor A to CCW at max
  delay(1000);  // Motor A will spin as set for 1 second
  driveArdumoto(MOTOR_A, CW, 127);  // Set motor A to CW at half
  delay(1000);  // Motor A will keep trucking for 1 second 
  stopArdumoto(MOTOR_A);  // STOP motor A 

  // Drive motor B (and only motor B) at various speeds, then stop.
  driveArdumoto(MOTOR_B, CCW, 255); // Set motor B to CCW at max
  delay(1000);  // Motor B will spin as set for 1 second
  driveArdumoto(MOTOR_B, CW, 127);  // Set motor B to CW at half
  delay(1000);  // Motor B will keep trucking for 1 second
  stopArdumoto(MOTOR_B);  // STOP motor B 

  // Now spin both!
  driveArdumoto(MOTOR_A, CW, 255);  // Motor A at max speed.
  driveArdumoto(MOTOR_B, CW, 255);  // Motor B at max speed.
  delay(1000);  // Drive forward for a second
  // Now go backwards at half that speed:
  driveArdumoto(MOTOR_A, CCW, 127);  // Motor A at max speed.
  driveArdumoto(MOTOR_B, CCW, 127);  // Motor B at max speed.

// driveArdumoto drives 'motor' in 'dir' direction at 'spd' speed
void driveArdumoto(byte motor, byte dir, byte spd)
  if (motor == MOTOR_A)
    digitalWrite(DIRA, dir);
    analogWrite(PWMA, spd);
  else if (motor == MOTOR_B)
    digitalWrite(DIRB, dir);
    analogWrite(PWMB, spd);

// stopArdumoto makes a motor stop
void stopArdumoto(byte motor)
  driveArdumoto(motor, 0, 0);

// setupArdumoto initialize all pins
void setupArdumoto()
  // All pins should be setup as outputs:
  pinMode(PWMA, OUTPUT);
  pinMode(PWMB, OUTPUT);
  pinMode(DIRA, OUTPUT);
  pinMode(DIRB, OUTPUT);

  // Initialize all pins as low:
  digitalWrite(PWMA, LOW);
  digitalWrite(PWMB, LOW);
  digitalWrite(DIRA, LOW);
  digitalWrite(DIRB, LOW);

Please put your code in its own window as seen in other posts. This can be done by placing     [code]  and [/code]  around the code or use the </> icon. This makes it easier for others to read.

How to use this forum

Please give us a circuit to show how the motors are connected. Hand drawn and photographed will do.


Here they are


You didn't read the post by weedpharma or worse, chose to ignore it. Remember that you are the one needing help, so all relevant information needs to come from you and you are supposed to hand it in such way that they are ready to be examined by anyone willing to spend her/his valuable time to solve your problem for you. If you do so, maybe someone is willing to help you out. If you don't you have to wait for someone stupid enough like me right now to do your work and look up that site, copy your code to examine it and watch a bunch of out of focus and therefore useless pictures to be found by any of the offered sources.

The gift you got was some rip off, not the product you assumed you got. Don't blame the person that got you the gift, they probably didn't have a clue what they were giving.

Your problem here is this: Your code doesn't match the hardware.

OP, please edit your original post to put code tags around the code section.

The reason for them is to make the code appear exactly as it is in the IDE. It also makes it easier for the helper to copy to their PC to run and test.

The photos are unclear do not show clearly the board identification. A link would be better.


My board is the L298P by Ficbox. I was messing with the motor shield, and motor b lights were blinking. I moved the black cord thatconnects the computer to the Arduino a little, and the motor a lights started to blink faintly. They stopped a few seconds later. I started to move the black cable, and the lights blinked at full power for a while. If I moved the cable a little, they stopped. They don't run anymore. Could there be a broken wire that when I shake the motor shield a little, the wire touch and can send the current?


Where’s the power supply ?
What’s the specifications of those motors ?

The now correct placed code in your first post, still doesn’t match the hardware.

There’s a lot wrong so it seems.
Tackle it one by one.