Configuring the Multi-channel Breathing LED (PWM)
This is my first time posting on a forum like this.
I’ll begin by explaining my end goal/result. I plan on making a nightlight for my niece similar to something like the image below (found at: http://i1.wp.com/craphound.com/images/la006-4p0604.jpg?w=970 )
This has been done before and there is actually an instructable covering this. http://www.instructables.com/id/Luminous-Mushroom-Night-Light/
Where this project takes a turn:
I’m wanting to have each LED fade, “breathe”, essentially as if it were alive. It would almost have an effect to something you might find in Avatar. This particular lamp pictured, shows 6 LED’s. I think a lamp with maybe 10-12 LED’s would be much more engaging as well as impressive.
Most Arduino’s have 6 PWM pins, but again, are these individually controlled? I imagine code could be written, but would involve multiple interrupts/delays in order to get all 6 LED’s to be breathing continuously without having to pause while the other 5 LED’s take a “breath”.
I understand the Arduino has four PWM channels and the Arduino Mega has up to 14 PWM pins! This is nice, but the price is not very nice. I’m making this for my niece and was wanting to keep the price of the project relatively cheap. I’m really new to electronics and am not sure about the channels on the Arduino Mega. I don’t know if those 14 pins means that all pins are capable of varying voltage (using PWM) at different frequencies, or if some are paired.
I’m looking to control about 10-12 LED’s individually. Ideally, I’d like to vary the period of each LED’s breathing “sinusoidal” wave so that it doesn’t look autonomous or like a bunch of LED’s fading on and off.
The research I’ve done already:
“If I have 6 PWM pins, I can double my output by charliplexing the LED’s!”
Originally, I thought I could use charlieplexing to get the most of my output pins. Charlieplexing is driving lots of LEDs with only a few pins. It is possible to set your pins to high/low ( 5v / 0v ) in a manner to control N number of pins * ( N-1) = number of LED’s controlled.
Example: 6 pins * (6-1) = 30 LEDs
The theory can be further explained here:
http://www.instructables.com/id/Charlieplexing-LEDs--The-theory/?ALLSTEPS
Using this theory, I had imagined using 2 pins to control 2 LEDs, or possibly more.
This would be very simple to do with a sinusoidal output with 1 LED.
Even using 2 LEDs using Charlieplexing seemingly would be possible
As long as both LEDs were at half brightness, this could work. What would not work however, is if there was a phase shift. I decided to move away from outputting the diagram above because if all LEDs were paired and glowing in this manner, it would look like there were only 2 synchronized sets of lights breathing on and off. This effect would not be very lifelike as well as this sinusoidal output is not very natural. Charlieplexing more than 2 LEDs would be impossible as three LEDs can not all share half brightness
I then found some great code to use in order to achieve the “breathing LED effect” - http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/
Code:
#include <math.h>
void setup()
pinMode(11, OUTPUT);
}
void loop()
{
float val = (exp(sin(millis()/2000.0*PI)) - 0.36787944)*108.0;
analogWrite(11, val);
}
The sinusoidal wave has peaks in it to reflect more naturally inhaling and exhaling. The voltage visual output would look something similar to the image below.
I realized, in theory, multiplexing using only 2 LEDs would only be possible because the peaked voltage, 5v, is sent very briefly. More time is spent in the lower voltages allowing for 2 LEDs to share 2 pins using charlieplexing. Using 3 or more LEDs using this method I can see causing issues. I have failed to mention, using the code previously provided, I am not sure how to program the pins to switch between high and low whilst still peforming this pulse width modulating sinusoidal wave.
Next I had pondered about writing a looping code in an Arduino or similar Atmega chip to write this PWM output to multiple pins, but I believe, the code executes in sequence. If I were to write code to output to multiple pins in a looping sequence, I think the the image below would reflect the end result.
This output would give the LED’s a chasing, twinkling effect. Again, not the desired result.
Ideally (though visually looks chaotic) I would like the output to be similar to below.
While this visual only uses 6 outputs, (red, orange, yellow, green, blue and violet) I would not be uninclined to use the same output for a duplicate LED, meaning: 2x red, 2x orange, 2x yellow, 2x green, 2x blue and 2x violet. It may be recognizable that there are pairs of LED’s, but I believe with varying wave frequencies/periods this would be more easily concealed.
What’s next?
I’m wondering if by using shift registers, the intended effect can still be achieved while keeping costs low.
This is my question to the forum: will using shift registers achieve the desired result or will the LED’s appear to be twinkling and chasing each other?
At this point, I’m not really certain what other options I have besides using multiple controllers/arduinos independently programmed using their 4-6 PWM channels/pins. Ideally, I'd like to stay away from using the arduino and instead using either a single or multiple micro IC's (low cost).
Any assistance or input would be greatly appreciated and please let me know if my description of my project was unclear.
-Scott C.
This is my first time posting on a forum like this.
I’ll begin by explaining my end goal/result. I plan on making a nightlight for my niece similar to something like the image below (found at: http://i1.wp.com/craphound.com/images/la006-4p0604.jpg?w=970 )

This has been done before and there is actually an instructable covering this. http://www.instructables.com/id/Luminous-Mushroom-Night-Light/
Where this project takes a turn:
I’m wanting to have each LED fade, “breathe”, essentially as if it were alive. It would almost have an effect to something you might find in Avatar. This particular lamp pictured, shows 6 LED’s. I think a lamp with maybe 10-12 LED’s would be much more engaging as well as impressive.
Most Arduino’s have 6 PWM pins, but again, are these individually controlled? I imagine code could be written, but would involve multiple interrupts/delays in order to get all 6 LED’s to be breathing continuously without having to pause while the other 5 LED’s take a “breath”.
I understand the Arduino has four PWM channels and the Arduino Mega has up to 14 PWM pins! This is nice, but the price is not very nice. I’m making this for my niece and was wanting to keep the price of the project relatively cheap. I’m really new to electronics and am not sure about the channels on the Arduino Mega. I don’t know if those 14 pins means that all pins are capable of varying voltage (using PWM) at different frequencies, or if some are paired.
I’m looking to control about 10-12 LED’s individually. Ideally, I’d like to vary the period of each LED’s breathing “sinusoidal” wave so that it doesn’t look autonomous or like a bunch of LED’s fading on and off.
The research I’ve done already:
“If I have 6 PWM pins, I can double my output by charliplexing the LED’s!”
Originally, I thought I could use charlieplexing to get the most of my output pins. Charlieplexing is driving lots of LEDs with only a few pins. It is possible to set your pins to high/low ( 5v / 0v ) in a manner to control N number of pins * ( N-1) = number of LED’s controlled.
Example: 6 pins * (6-1) = 30 LEDs
The theory can be further explained here:
http://www.instructables.com/id/Charlieplexing-LEDs--The-theory/?ALLSTEPS
Using this theory, I had imagined using 2 pins to control 2 LEDs, or possibly more.
This would be very simple to do with a sinusoidal output with 1 LED.

Even using 2 LEDs using Charlieplexing seemingly would be possible

As long as both LEDs were at half brightness, this could work. What would not work however, is if there was a phase shift. I decided to move away from outputting the diagram above because if all LEDs were paired and glowing in this manner, it would look like there were only 2 synchronized sets of lights breathing on and off. This effect would not be very lifelike as well as this sinusoidal output is not very natural. Charlieplexing more than 2 LEDs would be impossible as three LEDs can not all share half brightness
I then found some great code to use in order to achieve the “breathing LED effect” - http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/
Code:
#include <math.h>
void setup()
pinMode(11, OUTPUT);
}
void loop()
{
float val = (exp(sin(millis()/2000.0*PI)) - 0.36787944)*108.0;
analogWrite(11, val);
}
The sinusoidal wave has peaks in it to reflect more naturally inhaling and exhaling. The voltage visual output would look something similar to the image below.

