Looking for compatible libraries to control Servo motors with the AFMotor library via IR remote input

Hello,
So recently I’ve opened a thread concerning output issues with my IR Remote. This was the code in question:

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

AF_DCMotor motor(1); // DC motor on M1
AF_DCMotor pump(3); // Pump at M3
Servo pitch;  // Pitch of Nozzle at Pin 9
Servo rotate; // Rotating plate for nozzle at Pin 10

const int RECV_PIN = A5;
IRrecv irrecv(RECV_PIN);
decode_results results;

bool Press = false;
int p_pos = 0;    // variable to store the pitch position
int r_pos = 0;    // variable to store the rotation position

void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn();
  irrecv.blink13(true);

  pitch.attach(10);    // attaches the servo on pin 9 to the servo object
  rotate.attach(9);  // attaches the servo on pin 10 to the servo object
  pitch.write(p_pos);
  rotate.write(r_pos);


}

void loop() 
{
  if (irrecv.decode(&results))
  {
    Serial.println(results.value, HEX);
    irrecv.resume();



    if (results.value == 0xFFA25D)
    {
      motor.run(FORWARD);
      motor.setSpeed(255);
      delay(1000);
      motor.run(RELEASE);
      delay(1000);
    }

    if (results.value == 0xFFE21D)
    { 
      for (p_pos = 0; p_pos <= 45;) 
      {
        p_pos += 5;
        pitch.write(p_pos);
       delay(500);
      }
      for (p_pos = 45; p_pos >= 0;)
      {
        p_pos -= 5;
        pitch.write(p_pos);
        delay(500);
      }
  
    }

    if (Press == true)
    {
      for (r_pos = 0; r_pos <= 180;) 
      {
        r_pos += 5;
        rotate.write(r_pos);
        delay(500);
      }
      for (r_pos = 180; r_pos >= 0;)
      {
        r_pos -= 5;
        rotate.write(r_pos);
        delay(500);
      }

    }
  }

}

I did have a separate code with only the IR remote code to detect and decode the outputs from the IR remote which worked as expected.

The issue that was found on the other thread was that the IRremote library and the Servo library were incompatible.

Does anyone know any other libraries which can be used to take input from an IR remote to control both DC motors and Servo motors, and are compatible with each other?

Thanks!

Maybe investigate the ServoTimer2 library which, as its name suggests, uses timer2 which may prevent a conflict with the other libraries

Never heard of the library but this sounds just like the solution to my life problems.
We did find the issue to be with timers.

You’ll need a few code changes because ServoTimer2 write() acts like Servo.writeMicroseconds i.e. it takes microseconds not angles like Servo.write() does.

So write(90) becomes write(1500), write(0) > write(544) and write(180) > write(2400).

Steve

It appears the library is still incompatible with the IR Remote library or there is some other issue.
I tested the inputs with the ServoTimer2 integrated but I didn’t get any inputs. However, when I commented out all the commands from the library I got all the inputs.

Okay so I just realised the issue is with the AFMotor library and the Servo Library.

Does anyone know any alternative DC Motor control library which is compatible with the Servo Library?

Note: I’m using an Arduino Uno L293D Motor Shield

Do you actually need a library to control the DC motor ?

I don’t but I haven’t been able to find the schematics for the shield I’m using which specifies which pins are used for each port.

I’m also new to Arduino so I’m not sure how the coding would look to control a DC motor without the library.

Take a look at the library code you’re using. That should tell you what the shield’s pins are.

Where can I expect to find it on the page?

I think I found which pins they are. I’m just unsure how I would go about controlling the DC motor without the library.

Just an update with my progress, I found that AFMotor library with the Servo library affected the IRremote library. When I had all libraries together, I would get random outputs from my IR remote. However, if I remove one of the motor libraries, it would work fine. I am using the updated libraries for AFMotor V1 and Servo, but am using the 2.8.0 version of IR Remote.

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