Adafruit MotorShield IR Remote Controlled Car

So I decided to resurrect a project I was working on as a kid. Its a 4 motor remote controlled car, controlled by the Adafruit MotorShield V2, and an Infra-red receiver with the numbers and letters, VS, 1838B.

Now I'm nearly finished with the project, the motors can run perfectly, I've recorded the codes that the remote sends, and the receiver receives the code and acts. There is one problem though, that I encountered last time. With my code the receiver accepts the code for instance "0xFF629D," which tells the motors to run forward, but it is unable to accept the next code as the arduino is focused on running the motors, and not accepting the next code from the remote.

I'm quite sure the solution is very simple, but I'm only 15, and up and coming engineer.

Of course here's my code:

#include "IRLibAll.h"
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield();

Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
Adafruit_DCMotor *myMotor2 = AFMS.getMotor(2);
Adafruit_DCMotor *myMotor3 = AFMS.getMotor(3);
Adafruit_DCMotor *myMotor4 = AFMS.getMotor(4);



int ledPin = 10;


IRrecvPCI myReceiver(2);


IRdecode myDecoder;

void setup() {
  pinMode(ledPin, OUTPUT);

  AFMS.begin();
  Serial.begin(9600);
  delay(2000); while (!Serial);
  myReceiver.enableIRIn();
  Serial.println(F("Ready to receive IR signals"));

  myMotor->setSpeed(150);
  myMotor2->setSpeed(150);
  myMotor3->setSpeed(150);
  myMotor4->setSpeed(150);
}

void loop() {

  if (myReceiver.getResults()) {
    myDecoder.decode();
    if (myDecoder.protocolNum == NEC) {
      switch (myDecoder.value) {
        case 0xFFA857: //DOWN BUTTON
          myMotor->run(BACKWARD);
          myMotor2->run(BACKWARD);
          myMotor3->run(BACKWARD);
          myMotor4->run(BACKWARD);
          
          myReceiver.enableIRIn();
          break;
        case 0xFF629D: //UP BUTTON
          myMotor->run(FORWARD);
          myMotor2->run(FORWARD);
          myMotor3->run(FORWARD);
          myMotor4->run(FORWARD);
          
          myReceiver.enableIRIn();
          break;
        case 0xFF02FD: //OK BUTTON
          myMotor->run(RELEASE);
          myMotor2->run(RELEASE);
          myMotor3->run(RELEASE);
          myMotor4->run(RELEASE);
          myReceiver.enableIRIn();
          break;
        case 0xFF220D: //LEFT BUTTON
          myReceiver.enableIRIn();
          break;
        case 0xFFC23D: //RIGHT BUTTON
          myReceiver.enableIRIn();
          break;




      }
      myReceiver.enableIRIn();
    }


  }
}

Sorry for all the words, but thanks in advance.

sketch_aug25a.ino (1.77 KB)

I don't use the Adafruit motor driver or library, but glancing through the frustratingly incomplete documentation suggests that the run() command is not blocking. That is, it tells the driver to run the motor at the desired speed, in the desired direction and exits.

So, what is your evidence for this conclusion?

it is unable to accept the next code as the arduino is focused on running the motors,

I suspect a power supply problem, for example starting up all the motors crashes the Arduino, but you forgot to post a hand drawn (not Fritzing) wiring diagram. Also post links to the data sheets or product page for the motors, so we can see the voltage and current requirements (especially, the motor stall current).

See the "How to use this forum" posts on how to do that.

First post and you used code tags. Well done! Karma++

Thanks for all the help guys, it's been two years, and I solved the problem a while back, can't exactly remember what I did, but thanks

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