I've been knocking my head against the wall for a few days trying to get my Arduino Uno to receive IR signals from a 2nd gen Apple remote, and then control a standard Futaba servo with the received codes. It is a BoeBot application, so I am using the Board of Education shield with an IR receiver from Parallax running to pin 4 and the servo to pin 12. The problem I am having is that whenever I load Ken Shirriff's IRremote.h library and the Servo.h library, I encounter a servo twitch.
Here's a simple instance of the code that is giving me the issue:
- Code: Select all | TOGGLE FULL SIZE
int RECV_PIN = 4;
irrecv.enableIRIn(); // Start the receiver
It is powered by a 6V supply (4, 1.5V alkalines), and there is a common ground between the servo and the board.
Here are some things I've tried:
1. Using a different servo
2. Using different pins, for both the servo and IR receiver
3. Change the IRreceive.h library to interrupt with timer0, instead of timer2. (My thinking here is that there may have been a priority of operation, and I wanted to give the servo priority over the IR pin. This didn't change anything though, and I'm pretty sure timer0 has higher priority anyhow..)
4. Wrap the IRremote.h timer ISR in a "detach.servo();" and "attach.servo();" command somehow, but I can't seem to get the coding correct, and I'm not sure if this approach would work.
I should mention that the IR receive demo sketch and a basic servo sweep sketch work just fine when they're independent of one another.
I've seen some postings online where people have gotten the same code to work on the same type of application, so I feel like I'm really missing something big here. I've copied their approach exactly, but am still stuck with a twitchy servo. Any help would be great..I really do appreciate the support.
Ken Shirriff's IRremote library: