Go Down

### Topic: How to make a mood light with rgb led (Read 2503 times)previous topic - next topic

#### hitekos

##### May 23, 2011, 11:52 pm
Hi i'm kind of a noob at arduino and i would like to make a mood light. I have an arduino duemilanove and an rgb led.
I tried this http://blog.bsoares.com.br/processing/controlling-rgb-led-with-arduino-and-processing but it didn't work as well as the video(colors are diferent, maybe it's not the same led).

#### Simpson_Jr

#1
##### May 24, 2011, 01:17 amLast Edit: May 24, 2011, 01:40 am by Simpson_Jr Reason: 1
Unfortunately my knowledge of the Portuguese language is as good as my knowledge of Chinese

I do know that 4-pin RGB leds are sold with either a common Cathode or a common Anode.

Using the "wrong" one will result in the opposite of what you try to achieve.
Pointing at a white part of the window, which normally turns all colours on, will result in dimming the led. Pointing at green only will turn green off,  blue and red on, resulting in a pink colour.

If that's the case you can quite easily make it all right by changing the arduino sketch.

Code: [Select]
`  r = color >> 16 & 0xFF;  g = color >>  8 & 0xFF;  b = color >>  0 & 0xFF;  // Send values to analog pins  analogWrite(PIN_RED, r);  analogWrite(PIN_GREEN, g);  analogWrite(PIN_BLUE, b);`

Above is part of the code for the led the author used to control the different colours.
Changing it to the opposite using the code below should result in getting the colours the author wanted to show.

Code: [Select]
`  r = color >> 16 & 0xFF;  g = color >>  8 & 0xFF;  b = color >>  0 & 0xFF;  // change colours to the opposite here  r = 255 - r;  g = 255 - g;  b = 255 - b;  // Send values to analog pins  analogWrite(PIN_RED, r);  analogWrite(PIN_GREEN, g);  analogWrite(PIN_BLUE, b);`

I hope this will solve your problem.

#### Ryan J Blajda

#2
##### May 24, 2011, 01:18 am
So what do you want to do?

Do you want it to be a standalone mood light of some sort? or do you want to be able to control the color like in the video? And i wouldn't worry about the colors being the same because most cameras distort colors horribly.

(BTW i am very new to Arduino as well but ill do my best to help)

#### hitekos

#3
##### May 24, 2011, 01:47 pm
i'm looking for a better processing code to control the led and i think i hae the oposit of the led used in the tutorial, what it is called?

#### Simpson_Jr

#4
##### May 24, 2011, 02:31 pm
Ouch, forgot to mention one part, my mistake, sorry...

The author did use a Common Cathode, connecting the common pin to ground.

In case of an Common Anode RGB-led you should connect the common pin to +5 volt (and change the code) as well.

In the tutorial he does mention the use of resistors, but for some reason he doesn't seem to use them in the pictures given. That could ruin Led/arduino.

With a resistor of ~220 ohm you should be able to determine what type your Led is.
Connect the common pin to ground, connect the resistor to +5volt on one side and a colour-pin on the other. If it lights up it's a common Cathode.

If it lights up when you change ground and +5Volts using this set-up it's a Common Anode.

Colours shown may indeed differ due to camera and Led. I've got a few 5mm leds and a few high power RGBs, but they're quite different in colour.

It should by the way also be possible to change the code in processing instead of the arduino sketch.

#### hitekos

#5
##### May 25, 2011, 10:53 am
I tested it i have a common Cathode. Thanks for the tip.

Go Up

Please enter a valid email to subscribe