Arduino Motor Shield r3 not turning motor A

Hello,
I have an Arduino Motor Shield r3, and whenever I try to make the 'A' motor run forward, it doesn't. When I try to make the 'A' motor run backwards, it doesn't, but it shines both of the indicator lights (forward, backward). I don't know the power rating for the motors, but they are small DC hobby motors attached to gearboxes. Any help would be appreciated. :slight_smile:

How are you powering everything? Have you run the motor direct from the
supply you are using OK?

Draw a schematic on a piece of printer paper and take a photo of it and post it. with your code.

I am powering everything currently off of a NI-MH 9-volt, at 175mAh. I could use 5 AA's, but they are still rechargeable.
I can guarantee my code, but I am sorry, for I am new to schematics.
Here is my code:

// Robo-rover
//
// by EthanL67
#include <SerialLCD.h>
#include <SoftwareSerial.h>
 int pwm_A=3; //set the PWM motor pins
 int pwm_B=11;
 int dir_A=12; //set direction motor pins
 int dir_B=13;
 int brke_A=9; //set the motor brake pins
 int brke_B=8;
 int sns_A=A0; //set the motor analog sensing pins
 int sns_B=A1;
 int distR=0;
 int distL=0;
 const int pingPin = 7;
 
void setup() 
{ 
 pinMode(brke_A, OUTPUT);
 pinMode(dir_A, OUTPUT);
 pinMode(brke_B, OUTPUT);
 pinMode(dir_B, OUTPUT);
 digitalWrite(pwm_A, HIGH);
 digitalWrite(pwm_B, HIGH);
}

void loop() {
digitalWrite(brke_A, LOW);
digitalWrite(brke_B, LOW);
digitalWrite(dir_A, LOW);
digitalWrite(dir_B, LOW);
  
int inches=ping();
  if(inches<=15) {
  
  digitalWrite(dir_A, HIGH);
  delay(500);
  digitalWrite(dir_A, LOW);
  digitalWrite(brke_A, HIGH);
  digitalWrite(brke_B, HIGH);
  delay(100);
  
  distL=ping();
  delay(100);
  digitalWrite(brke_A, LOW);
  digitalWrite(brke_B, LOW);
  digitalWrite(dir_B, HIGH);
  delay(750);
  digitalWrite(dir_A, LOW);
  digitalWrite(brke_A, HIGH);
  digitalWrite(brke_B, HIGH);
  delay(100);
  distR=ping();
  delay(100);
  digitalWrite(brke_A, LOW);
  digitalWrite(brke_B, LOW);

if(distR>distL) {
    digitalWrite(pwm_A, HIGH);
    digitalWrite(pwm_B, HIGH);
}if(distL>distR) {
  digitalWrite(dir_A, HIGH);
  delay(750);
  digitalWrite(dir_A, LOW);
}

  }
}
  int ping(){
      int duration, distance, inch;
       pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, HIGH);
  delay(200);
  digitalWrite(pingPin, LOW);
   pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);
  distance = (duration/2) / 29.1;
  inch = (distance * 0.3937);

  return inch;
  
}

Would you like me to make a schematic for the motor shield, or just the motors?
Thanks!

Motor shield link:

Also, here is the motor shield schematic:

the motors are just connected directly to the +/- (on the screw sockets).

When I try to make the 'A' motor run backwards, it doesn't,

but it shines both of the indicator lights (forward, backward)

. I don't know the power rating for the motors, but they are small DC hobby motors attached to gearboxes.

THESE PINS

 int pwm_A=3; //set the PWM motor pins
 iint pwm_A=3; //set the PWM motor pins
 int pwm_B=11;

 int dir_A=12; //set direction motor pins
 int dir_B=13;

should have leds connected to the driver input pins with 220 ohm resistors to ground so you can see the status of all the driver pins

I am sorry for the miscommunication, but I do not know what you are asking.

EthanL67:
I am powering everything currently off of a NI-MH 9-volt, at 175mAh. I could use 5 AA's, but they are still rechargeable.

Well that's likely to be the problem, a motor takes more current than those
batteries can source (for long) - separate supplies for logic and motors is
the general rule.

int pwm_A=3; //set the PWM motor pins
iint pwm_A=3; //set the PWM motor pins
int pwm_B=11;

int dir_A=12; //set direction motor pins
int dir_B=13;

I am sorry for the miscommunication, but I do not know what you are asking.

I have an Arduino Motor Shield r3, and whenever I try to make the 'A' motor run forward, it doesn't. When I try to make the 'A' motor run backwards, it doesn't, but it shines both of the indicator lights (forward, backward). I don't know the power rating for the motors, but they are small DC hobby motors attached to gearboxes. Any help would be appreciated.

If you knew what was wrong you wouldn't be posting. I am saying if you add leds on the driver input lines you can see the motor control signal status at a glance and you can tell us what you see and we can make a determination .
It's up to you. If you would rather use a meter to measure the voltage on those pins to ascertain the status that's your call.
I just think it makes more sense to be able to see the status of all the control lines at a glance.

Ok, sorry. I fixed the problem, my microcontroller is a Seeeduino V3.0, when I switched to an Uno, it worked! XD
Thank you, and also the battery was part of the problem. (switched to 5 x AAs.) Also, I am really sorry because I am new to the forum :blush:

If both FWD and REV lines are turned on to an L298, it will go into "brake" mode whereby it shorts the motor leads together. My experience is a more generic board with the L298 on it, and each input has an LED as Raschemmel suggested you add.

I haven't studied your code to understand it, i guess no one uses comments anymore. As a general suggestion, don't just start out making everything the INT data type. You're just wasting RAM. When it comes to pin numbers use BYTE, it only chews up one byte, where an INT chews up two. If the value never changes, why make it a VAR at all? Why not something like:

#define pwm_A 3; //set the PWM motor pins
#define pwm_B 11;
#define dir_A 12; //set direction motor pins
#define dir_B 13;
#define brke_A 9; //set the motor brake pins
#define brke_B 8;
#define sns_A A0; //set the motor analog sensing pins
#define sns_B A1;
int distR=0;
int distL=0;
unsigned int Value;
#define pingPin 7;

Then, an analogRead would look like Value = (analogRead(sns_B) & 0000001111111111);

Not slamming you, Ethan. Just suggesting some programming methods that save memory and sanity.