2
\$\begingroup\$

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.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ You probably want to do the mixing in software rather than electrically to keep the parts count down and the circuit simple. Also be wary of the possibility of your LED current pulses causing interference in the headphones, either directly or by coupling back into the source device. \$\endgroup\$ Dec 8, 2011 at 20:31
  • \$\begingroup\$ Yes, software mixing is the other option I'm considering. I'll have to make sure the PWM frequency is above the audio range - thanks for the reminder. \$\endgroup\$
    – avramov
    Dec 8, 2011 at 20:43
  • 2
    \$\begingroup\$ What kind of power are you aiming for? Should this overpower the disco ball and strobe light at the club (sorry, dude) and the sun when she goes outside, or should it just gently glow indoors? According to Figure 17-20, I/O Pin Output Voltage vs. Sink Current (VCC = 3V), the ATTiny should be able to sink 5mA without any trouble, which should be plenty to get most 5mm RGB LEDs to glow nicely. \$\endgroup\$ Dec 8, 2011 at 22:44
  • \$\begingroup\$ @KevinVermeer - certainly not overpower disco lights or the sun, but be visible among dim lights. The MCU won't be able to drive four LEDs on its own, though... \$\endgroup\$
    – avramov
    Dec 9, 2011 at 8:12

2 Answers 2

3
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ Great idea! Can you point me to some material on DC/DC converters? Preferably something which I could modify and use right away, as I'm afraid I don't have too much time for research and trial/error... :/ I've been considering powering the circuit from several 2032 cells in series, which are then down-converted to the required voltage, but I have no idea how long these would last or how efficient would it be. Or maybe a single 1.5V AA cell stepped up to 5V? There's a whole lot of possibilities. \$\endgroup\$
    – avramov
    Dec 9, 2011 at 8:25
  • \$\begingroup\$ Although 1.5V would require an external DC converter, since the MCU won't power up at this voltage... \$\endgroup\$
    – avramov
    Dec 9, 2011 at 8:55
  • \$\begingroup\$ You can get high enough voltage by stacking CR2015s - The result fits in a CR2032 battery holder. \$\endgroup\$ Dec 9, 2011 at 10:28
  • \$\begingroup\$ I don't think the CR2032, CR2015 etc will have enough energy desnity to power the project for a long night of clubbing. \$\endgroup\$
    – MattyZ
    Dec 9, 2011 at 23:21
2
\$\begingroup\$

ATTiny25 datasheet here.
6 I/O pins

If driving RGB LEDS you need at least 3 volts and preferably more.

LEDS should be current controlled, not voltage controlled. Trying to control voltages will lead to massive voltage:brightness non linearity.

Trying to make an overall brightness control is doable but given limited pins and more this cries out for a software solution.

As all LEDs are the same colour and brightness at a given time RGB control needs 3 pins.

  • LEDs are fed from a voltage source via a resistor or constant current source such that when on they operate at full desired brightness for that LED. That sets a max current which you then PWM on/off to vary current.

  • PWM LDs on/off so = max brightness or off.

    • Adjust PWM duty cycles wrt to each other to get desired colour.
  • Then multiply each PWM duty cycle by a common brightness scaling factor.

  • eg say you have 8 bit PWM and a colour mix require 8:3:5 brightnesses.
    Max PWM at full brightness is 255 count say. So
    8 channel is set to 255.
    3 channel is set to 3/8 x 255 = 86 counts.
    5 channel = 5/8 x 255 = 159 counts.

The LED is now as bright as can be at that colour.
If 10% relative brightness is wanted then you can scale PWM counts to 26, 9, 16

This means that max brightness available will vary with colour.

  • The following is written at a rush.
    Concept is believed sound but it may be v hard to underatand, Ask if not clear.

If you want constant brightness for all colours then you will need to limit brightness that combinations can achieve to no more than th max achievable by any one colour by itself = 255 counts. As eg red is n=more inefficnt than blue this could mean the max count from red is say 150 counts but max blue = 255

A better method may be to adjust current sources per colour for max brightness in inverse order of efficiency so that when 100% on each colour is on same brightness they all have the same brightness.

eg say the relative brightnesses at the same current for R G B are 10:6:4 (made up) then setting the full brightness currents in the inverse ratio allows you to treat each the same as regards driver per brightess. eg
Red = 6ma,
Green = 10mA,
Blue = 15 mA
or 12,20, 30 mA or whatever.

THEN max brightness per LED with all 3 on should not be more than 85 counts each = 3 x 85 = 255 counts summed - As any one can not be > 255 by itself. So full Red = 255 0 0.

These may be further reduced by PWM ing for brightness control.


If you can get 3 sets of LED drives you and your beloved will not regret it. This allows light chaser action with colours oozing along necklaces etc.

Years ago I did a go to finish project in under one hour that had a PIC drive LEDs in an angel halo with tinsel wrapper and battery back. LEDs all same colour but driven as light chasers. Basic program written in minutes cycled through flash, roll left, roll right etc. Halo worn as pat of costume by my daughter for a party. A bit dim in room light but fantastic effect on dance floor. That plus colour !!!!!!!!

ATTiny's 6 IO allow 3 x 3 mux = 9 = 3 sets or could add one small I/O IC.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.