myservo.attach stops IR receiver from working

Weird problem. I am trying to simply getmy servo to stop and start with an ir remote. IR receiver and servo work fine separately. Had trouble getting them to work together. So I started adding in code line by line to see where the issue is. And it's very simply just the myservo.attach line. Everything else is commented out in the servo code- leaving the lines for the IR code. When I comment out the myservo.attach line, the IR receiver works (the light blinks when i press the remote and i get the code on the serial monitor screen). The moment I uncomment the myservo.attach line, the IR will not respond anymore.

Code below. I've also tried changing pins but that didn't help. If anyone has experience with this, please let me know what I can try. Both irremote and servo libraries are included.

int RECV_PIN = 10;
Servo myservo;
IRrecv irrecv(RECV_PIN);
int pos = 0;

decode_results results;

void setup()
irrecv.enableIRIn(); // Start the receiver


void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, DEC);
irrecv.resume(); // Receive the next value

the servo library uses Timer2 (which disables PWM on pin 9 and 10 by the way - just in case)

The IRremote library requires a timer for both transmitting and receiving and by default it's timer2 as well --> you can edit boarddefs.h to make IRremote use a different timer.

the servo library uses Timer2 (which disables PWM on pin 9 and 10 by the way - just in case)

That should be Timer1 (the rest is correct).

The OP may be able to use the ServoTimer2 library if he wants to free up pins 9 and 10


Good catch Robin

I will try that. Thanks all.