owi arm IR control problems

i have been trying to control an owi robotic arm with a tv remote. I have hooked up four of the motors to a motor control board and plugged in the IR receiver. This is my code:

#include <IRremote.h>
#include <IRremoteInt.h>
#include <AFMotor.h>


AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);
int RECV_PIN = A5;
IRrecv irrecv(RECV_PIN);
decode_results results;
#define button1 0x1DE807F
#define button2 0x1DE40BF
#define button3 0x1DEC03F
#define button4 0x1DE20DF
#define button5 0x1DEA05F
#define button6 0x1DE609F
#define button7 0x1DEE01F
#define button8 0x1DE10EF
#define button9 0x1DE906F

void setup() {
  
  motor1.setSpeed(200);
  motor1.run(RELEASE);
  motor2.setSpeed(200);
  motor2.run(RELEASE);
  motor3.setSpeed(200);
  motor3.run(RELEASE);
  motor4.setSpeed(200);
  motor4.run(RELEASE);
  irrecv.enableIRIn();
}

void loop() {
  if (irrecv.decode(&results)){
   if (results.value == button1) {               //wrist
    motor2.run(FORWARD);
    delay(100);
    motor2.run(RELEASE);
   }
   else if (results.value == button2) {         //wrist
    motor2.run(BACKWARD);
    delay(100);
    motor2.run(RELEASE);
   }
   else if (results.value == button4) {         //elbow
    motor3.run(FORWARD);
    delay(100);
    motor3.run(RELEASE);
   }
   else if (results.value == button5) {        //elbow
    motor3.run(BACKWARD);
    delay(100);
    motor3.run(RELEASE);
   }
   else if (results.value == button7) {        //shoulder
    motor4.run(FORWARD);
    delay(100);
    motor4.run(RELEASE);
   }
   else if (results.value == button8) {       //shoulder
    motor4.run(BACKWARD);
    delay(100);
    motor4.run(RELEASE);
   }
   else if (results.value == button3) {       //gripper
    motor1.run(FORWARD);
    delay(100);
    motor1.run(RELEASE);
   }
   else if (results.value == button6) {       //gripper
    motor1.run(BACKWARD);
    delay(100);
    motor1.run(RELEASE);
   }
  irrecv.resume();
  }
}

I am powering the arm with a 7.2v battery pack and the separately arduino with a 5V USB battery pack. The problem is that motors 3 and 4 work fine but motors 1 and 2 show no signs of life. I have checked the motor shield with another sketch and it works fine, I've also checked the remote codes and they are correct. I have also tried control with a sketch using switch case statements but that doesn't work at all this is the code:

 #include <IRremote.h>
#include <IRremoteInt.h>
#include <AFMotor.h>


AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);
int RECV_PIN = A5;
IRrecv irrecv(RECV_PIN);
decode_results results;

#define button1 0x1DE807F
#define button2 0x1DE40BF
#define button3 0x1DEC03F
#define button4 0x1DE20DF
#define button5 0x1DEA05F
#define button6 0x1DE609F
#define button7 0x1DEE01F
#define button8 0x1DE10EF
#define button9 0x1DE906F

void setup() {
  
  motor1.setSpeed(200);
  motor1.run(RELEASE);
  motor2.setSpeed(200);
  motor2.run(RELEASE);
  motor3.setSpeed(200);
  motor3.run(RELEASE);
  motor4.setSpeed(200);
  motor4.run(RELEASE);
  irrecv.enableIRIn();
}

void loop() {
  if (irrecv.decode(&results)){
    switch(results.value) {
      
      case button3:                          //gripper
      motor1.run(FORWARD);
      delay(100);
      break;
      
      case button6:                          //gripper
      motor1.run(BACKWARD);
      delay(100);
      break;
      
      case button1:                         //wrist
      motor2.run(FORWARD);
      delay(100);
      break;
      
      case button2:                        //wrist
      motor2.run(BACKWARD);
      delay(100);
      break;
      
      case button4:                       //elbow
      motor3.run(FORWARD);
      delay(100);
      break;
      
      case button5:                       //elbow
      motor3.run(BACKWARD);
      delay(100);
      break;
      
      case button7:                       //shoulder
      motor4.run(FORWARD);
      delay(100);
      break;
      
      case button8:                      //shoulder
      motor4.run(BACKWARD);
      delay(100);
      break;
      
      default:
      motor1.run(RELEASE);
      motor2.run(RELEASE);
      motor3.run(RELEASE);
      motor4.run(RELEASE);
    }
  }
  irrecv.resume();
}

I would greatly appreciate any help you could offer

First thing to do, just write a program that runs the motors that don't appear to work, I.e makes them go back and forward over and over again

If that works then there is not an electrical fault, and you have bugs in your code.

If it doesn't work, you have an electronics problem

click the MODIFY button in the upper right of the post window.
Highlight all you code.
click the "#" CODE TAGS button on the toolbar above just to the left of the QUOTE button.
click SAVE (at the bottom).
When you post code on the forum, please make a habit of using the code tags "#" button.

How far do you expect the motors to turn in 1/10th of a second?

How far do you expect the motors to turn in 1/10th of a second?

+1

I have checked for electrical faults using the motor test example code and everything is working fine. I don't expect to the motors to turn very far in 1/10th of a second with a single push but it the button is held down they do keep going. I have had motors 3 and 4 working fine so know the concept works just can't work out what the problem with the code is

If swapping the motors around does not change which ones work, then perhaps a review of the AFMotor source code, to see which pins and timers it uses, and a review of the IRremote source code, to see which pins and timers it uses, is in order.

Then, peeking at the ATMEL data sheet, to see which timers control which PWM pins would be the next step.

I had problems with the IR library too, it takes over an arduino Timer, which renders a couple PWM pins useless. I don't remember which. I was trying to build a lamp that could fade a RGB led through different colors and use a IR remote to control it. I ended up not having enough PWM pins because the IR library messes up two of them. For your application you may be able to do what I call "manual PWM" Write the motor HIGH, delay the write motor LOW. Wash rinse repeat. :open_mouth:

initialize(period)
You must call this method first to use any of the other methods. You can optionally specify the timer's period here (in microseconds), by default it is set at 1 second. Note that this breaks analogWrite() for digital pins 9 and 10 on Arduino.

It doesn't look like your using those pins but it does look like you are using pin 1 which is the serial Tx pin. That could be a problem.

AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);