How to fade 6 LEDs and have audio file played (not enough PWM?)

Hi Guys,

I am making a prototype of a meditation alarm clock.

I am using an arduino nano.

With a rotary knob (potentiometer) I will choose how many minutes I want to meditate. 10, 20, 30, 40, 50 or 60.

For each choice there will be a LED turning on. So in total 6 LEDs. These LEDs need to be able to blink/pulsate (fade in and out) to show how many time there is still to go. For instance if I still have 25 minutes to go, the '30 minute' LED will blink. If I have 1 to 10 minutes to go the '10 minute' LED will blink.

So this I can do with the 6 PWM pins ~3, ~5, ~6, ~9, ~10 and ~11

But now I also want to play the sound of a gong at the end of the meditation. So I looked up and see that I can use an SD card and amplifier to do this: Simple Arduino Audio/Music Player with SD Card

Only problem now is that this solution also needs PWM ports, namely 3, 9 and 11.

So now I don't have enough PWM ports.

Does any of you see how I can make this prototype using 1 arduino nano?

Many thanks!

You can simply code up a fading LED on a non PWM pin using digitalWrite. The arduino is fast enough that you can fool the eye into seeing the fading effect.

There are soft-PWM libraries out there. Quite easy to get 8 PWM outputs. A bit lower frequency and you can probably get a lot better even.

Or for your gong sound use a DF Player.

An alternative would be to use adressable LEDs, such as the WS2812; they even come in LED strips; you then connect the strip with 3 wires (Vcc, GND, data) and you're good to go; the downside is that the stripe actually uses a non-negligible current when off, so you ideally want a mosfet disconnecting the strip from the power for battery-powered applications; when doing that, you want to first set the data pin to input, then disconnect the power; similarly, when powering them, first apply power and then set the data pin to output;

That way you can use just 1 or 2 pins to control literally hundreds of LEDs.

Thanks a lot! I will try to dim the LEDs with a non PWM pin and will order the DF player as it looks way simpler to get it working than the SD card reader + amplifier.

I already bought specific LEDs so the suggestion of thegoodhen can't be applied but thanks anyway!

he DF player as it looks way simpler to get it working than the SD card reader + amplifier

It is very simple to get that one to work - it comes with a 3W mono speaker output, but you can also connect it to an amplifier if you want, it also has stereo line level outputs.