Pages: 1 [2]   Go Down
Author Topic: lighting design with 3 outputs[Newbie]  (Read 2743 times)
0 Members and 1 Guest are viewing this topic.
Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Not really, anything in series can swap order. Same math.
Logged


Belfast
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm currently designing my RGB LED array and I'm using this http://led.linear1.org/led.wiz to calculate what resistors I will need.

As mentioned above these are the LEDS I will be using - http://uk.farnell.com/jsp/search/productdetail.jsp?id=1716734&Ntt=1716734

So my question... When the wizard asks me for the forward voltage, the spec of the LEDs list different voltages for each colour. Using the 2.2V (Red value) gives me one answer for the type of resistor (22 ohms) and using the 3.5V figure (for Green or Blue) tells me to use 56 ohm resistors...

Or do I need 3 resistors for each LED and so 2 will be 56ohm and 1 will be 22ohm ?

I'm a bit confused, can anyone help?
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow, you must have put 150mA for red LED, to get 22 Ohm. That's very large current. You can't use your Arduino pins to directly power that LED unless you can drop down the current to 20mA (max rating is 40mA). This means 150 Ohm. The microcontroller chip can only provide a maximal of 200mA through all its pins so you don't get to power lots of RGB LEDs from directly hooking them up to arduino pins. To use that much current (150mA), you need a transistor to drive the LED. Then your Arduino board can only provide 500mA so to run 150mA per color and a number of RGB LEDs, you need external power.
Logged


Belfast
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes I think I have realised I need to use an external power source to run all the components that I have listed in my original post.... There will be 20 LEDs at least....

Did I make a mistake in the calculator though to get 22 ohms?
Logged

Belfast
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmm, this tutorial http://www.instructables.com/id/RGB-LED-Tutorial-using-an-Arduino-RGBL/

says I need 270 ohm resistors (3 per LED) to get the current down to 20mA

Where am I going wrong with the resistor calculator? I don't want to buy 60 resistors of the wrong type!
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You did it right. It's just not doable directly with arduino pins. The instructable.com page is not accurate but approximate since it doesn't mention current and voltage of the diodes. You'll be more than safe with 270ohm resistor.

I suggest you limit your current with say 270 ohm (dimmer than if you use 150 ohm but no big deal). Then use arduino pins to directly drive up to 3 RGB LEDs. Once you're comfortable with your project, you can move on to power your RGB LEDs with independent supply, and switch them with TLC5940 or use a matrix to only switch one one light at a time and turn on each light in sequence rapidly so they seem to be on together.

Like this one:

http://hackaday.com/tag/tlc5940/

You can control 16 colors = 5.333 RGB LEDs per tlc5940 chip.
Logged


Belfast
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Excellent, thanks for your help smiley

When I come to need an external power source will I need to use a power shield like this - http://proto-pic.co.uk/products/Power-Driver-Shield-Kit.html ?
Logged

Belfast
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Update - I have Got the Array working with two pots, one to control the brightness and another the colour. It works well smiley

Now starting the random light.
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Great! Post some pics!
Logged


Belfast
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Will do as soon as I can.

I've got the blinking light to kind of work too now smiley

I need to try and get it just to flash though instead of being on for a random length of time as well as off. It's the same problem described at the end of this thread but it didn't seem to be resolved - http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1201656636/15

anyway, here's my code so far.

Code:
const int hpotpin = 1;              // Hue controller connected to digital pin 1
const int fpotpin = 0;              // Brightness controller connected to digital pin 0

int rpin = 10; //Red in array of RGBs
int gpin = 6; //Green in array of RGBs
int bpin = 11; //Blue in array of RGBs

float h;
int h_int;
int r=0, g=0, b=0;
int hval=0;
void h2rgb(float h, int &r, int &g, int &b);

// these variables store the values for the fade knob and LED level
int fpotpinValue, fval;

// For blinking LED

#define numberOfLEDs 1
long nextFlash[1];
int ledPin[] = { 4 }; // LED pins to use.
int ledState[1];

