Can't DIM a LED if using -> irrecv.enableIRIn()

I made the PopMech demo robot a few weeks ago and have been upgrading it ever since.

I've added several LEDs to it. Here's my issue:

I have an IR receiver on digital pin 5. I have the LED in question on digital pin 11.

I want to fade/dim the LED on digital pin 11, sort of like a heartbeat. I used seperate sample code from the "Learning" area to test out my setup. It worked fine.

When I integrated that code into my main project code, instead of getting a nice fade/dim, I was getting only a blink.

After commenting out line after line, I found the one line that makes a difference:

irrecv.enableIRIn();

If I comment out this line, my fade/dim works perfectly. Otherwise, it doesn't. Also, it would appear that this line, which again refers to an IR Receiver on pin 5, ends up turning my pin 11 into an all or nothing pin -- that is, I can analogWrite(11, 255) and turn the light on pin 11 ON, but any other value (i.e. 50) and the LED is off. If I comment that irrecv line out, my analogWrite works perfectly for any level.

Is this a limitation of the PWM capabilities of the Arduino? Can I really not use the IR receiver and have a fading/dimming LED? Is it just my PIN choices? Do the analog pins provide another way to achieve my goals?

The ATMega168/328 chips are limited to three timers; Your IR library is apparently using the timer that ordinarily controls the PWM outputs on pin 11.

Try connecting your LED to pin 9 or 10.

I have one servo each already on pins 9 & 10. Don't the servo's need PWM pins?

Here's my pin usage...

Pins 0 & 1 -- not used

On pins 2, 3 & 4, I have interrupt using 'bumpers' (contact switches)

Pins 5, 6, 7 are used by the IR Receiver.

Pin 8 for a reed relay

Pins 9 & 10 for servo motors (left & right)

Pin 11 is the 'heartbeat LED' that I'm trying to make work at the same time as the IR receiver

Pin 12 for a reed relay

Pin 13 for a piezo speaker

Pin A0 for an LED (no dimming/fading needed) Pin A1 for an LED (no dimming/fading needed)

Everything works fine unless I want to be able to analogWrite Pin 11, then I have to choose between doing that and having the IR receiver work. (I can analogWrite (11,255) and leave the light on with no ill effects to the IR receiver, but anything else is effectively an 'off' for that LED).

You can probably simulate PWM by simply turning the LED on in loop() from time to time, and then off again, with different duty cycles. I did an alarm clock where I cycled between 4 digits, simply by turning pins on and off in sequence here:

http://www.gammon.com.au/forum/?id=11165

Assuming you go through "loop" fairly often, all you need to do is have a check (say, using micros() ) and if a certain number have elapsed turn the LED on/off as required.

For giggles, I did try switching to both pins 9 & 10 from 11, shuffling around the servo pins at the same time.

In the case were the LED was on 10, and the servos on 9 & 11 -- the servos still worked fine, but the LED had the same problem.

In the case were the LED was on 9, and the servos on 10 & 11 -- the servos seemed to get jittery -- they still kind of worked, but there was a ton of erratic movement thrown in. The LED still did not work as desired.

Damn... I found the following... http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html

If you search the comments on the page by looking up "Mike Gold" you'll see that he had a similar issue on Pin 11 with an LED. It would appear to be a timer issue. I could try swapping the IR to plug into pins 11, 12, & 13, and shuffle the others to 5, 6, and 7 and see if that works... maybe tomorrow.

As far as using the loop to rapid switch the LED, I have delay()s being used in the code to avoid spurious command inputs and those would throw off any smooth fading/dimming done in a loop.

Shuffling things around so that the IR Recv was on 11, 12, 13 and the LED in question was moved to 5 has worked so far.

The speaker I had moved from 13 to 6, however, picked up an annoying 'tick'. I moved it to A5 with no ill effect.

Hard to believe I'm on a simple project and already having to contemplate the Arduino MEGA just to avoid such limitations ;)

jg0001: I have delay()s being used in the code to avoid spurious command inputs and those would throw off any smooth fading/dimming done in a loop.

Here's a tip ...

Re-code to avoid using delay().

It can be done, and done easily.

Any complex program shouldn't have delay() in it. It's fine for a program that flashes an LED on and off every second. After that, bin it.

Hello, I encore the same issue, and I found a workaround. I use a teensy 2.0

In the IRremoteInt.h library file, I change timer pin to 9

#define IR_USE_TIMER3   // tx = pin 9

instead of pin 14

//#define IR_USE_TIMER1   // tx = pin 14

Here is my pin usage : 2 led in PWM + 1 RGB led that use 3 PWM

#define LED_WHITE          5     // the pin that control white
#define LED_SKY              10    // the pin that control sky
#define LED_R                 14    // the pin that control red
#define LED_G                 15    // the pin that control green
#define LED_B                 12    // the pin that control blue

#define LED_IR                4     // the pin that control IR receiver; use timer 9. Change it in IRremoteInt.h