Go Down

Topic: Project 04 (Read 9187 times) previous topic - next topic

gustavjp

Mar 27, 2013, 08:49 pm Last Edit: Mar 27, 2013, 08:59 pm by gustavjp Reason: 1
I'm having some problems with the LED. For some reason, it's really hard to make it glow green. I know that the LED is functioning properly, I've made it glow only green, but as soon as I mix colours I get this problem. My r, g and b values are very similar to each other when equally exposed to a light source. They also correspond to being covered up in the same way.
My friend has the same problem as me. Is making the LED glow green some inherent problem this type of LED has or have I made some mistake?

This is my scaled down code, without the printing and stuff.
Code: [Select]

int r, g, b;
void setup() {
 Serial.begin(9600);
 pinMode(9, OUTPUT);
 pinMode(10, OUTPUT);
 pinMode(11, OUTPUT);
}
void loop() {
 r = analogRead(A0);
 g = analogRead(A1);
 b = analogRead(A2);
 analogWrite(11, (r/4));
 analogWrite(9, (g/4));
 analogWrite(10, (b/4));
}

sina92

I have the same issues.

I have the same, I suspect it's either a weak 'green' component in the LED or our eyes are just much more responsive to blue and red, so they drown out the green. In the end I ended up dividing red and blue by 10 and green by 3 to make the different colours visible
Photography nut trying to make the flux capacitor of macro pho

Tzyn


I have the same, I suspect it's either a weak 'green' component in the LED or our eyes are just much more responsive to blue and red, so they drown out the green. In the end I ended up dividing red and blue by 10 and green by 3 to make the different colours visible


Sorry about my noob question but, how do you know for how much you have to "divide" the colors, or you just tryed different values till you get the led glow white?

dean_1230



I have the same, I suspect it's either a weak 'green' component in the LED or our eyes are just much more responsive to blue and red, so they drown out the green. In the end I ended up dividing red and blue by 10 and green by 3 to make the different colours visible


Sorry about my noob question but, how do you know for how much you have to "divide" the colors, or you just tryed different values till you get the led glow white?


Open the serial monitor and look at the values.  In my case, the r-g-b values are 131, 105 & 86, which should imply a reddish-green color, but it's more purple (reddish-blue).  Getting white is very difficult, as the green element just doesn't transmit well (due either to our lack of sensitivity to green or to a weak green LED element). 

I manually set the values to see what different ratios gave and the only way I could get a good green led was to set the r-g-b to 3-255-3.  Even setting the red and blue to 5 made the light noticeably non-green. 

To get a white led (ok, mostly white when looking from the side), I manually set the values to 20-255-20.  Once the red and blue values hit 50, the color was noticeably blue-purple.

KirAsh4

Not sure what project you're doing, not sure what LED you're using.  However, most RGB LEDs have different forward voltage values, so you can't use the same size resistors on all three channels.  And if you are using a single resistor on the cathode, you're doing it wrong.

Tzyn



Code: [Select]


void loop() {
  r = analogRead(A0);
  g = analogRead(A1);
  b = analogRead(A2);
  analogWrite(11, (r/4));
  analogWrite(9, (g/4));
  analogWrite(10, (b/4));
}



I really dont get why we have to divide here by 4  :~

BTW thanks for your help dean_1230 and KirAsh4!

#7
Apr 29, 2013, 12:03 pm Last Edit: Apr 29, 2013, 07:41 pm by nass Reason: 1
Tzyn, sorry for not replying sooner but yes I just did it by eye. I measured with a multimeter and there wasn't anything wrong with the circuits so I just figured the LEDs had different brightnesses, so adjusted accordingly.



I have the same, I suspect it's either a weak 'green' component in the LED or our eyes are just much more responsive to blue and red, so they drown out the green. In the end I ended up dividing red and blue by 10 and green by 3 to make the different colours visible


Sorry about my noob question but, how do you know for how much you have to "divide" the colors, or you just tryed different values till you get the led glow white?
Photography nut trying to make the flux capacitor of macro pho

Tzyn

Thank you Nass! x)

dean_1230