void setup()                    // run once, when the sketch starts
{
  Serial.begin(9600);           // set up Serial library at 9600 bps
   for(int i = 0; i<numberOfLEDs; i++){
   pinMode(ledPin[i],OUTPUT);
   ledState[i] = LOW;
   digitalWrite(ledPin[i], LOW); // all LEDs off
    nextFlash[i] = millis() +random(1, 1000);
}
}


void loop()                     // run over and over again
{
  // Two pot controlled RGB LEDs
 
  hval=analogRead(hpotpin);    // Hue pot
  fpotpinValue=analogRead(fpotpin); // Fade Pot
  fval = map(fpotpinValue, 0, 1023, 0 , 255);   // remap the values from 10 bit input to percentage
  h = ((float)hval)/1024;
  h_int = (int) 360*h;
  h2rgb(h,r,g,b);
 
  //Blinking
 
  for(int i = 0; i<numberOfLEDs; i++){
if(millis() > nextFlash[i]){
  if(ledState[i] == LOW) ledState[i] = HIGH; else ledState[i] = LOW;
  digitalWrite(ledPin[i],ledState[i]);
  nextFlash[i] = millis()+random(100, 1000) ; // next toggle random time
} }
 
  Serial.print(h);
  Serial.print("Potentiometer value: ");
  Serial.print(hval);
  Serial.print(" = Hue of ");
  Serial.print(h_int);
  Serial.print("degrees. In RGB this is: ");
  Serial.print(r);
  Serial.print(" ");
  Serial.print(g);
  Serial.print(" ");
  Serial.print(b);
  Serial.print("Fade: ");
  Serial.println(fval);

  analogWrite(rpin, r);
  analogWrite(gpin, g);
  analogWrite(bpin, b);
}

void h2rgb(float H, int &R, int&G, int&B) {

  int var_i;
  float S=1, V=1, var_1, var_2, var_3, var_h, var_r, var_g, var_b;

  if ( S == 0 )                       //HSV values = 0 ÷ 1
  {
    R = V * 255;
    G = V * 255;
    B = V * 255;
  }
  else
  {
    var_h = H * 6;
    if ( var_h == 6 ) var_h = 0;      //H must be < 1
    var_i = int( var_h ) ;            //Or ... var_i = floor( var_h )
    var_1 = V * ( 1 - S );
    var_2 = V * ( 1 - S * ( var_h - var_i ) );
    var_3 = V * ( 1 - S * ( 1 - ( var_h - var_i ) ) );

    if      ( var_i == 0 ) {
      var_r = V     ;
      var_g = var_3 ;
      var_b = var_1 ;
    }
    else if ( var_i == 1 ) {
      var_r = var_2 ;
      var_g = V     ;
      var_b = var_1 ;
    }
    else if ( var_i == 2 ) {
      var_r = var_1 ;
      var_g = V     ;
      var_b = var_3 ;
    }
    else if ( var_i == 3 ) {
      var_r = var_1 ;
      var_g = var_2 ;
      var_b = V     ;
    }
    else if ( var_i == 4 ) {
      var_r = var_3 ;
      var_g = var_1 ;
      var_b = V     ;
    }
    else                   {
      var_r = V     ;
      var_g = var_1 ;
      var_b = var_2 ;
    }

    R = (1-var_r) * fval;                  //RGB results = 0 ÷ fade value
    G = (1-var_g) * fval;
    B = (1-var_b) * fval;
  }
}

I'll try and post a video and a wiring diagram in the next few days smiley
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This should do your constant on flash:
Code:
const int FlashDuration=200; //Fixed length time in millisecs for led to stay on

  for(int i = 0; i<numberOfLEDs; i++)
    {
    if(millis() > nextFlash[i])
      {
      ledState[i]=!ledState[i];
      if(ledState[i]) //Led is going on, set to fixed length of flash
        nextFlash[i] = millis()+FlashDuration;
      else 
        nextFlash[i] = millis()+random(100, 1000) ; // led stays off for random interval
      digitalWrite(ledPin[i],ledState[i]);
      }
    }

Logged

Belfast
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Magnificent! smiley
Logged

Belfast
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Right well got 2 lighting outputs running together and it works very well smiley

The first is an array of common cathode RGB LEDs where each colour R,G and B runs off a separate PWM pin.
The second is a number of randomly flashing LEDs (I use 5 - each off a separate digital pin).

