1
#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.

13
  • Is the motor using pin 1?
    – Delta_G
    Jul 21, 2020 at 20:01
  • Yes I've connected the motor to pin1 also. I tried running the motor using a separate code and its working fine. @Delta_G Jul 21, 2020 at 20:05
  • 1
    That seems unlikely but if true explains your problem. If it is using pin 0 or 1 then you can’t use Serial. What motor shield do you have exactly? Do you have a link?
    – Delta_G
    Jul 21, 2020 at 23:13
  • 1
    It's a normal adafruit motor shield learn.adafruit.com/adafruit-motor-shield Jul 22, 2020 at 13:54
  • 1
    Are you sure it's the V1 and not the V2?
    – Delta_G
    Jul 22, 2020 at 14:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.