IR not working after using servo

I'm using DeMos D1 R1.
the code is working great without a servo.attach(pinNumber), but with the ir is not printing.
this is the working code:

#include <Servo.h>
#include <IRremote.h>
Servo myCRServo;
const int PIN_RECV = 16;
void setup() {
  Serial.begin(9600);
  IrReceiver.begin(PIN_RECV);
  //myCRServo.attach(5);
}
void loop() {
  if (IrReceiver.decode()) {
    IrReceiver.printIRResultShort(&Serial);
    IrReceiver.resume();
  }
}

and this is the code that not working:

#include <Servo.h>
#include <IRremote.h>
Servo myCRServo;
const int PIN_RECV = 16;
void setup() {
  Serial.begin(9600);
  IrReceiver.begin(PIN_RECV);
  myCRServo.attach(5);
}
void loop() {
  if (IrReceiver.decode()) {
    IrReceiver.printIRResultShort(&Serial);
    IrReceiver.resume();
  }
}

note that the only thing I changed was the "myCRServo.attach(5);" line.
the problem is only accrued after the servo.attch() is called.
when i delay (with millis) the "servo.attach()" the Serial is printing the ir info until the servo.attach is called.
servo.detach is not help neither.
I can confirm that the ir is reciving data beacuse the led on the IRreceiver is lighting when i click on the remote.
Also, I haven't connected the servo to the 5 pin yet, does it relevant?
Thanks for the help!

Post an annotated schematic showing exactly how you wired it. Be sure to include all power sources and note any lead over 10"/25cm.


Thanks for replying.
I only connected the irReceiver.
i removed all unnecessary cabels and code in order to keep the problem simple.
no cable is more than 25cm.

There may be a conflict in the Servo and IR libraries over timer usage, so try the ServoTimer2 library instead.

Edit: may not work with ESP8266

thank you, this is indeed not working with esp8266.
as you can see here
what can i do?
is there IRremoteTimer2?

I don't use the esp8266, but the library conflict certainly exists for AVR-based Arduinos, and one solution is ServoTimer2.

Check the web for information about possible library conflicts with esp8266 libraries, and how to resolve them.

There is a library in the library manager called IRremoteESP8266 by David Conran, Sebastien Warin, Mark Szabo, Ken Shirriff.

Not sure if it'll help but presumably there was a reason they wrote it. I have no experience with it though.

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