Can We Fade LEDS without PWM?

I have a project that needs to be able to fade a few dozen individual LEDS on and off. Ideally, I'd like to do this on a Mega with a sensor shield as I prefer this footprint for the project. Can fading LEDS on and off be done on none PWM pins?
I know I can do this with PCA9685 boards chained together but I really don't like this setup. Does anyone make a PCA board with 64 ports that will fit over a mega like a sensor shield?

Will you be able to use potentiometers to manually adjust LED brightness?

You could use MUX boards but you would still need atleast 1 PWM channel, or potentiometer, plus the required digital pins to change MUX channels

Can you elaborate on why you cannot use PWM, and the goal of your project

If your problem is not enough PWM pins you may try to use "bit angle modulation," check the included app note. With creative use of direct port manipulation and one timer interrupt you should be able to dim a lot of LEDs.
Bit Angle Modulation.pdf (43.4 KB)

get APA102 or Neopixels LEDs and you can select the color and the brightness programmatically without PWM and drive hundreds of them using only 1 or 2 pins.

Neopixels come in a variety of shape and forms, see

You can do it from any pin and you just need 1 pin for all LEDs is they are addressable LEDs

Software PWM

A little bit more detail on the project. I'm making a model railroad that will have lots of signal lights. Each LED needs to be controlled independently and needs to be 0201 or 0402 size LED inside a signal target. The LEDs will be turned on or off individually by input from a program called JMRI and an interface called CMRI not a button or pots.

While the end application does not need fade on or off, I do like the eye candy of having a brief, but noticeable fade when the LEDs are turned on or off. I have done this before using several PCA boards, but I really hate dealing with multiple boards both physically and in the code. There are not enough PWM pins on a Mega to fit my needs of the project. Was just looking for a way to do this by using standard non PWM pins on the mega through a sensor shield.

1 Like

You could experiment with various size capacitors in parallel with the LED.
When I was duplicating the look of the Larson Scanner, that uses incandescent bulbs, with LEDs I was able to get pretty close with some caps. I don't recall the values but you could do a simple RC calculation to get close.

Hi EmilyJane,

That is a really good suggestion :slight_smile:

1 Like

You may want to think about this.
WS2812 Addressable LED
These are the Addressable LEDs (Neopixels) others are talking about, but these are small enough to use in N-scale. An acquaintance of mine is using them in scale signal heads he custom 3D printed. I agree, the 9685 solution gets bulky, but I'd already bought them and committed to rebuilding my HO signal heads with the RR-Cirkits true-to-life tricolour LEDs. IF that doesn't work out, I'll look at the WS2812 solution, because it sure cuts down on the wiring.
C

I found this library as well. Looks like it will do what I need. Anyone here used it?

Increasing arduino PWM pins - theoryCIRCUIT - Do It Yourself Electronics Projects

use can use a timer overflow interrupt. At each interrupt increment a count.
In your code just poll the variable count and set or clear the gpio pin based
on the count.
For example if you want a 25% duty cycle set your gpio pin at count 1 and
reset it at 25 and at count 100 set count to 1.

You can use multiple count count variables like count_pin8, couint_pin7, etc ..in your timer interrupt routine so you can
use multiple gio pins as pwms with different duty cycles and periods.

Yeah, I mentioned it in post #6

I think SW PWM is the way to go. Fading only one or two LEDs at the same moment should be doable without heavy CPU load. After the LED is fully on/off you may disconnect the pin and release the resources used. If the software PWM is implemented in way enabling this.

might offer an option or not.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.