There are two potentiometers, one to control the brightness of th RGB array, and the other to control the hue. This second pot also controls the speed at which the random flashes fire but I will get a 3rd pot to do this I think..

There are also two switches connected to digital pins. One switch toggles the random flashes on and off, the other switches it from adjustable colour to white (R,G & B all full). I'm not sure if I'll keep it this way but it works for now.

Here's the code:

Code:
// Potentiometers

const int hpotpin = 1;              // Hue input connected to digital pin 1
const int fpotpin = 0;              // Fade input connected to digital pin 1

// switches

#define swPin 2                 // pin for RGB LED array switch input  - note: no semicolon after #define
int stateA, stateB;             // variables to store pin states
int sw1, sw2;                   // variables to represent switch states

#define sw2Pin 0                 // pin for blinking switch input  - note: no semicolon after #define
int state2A, state2B;             // variables to store pin states
int sw21, sw22;                   // variables to represent switch states

// RGB LEDs (3 pwm pins to allow for brightness control)

int rpin = 10;                      //PWM pin for red in RGB LEDs
int gpin = 6;                       //PWM pin for green in RGB LEDs
int bpin = 11;                      //PWM pin for blue in RGB LEDs

// Blinking LEDs

#define numberOfLEDs 5
long nextFlash[5];  //Not sure whether this number has to be the same as the number of leds?
int ledPin[] = { 4, 5, 8, 12, 13 }; // LED pins to use.
int ledState[5];  //Not sure about this either
const int FlashDuration=10; //Fixed length time in millisecs for led to stay on

// For calculating the hue value and converting to RGB

float h;     
int h_int; //Hue value (temperature)
int r=0, g=0, b=0;
int hval=0;
void h2rgb(float h, int &r, int &g, int &b);

// these variables store the values for the fade knob and LED level
int fpotpinValue, fval;


void setup()                   
{
   Serial.begin(9600);           // set up Serial library at 9600 bps
   for(int i = 0; i<numberOfLEDs; i++){
   pinMode(ledPin[i],OUTPUT);
   ledState[i] = LOW;
   digitalWrite(ledPin[i], LOW); // all LEDs off
    nextFlash[i] = millis() +random(1, 5000);   

}
}
void loop()           
{
   // Switch 1 - RGB LED array
   
   digitalWrite(swPin, LOW);                   // make sure the puillup resistors are off
   stateA = digitalRead(swPin);
   digitalWrite(swPin, HIGH);                  // turn on the puillup resistors
   stateB = digitalRead(swPin);

   if ( stateA == 1 && stateB == 1 ){          // both states HIGH - switch 1 must be pushed
      sw1 = 1;
      sw2 = 0;
     
      //switch state for off
     
       // read the value from the input
  fpotpinValue = analogRead(fpotpin);
  // remap the values from 10 bit input to 8 bit output
  fval = map(fpotpinValue, 0, 1023, 0 , 254);
 
  // use the input value to fade the led in white
  analogWrite(rpin, fval);
  analogWrite(gpin, fval);
  analogWrite(bpin, fval);

    // switch state end
 
   }
   else if ( stateA == 0 && stateB == 0 ){     // both states LOW - switch 2 must be pushed
      sw1 = 0;
      sw2 = 1;
     
      //switch state for on
     
  // Two pot controlled RGB LEDs
 
  hval=analogRead(hpotpin);    // Hue pot
  fpotpinValue=analogRead(fpotpin); // Fade Pot
  fval = map(fpotpinValue, 0, 1023, 0 , 255);   // remap the values from 10 bit input to percentage
  h = ((float)hval)/1024;
  h_int = (int) 360*h;
  h2rgb(h,r,g,b);
 
  analogWrite(rpin, r);
  analogWrite(gpin, g);
  analogWrite(bpin, b);
 
     // RGB LEDs  end
 
    // switch state end
   
   }
   else{                                       // stateA HIGH and stateB LOW
      sw1 = 0;                                 // no switches pushed - or center-off toggle in middle position
      sw2 = 0;
   } 
   // Switch 1 - End
   
   
   // Switch 2 - Blinking LEDs
   
   digitalWrite(sw2Pin, LOW);                   // make sure the puillup resistors are off
   state2A = digitalRead(sw2Pin);
   digitalWrite(sw2Pin, HIGH);                  // turn on the puillup resistors
   state2B = digitalRead(sw2Pin);

   if ( state2A == 1 && state2B == 1 ){          // both states HIGH - switch 1 must be pushed
      sw21 = 1;
      sw22 = 0;
     
      //switch state for off
     
      // switch state end
 
   }
   else if ( state2A == 0 && state2B == 0 ){     // both states LOW - switch 2 must be pushed
      sw21 = 0;
      sw22 = 1;
     
      //switch state for on
 
        //Blinking
 
 // read the value from the input
  fpotpinValue = analogRead(fpotpin);
  // remap the values from 10 bit input to 8 bit output
  fadeValue = map(fpotpinValue, 0, 1023, 10 , 5000); //Milliseconds
 
 for(int i = 0; i<numberOfLEDs; i++)
    {
    if(millis() > nextFlash[i])
      {
      ledState[i]=!ledState[i];
      if(ledState[i]) //Led is going on, set to fixed length of flash
        nextFlash[i] = millis()+FlashDuration;
      else 
        nextFlash[i] = millis()+random(10, fadeValue) ; // led stays off for random interval
      digitalWrite(ledPin[i],ledState[i]);
      }
    }
   
       // Blinking end
    // switch state end
   }
   else{                                       // stateA HIGH and stateB LOW
      sw21 = 0;                                 // no switches pushed - or center-off toggle in middle position
      sw22 = 0;
   }
   // Switch 2 - End
   
   
   
   
   
}     //Loop End


