Pages: [1]   Go Down
Author Topic: RGB lamp problem  (Read 4690 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to make a RGB color lamp with pots to control the color.
It doesn't work, and can anyone help me?
Quote
/* RGB light attempt
Andrew p.(my mom won't let my put my last name on anything.)

so far this program doesn't work, 
but I am going to comment it anyway so that I can try to fix
it(i wrote it then remembered to comment.)
so i wanted to make a rgb color lamp with user-selectable color, 
and I thought i should use potentiometers.
so i connected 3 5k pots to analog pins 0, 1, and 2(with the other
2 leads connected to 5v and gnd, so that couldn't be the problem).
I connected a rgb led to digital pins 9, 10, adn 11(they are the 
ones with pwm on my arduino.)and i put the gnd pin to ground.
by the way, I'm using a deumilanove. I have a tragic history of 
buying a gadget and then a few weeks later the company comes out 
with a newer, better one. 
so of course Arduino came out with the Arduino uno a few weeks 
after I bought my deumilanove. smiley-cry
anyway, I'll stop rambling and comment the sketch.
i was just commenting the serial connection and i realized i 
forgot to mention that I'm sending the data to the serial port too
for debugging.
before this i sent to pot values to the serial port only, and that
worked, so it's probably the mapping and led pwming that's the 
problem.
this is my first major attempt at programming anything more than
a blink program and im only 12.
*/
int pot_red = 0;   //variables for storing the pot data.
int pot_green = 0; //red, green, and blue since it's a rgb lamp.
int pot_blue = 0;  //and set them at zero so the led doesn't
                   //flicker at the beggining of the sketch.

void setup()
{
  Serial.begin(9600); //begin the serial connection
}
void loop()
{
  pot_red = analogRead(0);   // read the 3 pots
  pot_green = analogRead(1); //and store the data in
  pot_blue = analogRead(2);  //each pot's var.
  Serial.print("r = ");  //print the pot values to the serial
  Serial.print(pot_red); //connection. earlier i did just this
  Serial.print(" g = "); //not the led output and mapping part,
  Serial.print(pot_green);//so that is probably the problem.
  Serial.print(" b = ");
  Serial.println(pot_blue);
  map(pot_red, 0, 1023, 0, 255);//map the pot values to inputs
  map(pot_green, 0, 1023, 0, 255);//for the pwm control.
  map(pot_blue, 0, 1023, 0, 255);
  analogWrite(9, pot_red);  //write the color values to the pwm.
  analogWrite(10, pot_green);//I've never done pwm before,
  analogWrite(11, pot_blue);//so im probably getting pwned by pwm.
  delay(200); //delay to let everything get caught up
}
  
  

Logged

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

"it doesn't work"

Not helpful.
What does the debug output look like?
Quote
and i put the gnd pin to ground
You're sure the LED is common cathode?
« Last Edit: January 23, 2011, 12:20:47 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.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@AWOL, sorry I didn't include what the debug input looks like, it looks like this:
r = 564 g = 227 b = 218
r = 564 g = 227 b = 215
r = 564 g = 228 b = 217
and goes on and on and on.(this is in the serial monitor window in
the Arduino development environment)
The part where the pot data gets sent through the serial connection seems to be working. The LED doesn't light up at all, even if I turn the knobs.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46029
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The LED doesn't light up at all
Try a simple digitalWrite(9, HIGH); in loop. If the LED on pin 9 does not light up, the LED is either installed backwards or is defective.
Logged

Norway
Offline Offline
Sr. Member
****
Karma: 4
Posts: 423
microscopic quantum convulsions of space-time
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, "it doesn't work" is a bit sparse.

Good thing you provided the sketch. Also a description of how you connected the potentiometers (or pots). Which sounds right btw. But no description of what kind of LED(s) you have (as AWOL is suggesting, common cathode or perhaps common anode), or if you use any resistors connected to them. Which you really (really!) should, so you don't destroy your Arduino. One resistor pr. Arduino output, to the LEDs different color pins. Then the common LED pin to either GND or Vcc, depending on the type of led. (If common anode, to the Vcc, and then you should also invert the analogWrite values - which in that case would be to take 255 and subtract your remapped pot_color values)

Anyway, it seems you forgot to define the output pins as output:
Code:
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
Which is the only thing I noticed atm.

This could be lucky if you didn't use any resistors, as the Arduino have an internal "pull-up" resistor at around 20 k ohm that is turned on if an INPUT pin (as an undefined pin would be) gets written a "1". But if this was the case, you should (maybe) notice a very dim LED.

Btw, don't feel bad for not having the newest one, the main difference as I understand it, is that the new Arduino Uno have a built-in USB connector (so no need for an external USB board with an FTD chip or similar).
Logged

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

@raron:
pinMode isn't necessary; it is taken care of by calling analogWrite.
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.

Norway
Offline Offline
Sr. Member
****
Karma: 4
Posts: 423
microscopic quantum convulsions of space-time
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

AWOL: Ah ok, I didn't know that.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@raron, I did use 100 ohm resistors on each pin of the led except for the common cathode.
@pauls, thank u for ur advice, but I don't have my arduino with me now. I will try it as soon as I can, and post whether it worked on this forum.
Logged

Pages: [1]   Go Up
Jump to: