Electronic – ATtiny25 PWM LED driver with brightness control

attinyledmosfetpwmrgb

I'll be building a piece of RGB LED jewelry for a gift. It's basically a pair of earphones with one or two RGB LEDs on each, with a small ATtiny25-based PWM driver in a small enclosure.

I'll probably be able to devise the firmware myself; however, since I'm going to have a good few inches of wire going to each phone, I need some sort of LED drivers, and that's where I'm not sure how to proceed.

The basic idea is for all the LEDs to be displaying the same color at a given point. The MCU will fade through all colors in sequence using software PWM. However, I would also like to implement a control for the overall brightness of the LEDs (once ambient noise goes above a certain level, it starts pulsating along with it, kinda like a VU meter). I'm thinking about one PWM-driven 'brightness' MOSFET to control the, um, source voltage (?) to the other three 'color' MOSFETs. Is this the way to go?

I have a lot of BS170s and not much else in the way of FETs (BF245, 2N5457 JFETs), so that's probably what I'm gonna be using. I'm thinking of going all-out SMD on this… I only have the tiny25 in SOIC, anyway.

Best Answer

Here's another idea to add to the good suggestions proposed by others. If you're going to be using RGB LEDs, you should consider the power supply requirements of the device. The blue LEDs in the RGB LED package have a high forward voltage requirement, so you will pretty much need either a 3.6 volt lithium battery, or a 9 volt battery. The 3.6 volt battery is barely adequate for a blue LED - say you select your current limiting resistor based on this nominal voltage and the voltage decreases a few tenths of a volt as the battery discharges - the blue LEDs will rapidly lose brightness. You end up condemning your SO to carry around a 9 volt battery all night, or several 3.6 volt batteries in series, which is bulky.

The standard ATTiny is good to 10 mHz at down to 2.7 volts, and has two PWM channels and four AD converters. It will be slumming it just controlling a couple LEDs; there should be plenty of code space available to use the second PWM channel to implement a simple boost converter. The converter can take a barely adequate battery voltage and boost/regulate it to keep a blue LED's light output stable as the battery discharges. This opens up all sorts of possibilities for lightweight batteries; you could use 2 alkaline triple A's, for example, for really long life. There is another advantage to this scheme - you can dynamically modulate the LED power supply voltage depending upon which LEDs are being used. When the blue LEDs are on, pump the voltage up to what's needed to give them the required brightness. When they're off, drop the supply back to just above the battery output voltage for the red and green LEDS. This should give you significant power savings.

If you find that when using a 3 volt supply that the standard ATTiny browns out under some conditions when fed directly from the battery/batteries, you could try using the low voltage part, or you could actually set it up so that the direct battery voltage just gets it started, and then run the chip from the boosted supply.