Not sure what project you're doing, not sure what LED you're using.  However, most RGB LEDs have different forward voltage values, so you can't use the same size resistors on all three channels.  And if you are using a single resistor on the cathode, you're doing it wrong.


Here's the spec sheet for the RGB LED:
http://arduino.cc/documents/datasheets/LEDRGB-L-154A4SURK.pdf

Forward voltages are 1.95/3.3/3.3 respectively. 

As for the number and size of the resistors, going from memory (don't have the book in front of me at the moment) I think the
resistor strengths are all the same.  Maybe someone that has the book handy can check.

Tzyn

The resistor strengths are all the same, ill check the value as soon as i get home and post here!

KirAsh4


Forward voltages are 1.95/3.3/3.3 respectively. 

As for the number and size of the resistors, going from memory (don't have the book in front of me at the moment) I think the
resistor strengths are all the same.  Maybe someone that has the book handy can check.


So therein lies (part of) the issue.  With different voltages, you really need different resistor sizes as well.  Assume you're supplying 5V to them, and assuming you want to drive the LEDs at 20mA, you should be using:
Code: [Select]
(5V - 1.95)/20mA = 152.5 Ohm, round it up to the nearest size and you get 180 Ohm, which when recalculated means the LED is being driven at 16.9mA
(5V - 3.3)/20mA = 85mA, round it up to the nearest size and you get 100 Ohm, recalculated gets you 17mA on the LED


You can use exact sizes, if you can find them, however going to the nearest common size is usually cheaper and the human eye will have a hard time noticing the difference anyway.

Hello, i cant get my LED to change color at all, i've already checked my circuit/code twice and cant find any error.
when i wave my hand over the photoresistors i get different values in the serial monitor but the led never changes color... any help?

thanks

Hi guys,

Try this code if you have completed project 4 and want to try something 'extra'. I've added a 10 sec calibration and set constraint for output between 0 to 255 to prevent flickering. The effect is fantastic. You can also set brightness in the code, so that it won't blind you in dark environment.

For those of you who experienced problems, you might want to check your resistors. I used 10M Ohm instead of 10k Ohm in the beginning.  :smiley-eek:
I was stumped for 2 days because of wrong resistors because I had no multimeter that time.

Code: [Select]

/*
  Arduino Starter Kit example
Project 4  - Color Mixing Lamp (Extra added)

This sketch is written to accompany Project 3 in the
Arduino Starter Kit

Parts required:
1 RGB LED
three 10 kilohm resistors
3 220 ohm resistors
3 photoresistors
red green and blue colored gels

Created 13 September 2012
Modified 14 November 2012
by Scott Fitzgerald
Thanks to Federico Vanzati for improvements

Extra features added by Lam Kwok Leong, 8 July 2013

http://arduino.cc/starterKit

This example code is part of the public domain
*/

const int Brightness = 20;  // set overall brightness, use lower value in darkroom to protect your eyes (0-255)

const int greenLEDPin = 9;    // LED connected to digital pin 9
const int redLEDPin = 10;     // LED connected to digital pin 10
const int blueLEDPin = 11;    // LED connected to digital pin 11

const int redSensorPin = A0;  // pin with the photoresistor with the red gel
const int greenSensorPin = A1;   // pin with the photoresistor with the green gel
const int blueSensorPin = A2;   // pin with the photoresistor with the blue gel

int redSensorValue = 0; // variable to hold the value from the red sensor
int greenSensorValue = 0; // variable to hold the value from the green sensor
int blueSensorValue = 0; // variable to hold the value from the blue sensor

int redSensorHigh = 0; //High and low value for mapping. Notice that 'High' value were set low at 0, so that during calibration, its value would be be pushed up. See project 6.
int greenSensorHigh = 0;
int blueSensorHigh = 0;
int redSensorLow = 1023; // the opposite is true for 'Low' value
int greenSensorLow = 1023;
int blueSensorLow = 1023;

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);

  // set the digital pins as outputs
  pinMode(greenLEDPin,OUTPUT);
  pinMode(redLEDPin,OUTPUT);
  pinMode(blueLEDPin,OUTPUT);
 
  //switching on your lamp before calibration, as it would affect calibration too, especially in dark environment
  analogWrite(redLEDPin, Brightness);
  analogWrite(greenLEDPin, Brightness);
  analogWrite(blueLEDPin, Brightness);
 
  //actual calibration which takes 10 seconds. During calibration, LED would shine at constant brightness. After that, it'll start to respond.
  while (millis() < 10000) {
  redSensorValue = analogRead(redSensorPin);  //read pin
  if (redSensorValue > redSensorHigh) {  //push 'High' value up based on sensor value. At the end of calibration, 'High' value would take the highest 'SensorValue' during the 10 seconds.
  redSensorHigh = redSensorValue;
  }
  if (redSensorValue < redSensorLow) { //opposite is true for 'Low' value
  redSensorLow = redSensorValue;
  }
  delay(5);
 
  greenSensorValue = analogRead(greenSensorPin); 
  if (greenSensorValue > greenSensorHigh) {
  greenSensorHigh = greenSensorValue;
  }
  if (greenSensorValue < greenSensorLow) {
  greenSensorLow = greenSensorValue;
  }
  delay(5);
  blueSensorValue = analogRead(blueSensorPin); 
  if (blueSensorValue > blueSensorHigh) {
  blueSensorHigh = blueSensorValue;
  }
  if (blueSensorValue < blueSensorLow) {
  blueSensorLow = blueSensorValue;
  }
  delay(5);
  }
}

void loop() {
  // Read the sensors first:
 
  // read the value from the red-filtered photoresistor:
  redSensorValue = analogRead(redSensorPin);
 
  // give the ADC a moment to settle
  delay(5);
  // read the value from the green-filtered photoresistor:
  greenSensorValue = analogRead(greenSensorPin);
  // give the ADC a moment to settle
  delay(5);
  // read the value from the blue-filtered photoresistor:
  blueSensorValue = analogRead(blueSensorPin); 

  // print out the values to the serial monitor 
  Serial.print("raw sensor Values \t red: ");
  Serial.print(redSensorValue);
  Serial.print("\t green: ");
  Serial.print(greenSensorValue);
  Serial.print("\t Blue: ");
  Serial.println(blueSensorValue);

  /*
  In order to use the values from the sensor for the LED,
  you need to do some math. The ADC provides a 10-bit number,
  but analogWrite() uses 8 bits. You'll want to divide your
  sensor readings by 4 to keep them in range of the output.
  */
  /*
  Changed from a mere division by 4 in the original code to mapping.
  Lowest value recorded at calibration would be mapped to 0, and highest value would be mapped to brightness set earlier.
  The constraint function is set to prevent flickering, when value are negative or exceeds 255.
  */
 

  int redValue = map(redSensorValue,redSensorLow,redSensorHigh,0,Brightness);
  redValue = constrain(redValue,0,255);
  int greenValue = map(greenSensorValue,greenSensorLow,greenSensorHigh,0,Brightness);
  greenValue = constrain(greenValue,0,255);
  int blueValue = map(blueSensorValue,blueSensorLow,blueSensorHigh,0,Brightness); 
  blueValue = constrain(blueValue,0,255);

  //  print out the mapped values 
  Serial.print("Mapped sensor Values \t red: ");
  Serial.print(redValue);
  Serial.print("\t green: ");
  Serial.print(greenValue);
  Serial.print("\t Blue: ");
  Serial.println(blueValue);

  /*
  Now that you have a usable value, it's time to PWM the LED.
  */
  analogWrite(redLEDPin, redValue);
  analogWrite(greenLEDPin, greenValue);
  analogWrite(blueLEDPin, blueValue);
}


kaning

you guys dont have any problem with code or anything else i think. for making color green you need to mix yellow and blue and RGB LED dont have yellow lamp, besides you are controling it with light what makes it even less precise, instead of LDR's or after them mount potenciometers (1 for each) and you will see the diference, i got awesome colors that controling with light were impossible to have like very intense orange.very nice!! cumps

Go Up