Unable to use ir receiver and motor shield together

#include <IRremote.h>
#include <AFMotor.h>
AF_DCMotor motor(1);


int RECV_PIN = 14;//The definition of the infrared receiver pin 11
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600); //Open serial 
  irrecv.enableIRIn(); // Initialization infrared receiver
  motor.setSpeed(255);
  motor.run(RELEASE);
  Serial.println("start");
  motor.run(FORWARD);
  delay(1000);
} 

void loop() 
{
  if (irrecv.decode(&results)) {
    if(results.value==0x3D9AE3F7)
    {

      motor.run(FORWARD);
      delay(2000);    
    }
    else if(results.value==0x1BC0157B)
    {
      motor.run(RELEASE);
      motor.run(BACKWARD);    
    }
    Serial.println(results.value, HEX);//Wrap output in hex receive code
    Serial.println();//For ease of viewing the output to add a blank line
    irrecv.resume(); //Receiving the next value
  }
}

Motor shield is not working when I use an IR receiver. I tried connecting the ir receiver in different analog pins but it didn't work. I guess it's due to some error in my code but unable to figure out.
I'm using an arduino uno
The motor shield is a normal adafruit motor sheild.
The motor shield takes up all the almost all the io pins of the arduino but I read on online that it does not use analog ports so I've connected IR sensor to analog 0(I tried with other analog ports too).
I've IR part works fine I tested it via serial monitor.
I have tested the motor driver separately(without ir) and it worked fine.

1 Like

Inconsistent: int RECV_PIN = 14;//The definition of the infrared receiver pin 11

What pins does the motor shield use?

The motor shield sits on top of the arduino so it takes up all the pins as it sits on top of the arduino.

Why the difference between code and comment?
Please read and respond to the replies.

Okey. How do You expect me to know what pins are actually used?
Get started and supply information, links etc. about Your stuff.

I'm reallly sorry sir, I new to this. There's inconsitency because I took the code from the internet I changed the value in the code but forot to remove the comment.
I'm using an arduino uno
The motor shield is a normal adafruit motor sheild.
The motor shield takes up all the almost all the io pins of the arduino but I read on online that it does not use analog ports so I've connected IR sensor to analog 0(I tried with other analog ports too).
I've IR part works fine I tested it via serial monitor.
I have tested the motor driver separately(without ir) and it worked fine.

Okey. The motor shield and the IR works, one at the time. Thats good.
ormal adafruit motor sheild. That doesn't tell me anything. Adafruit likely sell a number of different motor shields.
No motor shield is using all the pins. Find out what pins it is using. Specifying which motor shield You've got would help.

It looks like some kinf of software collision, both using the same controller resource.


I've attached a picture of my motor driver.
It's given in their documentation that all the analog pins and digital 2,13 are not used. Everything else is used by the shield. I also plugging my ir recever in all the analog pins and digital pin2. Always thes same result, the ir works fine but the motor shield doesn't work

That is an I/O hungry shield, but okey.
Did You test the IR using the same analog pins when IR worked?
Passed midnight here....
Maybe some more helper will step in. Maybe it is some library collision.

Even when both the shield and ir are connected, the ir sensor works perfectly fine I checked it via serial monitor.

Does your motor library use timer1? If so, it is probably conflicting with the IR library which already uses it.

Another problem, I don't see any place in this thread where you tell us specifically what is wrong, what the program actually does/doesn't do, that it should/shouldn't. You only said, "but it didn't work". We need more information than that.

I'm very new to arduino so I don't know much about the technical stuff.
I'll look into what timer my motor library uses.
By not working I mean the motor is not spining. The motor is supposed to spin as soon as the program gets executed. When I remove the IR part of the code the motor spins.

1 Like