Go Down

Topic: How to connect a LED Cathode (4-wire led) (Read 3478 times) previous topic - next topic

the_julle

Hi All.

I found one of my old LED Cathode that I once had inside a computer.
Now I want to connect to my Arduino Mega.

I found a good guide, showing how to connect a Common Cathode or a Common Anode.
Arduino Examples #1 Make An RGB Led Randomly Flash Different Colors

I wired my LED like this:
Black wire: GND
Yellow wire: PWM 8
Blue wire: PWM 10
Red wire: PWM 12.

And this is my code:
Code: [Select]
  digitalWrite(redPin, HIGH);
  digitalWrite(bluePin, HIGH);
  digitalWrite(greenPin, HIGH);
  digitalWrite(redPin, LOW);
  delay(1000);           
  digitalWrite(redPin, HIGH);
  digitalWrite(bluePin, LOW);   
  delay(1000);
  digitalWrite(bluePin, HIGH);
  digitalWrite(greenPin, LOW);   
  delay(1000);
  digitalWrite(redPin, LOW); 
  delay(1000);
  digitalWrite(greenPin, HIGH);
  digitalWrite(bluePin, LOW);
  delay(1000);
  digitalWrite(redPin, HIGH);
  digitalWrite(greenPin, LOW); 
  delay(1000);
  digitalWrite(redPin, LOW); 
  delay(1000);


When I run the program, this is the colors I get:
Blue+Green
Red+Blue
Off
Red+Green+Blue+White

So I never get only one color...

HOWEVER; if I remove the wire from GND, I get these colors:
Green
Red
Green,Red,Yellow

So, I guess this means, that I have hooked up the wires incorrectly. Can anyone help, how should I then connect the wires??

Youtube video:
https://www.youtube.com/watch?v=fV38cvRt44M&feature=youtu.be
Alex.

Hackscribble

Hi Alex

Code: [Select]
  digitalWrite(redPin, HIGH);
  digitalWrite(bluePin, HIGH);
  digitalWrite(greenPin, HIGH);
  digitalWrite(redPin, LOW);
  delay(1000);           


Quote
When I run the program, this is the colors I get:
Blue+Green


It looks like HIGH turns on the colour, and LOW turns it off. 

To get only red on, try ...

Code: [Select]
  digitalWrite(bluePin, LOW);
  digitalWrite(greenPin, LOW);
  digitalWrite(redPin, HIGH);
  delay(1000);           


Or am I misunderstanding what the problem is?

Regards

Ray


Hackscribble.  Writing about making things
hackscribble@outlook.com

the_julle

Hi Ray.

Thanks for your suggestion.
However, that doesn't work. I think it is due to wrong wiring.

So, I tried to wire it as an Anode instead:
Blue wire: 5 V
Yellow wire: PWM 8
Red wire: PWM 10
Black wire: PWM 12

And now this code works:
Code: [Select]
digitalWrite(redPin, LOW); // RED on
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, HIGH);
delay(200);     

digitalWrite(redPin, HIGH); // GREEN on
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, HIGH);
delay(200);   

digitalWrite(redPin, HIGH); // BLUE on
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, LOW);
delay(200); 



So my main question must then be: How can I tell if my LED is a Anode or a Cathode, if I do not have the datasheet, and nor can I see the legs of the LED?

With this setup (wire to 5V), it seems like it works. But with the old setup (wire to GND) I could still get something to light up...

Any suggestions and help is highly appreciated.
Alex.

Grumpy_Mike

Quote
I found a good guide, showing how to connect a Common Cathode or a Common Anode.
Arduino Examples #1 Make An RGB Led Randomly Flash Different Colors

No you found a crap guide.

You need a resistor in each of the colours NOT the common connection.

the_julle

Hi Mike.


What difference does it do, whether the resistor is on all the wires, or only the common one?
And why is the resistor even necessary?

I have now all the colors working with this wiring:
Blue wire: 5 V
Yellow wire: PWM 8
Red wire: PWM 10
Black wire: PWM 12
So that must mean, that I have an Anode LED. I just think it is weird to have the blue wire connected to +5V?


For reference, this is my final code:
Code: [Select]
int redPin = 8;
int greenPin= 10;
int bluePin = 12;

void setup()
{               
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}

void loop()
{
// Reset. All Off.
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, HIGH);
delay(2000); 

// Red
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, HIGH);
delay(2000); 

// Green
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, HIGH);
delay(2000); 

// Blue
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, LOW);
delay(2000);

// Yellow
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, HIGH);
delay(2000); 

// Cyan (Light Blue)
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
delay(2000); 

// Magenta (purple)
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, LOW);
delay(2000);

// White
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
delay(2000);
}
Alex.