// Sub routine for converting the HUE to RGB

void h2rgb(float H, int &R, int&G, int&B) {

  int var_i;
  float S=1, V=1, var_1, var_2, var_3, var_h, var_r, var_g, var_b;

  if ( S == 0 )                       //HSV values = 0 ÷ 1
  {
    R = V * 255;
    G = V * 255;
    B = V * 255;
  }
  else
  {
    var_h = H * 6;
    if ( var_h == 6 ) var_h = 0;      //H must be < 1
    var_i = int( var_h ) ;            //Or ... var_i = floor( var_h )
    var_1 = V * ( 1 - S );
    var_2 = V * ( 1 - S * ( var_h - var_i ) );
    var_3 = V * ( 1 - S * ( 1 - ( var_h - var_i ) ) );

    if      ( var_i == 0 ) {
      var_r = V     ;
      var_g = var_3 ;
      var_b = var_1 ;
    }
    else if ( var_i == 1 ) {
      var_r = var_2 ;
      var_g = V     ;
      var_b = var_1 ;
    }
    else if ( var_i == 2 ) {
      var_r = var_1 ;
      var_g = V     ;
      var_b = var_3 ;
    }
    else if ( var_i == 3 ) {
      var_r = var_1 ;
      var_g = var_2 ;
      var_b = V     ;
    }
    else if ( var_i == 4 ) {
      var_r = var_3 ;
      var_g = var_1 ;
      var_b = V     ;
    }
    else                   {
      var_r = V     ;
      var_g = var_1 ;
      var_b = var_2 ;
    }

    R = (1-var_r) * fval;                  //RGB results = 0 ÷ fade value from pot
    G = (1-var_g) * fval;                  //In effect we are creating the L value of the HSL colour model 
    B = (1-var_b) * fval;
  }
}

Attached is a breadboard drawing that I did in fritzing.

Lastly here's a video of it in action smiley

(not sure how to embed youtube in this post)...

Thanks for all your help... I've learnt a lot! cheers. The next step is to get a laser firing randomly and introduce a disposable camera flash flashing randomly.... Hopefully I'll learn a bit about opto-isolators, relays, mosfets and capacitors.... maybe transistors too.



* Fritzing Breadborad for lighting_bb.png (155.06 KB, 1140x708 - viewed 11 times.)
Logged

Belfast
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

At the moment I have the hue adjustable by one pot and a switch to make it 'white' (i.e. all colours up full).

Is it possible to split the range of the pot so that (out of 1024) the first 900 control the colour and the last 124 are reserved for 'white' ?

Cheers!
Logged

Pages: 1 [2]   Go Up
Jump to: