IRremote lib and ARmotor lib interfering with eachother

i am using a l293d motor shield to drive 4 dc motors and 2 servos. And also using an hx1832 IR receiver to receive inputs

the problem is that after introducing the IRremote library into the code some dc motors no longer work

ive tested it out, upon removing the IRremote library all the motors start working again

this is the circut, the motors ive crossed out are the ones that dont work
image

this is the code. (note: right() , left(), and move_stop() are just functions to drive the dc motors, i didnt show them because it would make this code part too long)

#include <Servo.h>
#include <AFMotor.h>
#include <IRremote.hpp>
//#define IR_USE_AVR_TIMER 2

Servo gripper;
//0 is close 80 is open
//is servo 1

Servo arm;
//180 is up and 0 is down
//is servo 2

AF_DCMotor motor_Kanan_Depan(3);
AF_DCMotor motor_Kanan_Belakang(2);
AF_DCMotor motor_Kiri_Depan(1);
AF_DCMotor motor_Kiri_Belakang(4);

void setup() {
  // put your setup code here, to run once:
  gripper.attach(10);
  arm.attach(9);
   Serial.begin(9600);
   Serial.println("start");

   motor_Kanan_Depan.setSpeed(100);
   motor_Kanan_Belakang.setSpeed(100);
   motor_Kiri_Depan.setSpeed(100);
   motor_Kiri_Belakang.setSpeed(150);

//   IrReceiver.begin(2);
}

void loop() {

//  if(IrReceiver.decode()){ 
//    Serial.println(IrReceiver.decodedIRData.decodedRawData , HEX);
//    IrReceiver.resume();
//  }

  gripper.write(0);

  right();
  delay(2000);
  move_stop();
  delay(1000);
  left();
  delay(2000);
  move_stop();
  delay(1000);

}

Are you using an Uno?

On the Uno, the IRremote library uses Timer 2 for its own purposes.

The AFMotor library also uses Timer 2 for its own purposes.

You make setSpeed() calls, some of which end up reprogramming Timer 2 according to their needs.

You then initialize the IR receiver, and it sets up Timer 2 according to its needs.

And the motor channels that were using Timer 2 are left out in the cold.

yes, i am using an uno, i forgot to mention

how many timers does the uno have? and do any of them make use of pins 1, 0, 2, 13, or analog pins?

because those are the pins that are still available to me in this project

I don't have that information committed to memory, but a simple google search turned up:

so i have this idea, please tell me whether you think it'll work or not

first, ill move the two servos from pin 9 and 10 to analog pins, that should free up timer 1 since that uses 9 and 10

next ill move either the IRreceiver lib or AFmotor lib to use timer 1 instead of 2

Wouldn't it be less effort to retire the v1 motor board that's been discontinued for more than a decade and use a v2 board that only uses the I2C pins and no timers at all?

look, ive already bought this one, and the project is due in 2 days, just tell me if you see any problems with my solutions at all

I think what you propose is a fair amount of work with no guarantee of success by your deadline. But good luck.

if what you're worrying about is the deadline then worry not, for i shall not sleep until this project is finished

can you move the timer at servo? i remember being able to do that for IRreceiver

correct me if im wrong, but for this project i would need 3 timers

1 for servo
1 for IrReceiver
1 for AFMotor

and the arduino also has 3 timers

timer 0, 1, and 2

so, there really is no way around it then huh

you know what, new idea

so the IRreceiver is only interfering with motor 1 and 2

ill add another motor driver, this one is to drive motor 1 and 2

do you see any problems with that?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.