steinie44

Quote

So my main question must then be: How can I tell if my LED is a Anode or a Cathode, if I do not have the datasheet, and nor can I see the legs of the LED?

Connect a 330 or 470 Ohm resistor to +5v
Touch the anode to the resistor and one lead to ground. If it lights up then it's Anode.
If it won't light up, reverse it and if it lights up then it's Cathode.

When a LED lights up the + is Anode and the - is Cathode.

Grumpy_Mike

Quote
What difference does it do, whether the resistor is on all the wires, or only the common one?

Because with only one resistor :-
1) the brightness will change depending on the number of LEDs that are lit.
2) the voltage drop across each colour is different and it prevents some from coming on when others are no irrespective of how the digital output lines are set.

Quote
And why is the resistor even necessary?


You need resistors in line with LEDs, because they are a non linear load, see why:-
http://www.thebox.myzen.co.uk/Tutorial/LEDs.html


the_julle

Thanks for your replies, and good links for documentation.

As I read it, we only need to resistor to limit the current.
It seems like, I only use 10mA on each pin. If I use a resistor, doesn't that mean, that the LED will get less current (the output pin will output the same amount of current no matter the resistor?)?

This means that the LED will not light as bright as it does now. So with only 10mA current usages - is a resistor still mandatory?

A quick comment about the Arduino code. I found a function called analogWrite, which writes a PWM signal to the digital lines. Why is it called something with analog?? What am I missing here to understand that name?
Alex.

Grumpy_Mike

Quote
It seems like, I only use 10mA on each pin.

What makes you think that?
Did you read that link?
How do you think you are limiting the current to 10mA?


Yes resistors are mandatory unless you use a constant current drive. As you are not yet up to using resistors a constant current drive is way out of your league at the moment.

For information on PWM see:-
http://www.thebox.myzen.co.uk/Tutorial/PWM.html


the_julle

I tried to measure it with a multimeter.
It varies between 10 - 16 mA, so I don't think I limited the current to 10mA, that is just what I am measuring :-)

I understand what a PWM signal is, but I just don't understand why they called the function analogWrite :-)
Alex.

Grumpy_Mike

Quote
It varies between 10 - 16 mA, so I don't think I limited the current to 10mA, that is just what I am measuring

Are you measuring it with the resistor in the common line? That is what is limiting the current. That is the resistor you should remove and replace by a short circuit. Then put a resistor in each colour, have you done this?

Quote

I understand what a PWM signal is, but I just don't understand why they called the function analogWrite

Because the smoothed version of the signal can be used as an analogue signal.

the_julle

Okay, so in order to make this correct, I found the old control box that comes with these LEDs.

As you can see from the PCB, the LEDs must be Anode, since they are connected directly to +5V.
But I cannot see what resistor size they used. Maybe you can help explaining the PCB?

Components used:
R1: 390 (orange, white, brown, gold)
R2: 27k (red, violet, orange, gold)
R3,R4,R5: 100k (brown,black,yellow,gold)
Q1,Q3: S8050 D 136
Q2: S8050 D 131
Q4,Q5,Q6; S8550 D 331

So based on this, I would say they use a 100k resistor for each color, but then again; that does sounds a really big resistor? So maybe they are doing something fancy on the PCB??
Alex.

the_julle

After reading up on how a transistor works, it seems like they uses the transistors with the 100k resistors to form a switch. This makes since since they need to be able to switch between the different colors.

I guess they then use R1 (390 ohm) as their resistor, and thus they are only using one resistor for all colors.

I tried to add the 100k resistor to my Arduino setup, and just as expected, nothing lights up. When adding the 390 ohm resistor, the LED is still able to light up.

I can see that it does not light up just as bright as without the resistor. Does that mean that I can try to use a resistor with less resistance? If so, when is enough enough?
Alex.

Grumpy_Mike

The blob thing covered with resin on the right angled board is an integrated circuit. That can be doing anything so you can not assume that the current limiting device for the LED is a resistor either on the board or in the LED circuit.

Yes that is what the 100K resistors are they are base resistors for the transistor.

Quote
the LEDs must be Anode,

I assume what you mean here is that the LEDs are common anode.

So you have taken the LEDs out of something and want to use it with the arduino, is that correct?

If so, connect the common line to +5, connect each colour to a 220R resistor and the other end of the resistor to a separate digital output. You should then be able to switch any colour or combinations of colour on and off. With digital pins these will be 7 different colours.
If you use PWM pins then you will be able to get almost unlimited colours by writing various values of PWM duty cycle to the pins.

the_julle

Thank you very much in confirming this!

So my very last question: How did you come up with the 220 ohm resistor?'
Alex.

Go Up