Dimming 6 LEDs

I'm putting lighting into these cool Christmas Parol Lanterns: inventorArtist » Philippines Christmas Parol Lantern Kits/Templates

I'm pretty happy with the little Six LED system that uses IR remote. I can change the patterns with any TV remote.

I'm able to do dimming of the LEDs using the following code:

analogWrite(led[3], i);

Problem is it was only working with some of the LEDs. I had the LEDs connected to pins 8 through 13 and it was working on 9, 10, 11. I noticed they are marked with PWM.

Pin 3, 5, 6 were also marked as PWM. So I tried wiring to 3,5,6, 9, 10, 11 for my six LEDs. It still doesn't dim for all.

Any ideas?

Here's the page on my lighting project: inventorArtist » Parol Lantern Lighting Experiments

You have this?
led[] = {3,5,6,9,10,11,};

and

for (x=0; x<6; x=x+1){
analogWrite (led[x], dimLevel); // dimLevel = 0 to 255
}

Note, that depending on what other libraries you use, it can disable PWM on certain pins. This is due to the libraries using the hardware timer that the PWM pins use behind the scenes.

On the Uno, I believe pins 3 and 11 cannot do PWM if you use the tone library. I believe the IRRemote library also disables PWM on 3 and 11, which may be your problem. If you use the servo library, it disables PWM on pins 9 and 10. That leaves only pins 5/6 as PWM if you use both Tone/IRRemote and servo.

There are shields and breakout boards that do PWM for multiple pins, and are controlled by I2C or SPI devices. One such is the Adafruit pwm shield: Adafruit 16-Channel 12-bit PWM/Servo Shield - I2C interface : ID 1411 : $17.50 : Adafruit Industries, Unique & fun DIY electronics and kits, or their breakout board: Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface [PCA9685] : ID 815 : $14.95 : Adafruit Industries, Unique & fun DIY electronics and kits

There is also the SoftPWM that claims to do PWM on any available pin (though it may disable PWM on some of the hardware PWM pins): Google Code Archive - Long-term storage for Google Code Project Hosting.

@Crossroads, thanks for the note. I have this at the beginning of my program...

#include <IRremote.h>
int RECV_PIN = 4;
IRrecv irrecv(RECV_PIN);
decode_results results;
//visualization
int led[] = {3,5,6,9,10,11}; //pins 9, 10, 11 can fade
int ledN = 5;

@Michael, thanks, I am using the IR. So if you're right, I then only have 4 of the six PWMs available. I can live with that for now I guess. I will only do dimming on the rest for now.

I noticed when I try and do it on some of the pins everything goes a little haywire. I suppose that's normal...

I'm making another version with an ultrasonic range finder, I suppose I'll loose some PWM pins there as well. I suppose I could try a sensor thats really simple so I can keep all six.

Note, I've bought these but so far they are on my do it someday pile.

There are chips that move the processing of the IR receiver off of the Arduino, so that all you have to do is read a single pin, and you don't have to do the timing in the Arduino via IRremote. Sparkfun sells the sis-2 that allows you to program 2 buttons (I bought this but then got busy doing other things and I haven't used it): Programmable IR Receiver - SIS-2 - SEN-08753 - SparkFun Electronics

You can get the big brother sis-7 that supports 7 different key presses from the manufacturer simerec.com: http://www.simerec.com/SIS-7C.pdf

This is a similar chip to the sis-7, and it includes a remote. I bought this, but like the sis-2 I haven't actually used it at the current time: http://www.ebay.com/itm/Infrared-Remote-Decoder-Modul-Small-7-key-Controller-/251321432000?pt=US_Remote_Controls&hash=item3a83ecb7c0

Can add simple shift register such as Tpic6B595 to sink current thru the LEDs, then use a single PWM on its output enable pin to control dimming.
Put a 0.1uF cap from its Vcc pin to gnd.

http://www.dipmicro.com/store/TPIC6B595N