Pages: [1] 2 3 ... 5   Go Down
Author Topic: Help with LED Lamp concept.  (Read 6668 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 1
Posts: 209
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Hi all looking for a little (lot) of help with an Idea I have for an LED lamp. It consist of 6 RGB LED’s mounted in a circle in acrylic running on a atTiny85.

The LED’s will cycle though  all the colors.  I have made a proof of concept and it works fine on the Arduino.  I know it is not wired right and that is what I need help with.  Right now on the Arduino I have all the Red’s going to pin 3, all the Green’s going to pin 5 and all the Blues going to pin 6.  At this time I am not using resistors.

The Forward current on all three colors is 20mA. The Forward voltage on the Red is 2.0 and on both the Green and Blue are 3.0.

I am not sure how much power I will need to drive all 6 RGB’s and the atTiny85.

I know this is asking a lot, but as I am still learning and I learn best by seeing/doing I was hoping maybe one of you pros would like to take me under your wing so to say and walk me though how to wire this.  I know how to figure out what size resistors to use, that is once I know what my supply voltage is going to be. But I am thinking I am going to need transistors and maybe a Voltage Regulator. That is where I get lost.


Attached is the code I am using. I got the code off the Net.

Thank you all in advanced for any help.

-Keith

Code:
/*
 RGB LED - Automatic Smooth Color Cycling

 Marco Colli
 April 2012
 
 Uses the properties of the RGB Colour Cube
 The RGB colour space can be viewed as a cube of colour. If we assume a cube of dimension 1, then the
 coordinates of the vertices for the cubve will range from (0,0,0) to (1,1,1) (all black to all white).
 The transitions between each vertex will be a smooth colour flow and we can exploit this by using the
 path coordinates as the LED transition effect.
*/
// Output pins for PWM
#define  R_PIN  3  // Red LED
#define  G_PIN  5  // Green LED
#define  B_PIN  6  // Blue LED

// Constants for readability are better than magic numbers
// Used to adjust the limits for the LED, especially if it has a lower ON threshold
#define  MIN_RGB_VALUE  10   // no smaller than 0.
#define  MAX_RGB_VALUE  255  // no bigger than 255.

// Slowing things down we need ...
#define  TRANSITION_DELAY  70   // in milliseconds, between individual light changes
#define  WAIT_DELAY        500 // in milliseconds, at the end of each traverse
//
// Total traversal time is ((MAX_RGB_VALUE - MIN_RGB_VALUE) * TRANSITION_DELAY) + WAIT_DELAY
// eg, ((255-0)*70)+500 = 18350ms = 18.35s

// Structure to contain a 3D coordinate
typedef struct
{
  byte  x, y, z;
} coord;

static coord  v; // the current rgb coordinates (colour) being displayed

/*
 Vertices of a cube
     
    C+----------+G
    /|        / |
  B+---------+F |
   | |       |  |    y   
   |D+-------|--+H   ^  7 z
   |/        | /     | /
  A+---------+E      +--->x

*/
const coord vertex[] =
{
 //x  y  z      name
  {0, 0, 0}, // A or 0
  {0, 1, 0}, // B or 1
  {0, 1, 1}, // C or 2
  {0, 0, 1}, // D or 3
  {1, 0, 0}, // E or 4
  {1, 1, 0}, // F or 5
  {1, 1, 1}, // G or 6
  {1, 0, 1}  // H or 7
};

/*
 A list of vertex numbers encoded 2 per byte.
 Hex digits are used as vertices 0-7 fit nicely (3 bits 000-111) and have the same visual
 representation as decimal, so bytes 0x12, 0x34 ... should be interpreted as vertex 1 to
 v2 to v3 to v4 (ie, one continuous path B to C to D to E).
*/
const byte path[] =
{
  0x01, 0x23, 0x76, 0x54, 0x03, 0x21, 0x56, 0x74,  // trace the edges
  0x13, 0x64, 0x16, 0x02, 0x75, 0x24, 0x35, 0x17, 0x25, 0x70,  // do the diagonals
};

#define  MAX_PATH_SIZE  (sizeof(path)/sizeof(path[0]))  // size of the array

void setup()
{
  pinMode(R_PIN, OUTPUT);   // sets the pins as output
  pinMode(G_PIN, OUTPUT); 
  pinMode(B_PIN, OUTPUT);
}

void traverse(int dx, int dy, int dz)
// Move along the colour line from where we are to the next vertex of the cube.
// The transition is achieved by applying the 'delta' value to the coordinate.
// By definition all the coordinates will complete the transition at the same
// time as we only have one loop index.
{
  if ((dx == 0) && (dy == 0) && (dz == 0))   // no point looping if we are staying in the same spot!
    return;
   
  for (int i = 0; i < MAX_RGB_VALUE-MIN_RGB_VALUE; i++, v.x += dx, v.y += dy, v.z += dz)
  {
    // set the colour in the LED
    analogWrite(R_PIN, v.x);
    analogWrite(G_PIN, v.y);
    analogWrite(B_PIN, v.z);
   
    delay(TRANSITION_DELAY);  // wait fot the transition delay
  }

  delay(WAIT_DELAY);          // give it an extra rest at the end of the traverse
}

void loop()
{
  int    v1, v2=0;    // the new vertex and the previous one

  // initialise the place we start from as the first vertex in the array
  v.x = (vertex[v2].x ? MAX_RGB_VALUE : MIN_RGB_VALUE);
  v.y = (vertex[v2].y ? MAX_RGB_VALUE : MIN_RGB_VALUE);
  v.z = (vertex[v2].z ? MAX_RGB_VALUE : MIN_RGB_VALUE);

  // Now just loop through the path, traversing from one point to the next
  for (int i = 0; i < 2*MAX_PATH_SIZE; i++)
  {
    // !! loop index is double what the path index is as it is a nybble index !!
    v1 = v2;
    if (i&1)  // odd number is the second element and ...
      v2 = path[i>>1] & 0xf;  // ... the bottom nybble (index /2) or ...
    else      // ... even number is the first element and ...
      v2 = path[i>>1] >> 4;  // ... the top nybble
     
    traverse(vertex[v2].x-vertex[v1].x,
             vertex[v2].y-vertex[v1].y,
             vertex[v2].z-vertex[v1].z);
  }
}
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 150
Posts: 5666
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

At this time I am not using resistors.

Don't do it. Not even for testing. Put something in there, anything.

Is the effort of adding a resistor to a circuit worth more than your Arduino?

The Forward current on all three colors is 20mA. The Forward voltage on the Red is 2.0 and on both the Green and Blue are 3.0.

I am not sure how much power I will need to drive all 6 RGB’s and the atTiny85.

The LEDs need 6 x 3 x 20mA = 360mA

A TIny85 needs about 15mA max, less in reality.

Call it 400mA total - perfect for a USB phone charger (or whatever).

But I am thinking I am going to need transistors and maybe a Voltage Regulator

Transistors? Yes.

Voltage regulator? Probably not. 5V supplies are common household items in 2013.
Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Full Member
***
Karma: 1
Posts: 209
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Don't do it. Not even for testing. Put something in there, anything.
Noted... Nood Mistake  smiley-confuse




Voltage regulator? Probably not. 5V supplies are common household items in 2013.


That one I am lost on a little. One of the Tutorials I was reading said. If you are using 3, 3.0 Volt LEDs that you would need a 9 volt supply. and if you wanted to use 4 leds you would need a 12 volt supply.  What did I not get out of that tutorial.

Also Thansk for the help..
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 150
Posts: 5666
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That one I am lost on a little. One of the Tutorials I was reading said. If you are using 3, 3.0 Volt LEDs that you would need a 9 volt supply. and if you wanted to use 4 leds you would need a 12 volt supply.

That's if you put them in series.

If you put them in parallel you only need enough volts for one LED.
Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Full Member
***
Karma: 1
Posts: 209
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


That's if you put them in series.

If you put them in parallel you only need enough volts for one LED.


Just to make sure I understand the differences.

Series is  + to - to + to - and so on.

and

Parallel is + to + to + and - to - to - and so on.
 
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 209
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Using the Tool at http://led.linear1.org/led.wiz

it has me using 3, 56 ohms resistors for the red. one resistor for every two LEDS.  but it places them on the cathode.  I am using common cathode LEDS so is it OK to put them On the Anodes?

I am learning a lot thanks

Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 150
Posts: 5666
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it has me using 3, 56 ohms resistors for the red. one resistor for every two LEDS.  but it places them on the cathode.  I am using common cathode LEDS so is it OK to put them On the Anodes?

Yes.

Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Full Member
***
Karma: 1
Posts: 209
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry to bug once more, But as I said before i am very new to this. i was hoping maybe you could help me out one more time. I have only worked with transistors once and I was fallowing a video.


In my case using RGB common cathodes do I put the pin out of the Arduino to the Base, 5v to the collector and the LED Anode to the Emitter. Or and I way off.


 
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 150
Posts: 5666
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In my case using RGB common cathodes do I put the pin out of the Arduino to the Base, 5v to the collector and the LED Anode to the Emitter.

Yes.

Beware though, with the transistor up near the 5V line it will only work if you use a PNP transistor, not an NPN.

Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Full Member
***
Karma: 1
Posts: 209
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Yes.

Beware though, with the transistor up near the 5V line it will only work if you use a PNP transistor, not an NPN.


Darn, I spent all day reading up On NPN because I have a bunch. If you don't mind can I ask you a few more questions,

First, Do i have to use Transistors?  When I hook it up to My Arduino (with the right resistors) it works like a charm.  But when i put it on a Bread Board with a atTiny85 and my DC power supply set to 5v. it works. Not a well, the transition are not as smooth. Is that because of the lack of transistors or is it the at85 .

And lastly. will I need a resistor on the base pin of the PNP if so can you recommend the size.

Once more Thank you for all your help. I would like to repay you some how.
Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Just wondering what pin definitions you use in place of these on the ATTiny85 version?
Code:
// Output pins for PWM
#define  R_PIN  3  // Red LED
#define  G_PIN  5  // Green LED
#define  B_PIN  6  // Blue LED
As there is no D6 on that uC I'm hoping your ATTiny85 version was using 0, 1 and 4 (physical legs 5,6 & 3) which have hardware PWM support for that analogWrite() later in the sketch.

Cheers ! Geoff
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Offline Offline
Full Member
***
Karma: 1
Posts: 209
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Just wondering what pin definitions you use in place of these on the ATTiny85 version?
Code:
// Output pins for PWM
#define  R_PIN  3  // Red LED
#define  G_PIN  5  // Green LED
#define  B_PIN  6  // Blue LED
As there is no D6 on that uC I'm hoping your ATTiny85 version was using 0, 1 and 4 (physical legs 5,6 & 3) which have hardware PWM support for that analogWrite() later in the sketch.

Cheers ! Geoff

Sorry I posted the sketch for the Arduino.

On the at85 I use 3,Red 0,Green 1,Blue.
Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

On the at85 I use 3,Red 0,Green 1,Blue.
Shuffle that red over to D4 and I think you'll have a better result.  The tiny core doesn't give you hardware PWM control on D3 so the effect of analogWrite() will be a harsh cut-over from OFF to ON.

As identified above, you will still need to drive them using a transistor of some sort as (from page 166 of the ATTiny85 datasheet)  the maximum power for any one pin is only 40mA so rather than sourcing the LED power from a pin you'll want to control it from a pin, and have the LEDs draw their power directly from a source that's attenuated by that transistor-PWM combination.

Cheers ! Geoff
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 150
Posts: 5666
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Darn, I spent all day reading up On NPN because I have a bunch.

Common-cathode LEDs cause these pains.

It's basically the same though, except the output will be inverted (pin LOW=LED on).

First, Do i have to use Transistors?  When I hook it up to My Arduino (with the right resistors) it works like a charm.  But when i put it on a Bread Board with a atTiny85 and my DC power supply set to 5v. it works. Not a well, the transition are not as smooth. Is that because of the lack of transistors or is it the at85 .

The chip's I/O pins start to burn up at 40mA. There's no way you can drive six LEDs from one pin without damaging the chip (the effect you see is probably the chip fighting for its life).

And lastly. will I need a resistor on the base pin of the PNP if so can you recommend the size.

Yes, and for the same reason: You have to keep the current coming out of the chip below 40mA.

330 ohms is a good general-purpose value.
Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Full Member
***
Karma: 1
Posts: 209
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

can someone take a look at this before I burn something up. 

Thanks



* LED-Lamp1.jpg (33.96 KB, 539x480 - viewed 45 times.)
Logged

Pages: [1] 2 3 ... 5   Go Up
Jump to: