Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LED Controller - Fade Between Colours

Status
Not open for further replies.
After a lot of looking, I realized its just not going to happen without a uC. What Im looking to do is have a potentiometer, that I can turn from fully CCW to fully CW, and have it fade between red, green, blue, and all the different colours inbetween. Id be using a lot of RGB leds (the kind with four leads), to light up the boarder of a room, or at least part of it (and the knob would change the colour on demand).

Ive got a couple 16F84A's and one 16F873A in my cabinet, so Id like to use these if at all possible. Would anyone be able to point me in the direction of a schematic and code (considering Ive never coded a uC before, or anything for that matter), or even better, be able to at least write the code for me?
 
Sounds like a cool project, maybe a little much for a beginner. The ADC can read the potentometer. Probably want to stick with 8 bit resolution for 256 colors, and the PWM is 8 bits, bytes are 8 bits. It'll greatly simplify the code, and memory might be an issue. The duty cycle determines the brightness of each of the three LED colors. Using a look-up table would take 3*255 is 765 bytes (guessing if you want black, just hit the power switch).

I use AVR, so don't know the details on the PICs you have, but should be good enough. Coding... might get lucky here. Sounds cool and fairly simple.
 
ParkingLotLust said:
Ive got a couple 16F84A's and one 16F873A in my cabinet, so Id like to use these if at all possible.

The PIC16F84 doesn't have the A/D module, so you can't read the potentiometer. If you use a button, you can increment a variable when it's pressed.
 
ParkingLotLust said:
So since I'd need an ADC, Id probably be more apt to use a 16F88 if I wanted to use a pot to control the LEDs, right?

It's simple to do without an A2D (see my tutorials) but the 16F84 shouldn't even be a consideration! - and an A2D does make it slightly simpler.
 
I can share a schematic, just to show there isn't much involved, but I'm afraid I don't have finished code (sorry). The prototype uses a rotary encoder with detents and it has a built in push button switch on the shaft.

Good luck with your project. Mike
 

Attachments

  • RGBX.JPG
    RGBX.JPG
    100.1 KB · Views: 794
2N7000 dead

Mike K8LH,

You are using a 2N7000 as an inverter for RS232 input. I have problems killing the gate input on FETs when connected to another board. You need some kind of protection for the gate of the FET. Try using a digital transistor with two 10k resistors built in. See:
**broken link removed**

To scan the switches A, B and S you will need to put 011, 101, and 110 on Q7,Q6,Q5 so the LED can not be 100% on or 100% off.

ron
 
Hello PLL.
If you aren't dead set on building it yourself, and have $20 to $60, you can buy a PIC on a plugin module loaded with an easy to use BASIC with commands that make things like reading voltages (from pots) and doing PWM easy. These would be the Atom (. They both have a powerful BASIC, which makes programming fairly simple, though not effortless.

The Atom IC by itself can be had for as little as $20, but you have to supply a crystal or resonator, DC power jack, RS-232 IC... a boatload of stuff, then assemble it all together without mishap. I have these, and other variations.

The PICAxe-18 (an 18 pin IC) can be had for as little as $2.50. It has a few channels of analog inputs and several outputs to drive the LEDs. I'm not as familiar with these chips as the Atom, so you'll want to check these carefully for suitability.

Of course shipping and handling will add to the final cost.
Both have enough current out to drive typical LEDs handilly.

Hope that helped.
kenjj
 
Isn't the current limiting resistor needed for the LED? Or it is not needed if the LED is PWM driven?
 
Some people say you must always use current limiting resistors with LEDs, and I'm really not qualified to argue the point. From personal experience... If the LED is to stay on steady, then yes it's a good idea, since there would be not chance to cool down. For things that flash, pulse or fade, I seldom bother. Most of the AVR circuits I've done with LED don't have them, and have been working just fine. The outputs will source 25mA, common LEDs are rated for 20 mA, not really abusing the that much.
 
Same with PIC's, they will output about 25mA per pin, BUT (and presumably the AVR is the same?) it's NOT really a current limited output, just specified that you shouldn't draw more then 25mA from it. So it's certainly good practice to include a limiting resistor, regardless of PWM or not.
 
One can only have PWM or flashing when the controller is running proper code. Can you 100% sure that it will remain that way?

What happens when it hangs upon a power glitch? No more PWM output and your port pin and/or LED will be possibly damaged.

Use a resistor.
 
As with a lot of engineering, it depends.

To a first approximation, an LED looks like a forward biased diode (with a specified Vf) in series with a resistance. The microcontroller looks like a voltage source (Vcc, Vdd) in series with a resistance.

You can estimate each of these resistances by plotting the V/I curve, from the data sheet, or you may have to measure it. In my experience, the typical 20 mA output from a PIC or AVR is around 10 ohms, give or take. I've seen LEDs from 10 ohms to 100 ohms.

Subtracting the Vf of the LED from the Vdd of the micro, you have the voltage that needs to be dropped across the resistance. In the rare case where the sum of the internal resistances is appropriate, you don't need a separate resistor. In the more common case, a series resistor could save your micro, or your LED. Don't forget to look at the peak rated current if you plan to PWM.

For some applications, a designer or hobbyist will say reliability doesn't matter, at least till something fails.
 
These past few post are more wastefull than adding components to a design that do nothing:

You cannot burn out a PIC with an LED load, 1/4 watter or 2 watter makes no difference.
You cannot burn out a PIC given the output is tied directly to Ground.

1/2 of my projects use resistors for LEDs, the other 1/2 of the projects do not and the projects are purely LED based. So why do I not use the resistors? Because there is no question in my mind wheither or not I should use them.

If there is any question as to wheither or not to use a resistor, then use a Resistor and use the correct value and wattage resistor. End of that discussion.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top