I realized, in theory, multiplexing using only 2 LEDs would only be possible because the peaked voltage, 5v, is sent very briefly. More time is spent in the lower voltages allowing for 2 LEDs to share 2 pins using charlieplexing. Using 3 or more LEDs using this method I can see causing issues. I have failed to mention, using the code previously provided, I am not sure how to program the pins to switch between high and low whilst still peforming this pulse width modulating sinusoidal wave.

Next I had pondered about writing a looping code in an Arduino or similar Atmega chip to write this PWM output to multiple pins, but I believe, the code executes in sequence. If I were to write code to output to multiple pins in a looping sequence, I think the the image below would reflect the end result.

This output would give the LED’s a chasing, twinkling effect. Again, not the desired result.
Ideally (though visually looks chaotic) I would like the output to be similar to below.

While this visual only uses 6 outputs, (red, orange, yellow, green, blue and violet) I would not be uninclined to use the same output for a duplicate LED, meaning: 2x red, 2x orange, 2x yellow, 2x green, 2x blue and 2x violet. It may be recognizable that there are pairs of LED’s, but I believe with varying wave frequencies/periods this would be more easily concealed.
What’s next?
I’m wondering if by using shift registers, the intended effect can still be achieved while keeping costs low.
This is my question to the forum: will using shift registers achieve the desired result or will the LED’s appear to be twinkling and chasing each other?
At this point, I’m not really certain what other options I have besides using multiple controllers/arduinos independently programmed using their 4-6 PWM channels/pins. Ideally, I'd like to stay away from using the arduino and instead using either a single or multiple micro IC's (low cost).
Any assistance or input would be greatly appreciated and please let me know if my description of my project was unclear.
-Scott C.