IR/Motor program question

Hey guys,
I am trying to get motor controlled using IR receiver. The problem I have right now is that the motor does not run in the current program but works fine when I am not using the IR receiver. I am guessing its some programming issue rather than the hardware.

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

AF_DCMotor motor(2, MOTOR12_2KHZ); 
int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  Serial.begin(9600);           
  motor.setSpeed(250);     
  irrecv.enableIRIn();
}

void loop() {
  if (irrecv.decode(&results))
  {
    Serial.print(results.value, DEC);
    if(results.value == 1637892797)
    {
      Serial.print("tock");
      motor.run(FORWARD);      
      delay(1000);
    }
    else if(results.value == 1637925437)
    {
      motor.run(RELEASE);
      delay(5000);
    }
    irrecv.resume();
  }  
}

Thanks a lot,
DJ

Do you get the expected serial output when you press the remote buttons?

Sorry for the late reply but yes, serial output does come. I have found out that the Motor's do not work on port 1 and 2 of the motor shield but 3 and 4 work fine. But can't really use both 3 and 4 since I have two motors and both at 1A (already burned one of the H bridges).

Upon further investigation, I have noticed that the motor does move (like for nano second) but doesn't act the way its supposed to (only on ouputs 1 and 2). I think its some sort of timer issues.

Upon further investigation, I have noticed that the motor does move (like for nano second) but doesn't act the way its supposed to (only on ouputs 1 and 2). I think its some sort of timer issues.

Does the motor move like it is supposed to if you don't use the IR remote?

I was told that the IRemote library uses Timer 2 and the motors 1/2 output also use timer 2 so there is a conflict and can't be resolved :confused: I am just going to piggyback two SN754410NE now with heatsink to run the two DC motors off outputs 3/4.

I run into the exact problem, but I need to use 3 DC motors. So is there absolutely no way to avoid this conflict? Can we hack the IR library so it use some other timer? I think most people's first project will be a IR remote control to drive a motor, so it's very disappointing to get everything working quickly only to find out you are hitting a wall. Hopefully the IR and the Motor shield guys can come together and resolve this conflict?

Uni

mcjohn113:
Hey guys,
I am trying to get motor controlled using IR receiver. The problem I have right now is that the motor does not run in the current program but works fine when I am not using the IR receiver. I am guessing its some programming issue rather than the hardware.

#include <AFMotor.h>

#include <IRremote.h>

AF_DCMotor motor(2, MOTOR12_2KHZ);
int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  Serial.begin(9600);           
  motor.setSpeed(250);     
  irrecv.enableIRIn();
}

void loop() {
  if (irrecv.decode(&results))
  {
    Serial.print(results.value, DEC);
    if(results.value == 1637892797)
    {
      Serial.print("tock");
      motor.run(FORWARD);     
      delay(1000);
    }
    else if(results.value == 1637925437)
    {
      motor.run(RELEASE);
      delay(5000);
    }
    irrecv.resume();
  } 
}




Thanks a lot,
DJ

I have the same problem, and I was able to solve it by just editing the header file IRremoteInt.h by uncommenting the timer I wanted to use and commented the default timer.

Jaggedhead solution works Ok in Uno, using Timer 1 there will be no conflict with the motor shield.

I've attached an screenshot...

I confirm, this is very unfortunate and would be, I suppose, quite difficult for beginner programmers, even with your explanations.

Note that the #define is now in the boarddefs.h file.

Thanks for this solution.