Pages: [1] 2   Go Down
Author Topic: RGB LEDs HELP!!!!  (Read 1452 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
HTML: How To Meet Ladies
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hey guys,
I'm really new to the Arduino, so bear with me.
I've been (trying) to work with RGB LEDs. I have this big project/idea in my head, so i bought one RGB LED to see if this idea can be brought to life! So i have a 4 pin common anode LED. I've been experimenting with the LED library, using "void setValue(byte val)" to set each RGB color. It's working ok...but not really. Any help would be much appreciated!
I was also wondering how i would hook up 3 potentiometers, one to control the RED, one to control the GREEN, and one to control the BLUE. Thanks a ton!
Logged

":<> H@(Ke|) :"

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25813
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
working ok...but not really. Any help would be much appreciated!
So?
Where is it?

BTW there are plenty of threads with exactly this code in, on the forum.
« Last Edit: June 30, 2009, 11:59:18 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

U of A, Tucson, AZ
Offline Offline
Full Member
***
Karma: 0
Posts: 164
Hello World
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It would really help to see your sketch.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
HTML: How To Meet Ladies
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't really have a code. I don't know what to do! I've tried doing something like this:

#include <LED.h>

LED led9 = LED(9);
LED led10 = LED(10);
LED led11 = LED(11);

void setup() {
}

void loop() {
led9.setValue(0);
led10.setValue(0);
led11.setValue(255);
}

But that's not really working. I figured that if i could get any color by setting the RGB colors to the byte value.

But my main problem is that when i try to connect a potentiometer, it grounds out and turns everything off! Any help with that!?!
Here's what i have:
Common Anode(+) to 5V
RED LED pin to 11
GREEN LED pin to 10
BLUE LED pin to 9
Potentiometer middle pin to Analog 2
Potentiometer Ground to GND
Potentiometer Power to 5V

Like i said. I would like to be able to control the RGB values with a Potentiometer. I only have one potentiometer at the time, so lets say that i would like to control the RED value and leave the the Green and Blue at high (or something like that). Thanks!  
Logged

":<> H@(Ke|) :"

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25813
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You MUST have current limiting resistors between your Arduino pins and the LEDs.

I'd break down the problem first.
Assuming you can get "Serial" to work, try reading values off your pots, and print them so that you can verify that the pot is working.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
You [glow]MUST[/glow] have current limiting resistors between your Arduino pins and the LEDs.

Additionally, if your LED is truly common anode, you will have to invert the value you pass to setValue(), using something like

l
Code:
led9.setValue(intensity ^ 255);
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
HTML: How To Meet Ladies
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ahh. ok. I tested my potentiometer using the serial.println and it seemed to work fine. I will try the intensity thing and post back soon. Thanks for all the quick responses!
Logged

":<> H@(Ke|) :"

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25813
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You said when you connect the pot , it resets - what value pot have you got?

(well-spotted EJ, I just saw the LED-to-pin connection and knee-jerked.
I guess at low PWM ratios the LEDs and output pins would probably be OK without resistors, but as the ratio got higher, maybe the average current gets too great)
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
HTML: How To Meet Ladies
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmm, i don't know. I just hooked up my Potentiometer and it worked fine. Didn't reset. Wierd. Anyway, i edited my code:  

led10.setValue(value ^ 255);

and that seemed to help a little. However when its all the way, one way...it'll get a deep red and as i start to turn it it gets whiter and whiter, then it goes back to red and does that about 4 times before the POT is all the way, the other way. Any suggestions?
« Last Edit: June 30, 2009, 12:31:58 pm by Shadown » Logged

":<> H@(Ke|) :"

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Let's see all the code.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25813
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"value = map (value, 0, 1023, 0, 255);"
before you call "setValue".
Or "value /= 4;"

analogRead goes 0...1023, analogWrite goes 0...255.

BTW red to "white"  sounds bad - better get those current limiters in soon, or it'll end in tears!
« Last Edit: June 30, 2009, 12:38:54 pm by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Bingo!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
HTML: How To Meet Ladies
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

YES! That worked! The map thingy! That's amazing! Thank you so much. So theoretically if i would get two more potentiometers and use the following code, i could get any color i want?

#include <LED.h>
int potPin1 = 1;
int potPin2 = 2;
int potPin3 = 3;
LED led9 = LED(9);
LED led10 = LED(10);
LED led11 = LED(11);

void setup() {
 pinMode(potPin1, OUTPUT);
 pinMode(potPin2, OUTPUT);
 pinMode(potPin3, OUTPUT);
}

void loop() {
  int value1 = analogRead(potPin1);
  int val1 = map(value1, 0, 1023, 0,255);
  int value2 = analogRead(potPin2);
  int val2 = map(value2,0,1203,0,255);
  int value3 = analogRead(potPin3);
  int val3 = map(value3,0,1203,0,255);

  led9.setValue(val1 ^ 255);
  led10.setValue(val2 ^ 255);
  led11.setValue(val3 ^ 255);
}

That should do it shouldn't it?!?!?
Also, how many ohm resistor would i need? I have an 650mcd(green) 120mcd(blue) RGB LED with a FW current: 30mA(green/blue) 50mA (red)
Logged

":<> H@(Ke|) :"

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yay!

50 ohm resistors will work for all three. It calculates more like 60 for the red but 50 should be close enough.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
HTML: How To Meet Ladies
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 smiley-grin Thanks guys! You guys are great! I don't mean to keep bothering you, but do any of you know anything about processing? I was thinking of a way to control the RGB values using processing instead of Potentiometers (or maybe use both!) I can't seem to find any good tutorials on Processing and the Arduino, so i was wondering if any of you knew?! Thanks again!  smiley-wink
Logged

":<> H@(Ke|) :"

Pages: [1] 2   Go Up
Jump to: