Project 4 - Color Mixing Lamp

Hi,

I'm wondering if somebody could help me. I've wired up the board as per the guide, switched it on, and I do not see the LED lamp light up and placing my finger any of the photoresistors doesn't change the LED.

My serial output is as follows;
]]raw sensor Values red: 0 green: 0 Blue: 0
Mapped sensor Values red: 0 green: 0 Blue: 0
raw sensor Values red: 0 green: 0 Blue: 0

What have I done? Or what have I not done? :slight_smile:

Appreciate any help.

An edit; shining a bright light over the LEDs does make the LED change albeit very faint;
|raw sensor Values | red: 7| green: 6| Blue: 9|
|Mapped sensor Values | red: 1| green: 1| Blue: 2|
|raw sensor Values | red: 7| green: 6| Blue: 8|
|Mapped sensor Values | red: 1| green: 1| Blue: 2|

Thanks
Chris

Hello ardaussie

Welcome to the best Arduino forum ever.

Post your current sketch to see how we can help.

You should show a schematic or a wiring diagram...

And you should show the sketch or program.

//input: phototransistors
const int redSensorPin = A0;
const int greenSensorPin = A1;
const int blueSensorPin = A2;

//output: RGB LED
const int redLEDPin = 11;
const int greenLEDPin = 9;
const int blueLEDPin = 10;

//input values
int redSensorValue = 0;
int greenSensorValue = 0;
int blueSensorValue = 0;

//output values
int redValue = 0;
int greenValue = 0;
int blueValue = 0;

void setup() {
  //serial (monitor)
  Serial.begin(9600);

  //led pins are outputs
  pinMode(redLEDPin, OUTPUT);
  pinMode(greenLEDPin, OUTPUT);
  pinMode(blueLEDPin, OUTPUT);
}

void loop() {
  //read phototransistors
  redSensorValue = analogRead(redSensorPin);
  delay(5);
  greenSensorValue = analogRead(greenSensorPin);
  delay(5);
  blueSensorValue = analogRead(blueSensorPin);

  Serial.print("Raw Sensor Values \t Red: ");
  Serial.print(redSensorValue);
  Serial.print("\t Green: ");
  Serial.print(greenSensorValue);
  Serial.print("\t Blue: ");
  Serial.println(blueSensorValue);

  //0-1023 -> 0-255
  redValue = redSensorValue / 4;
  greenValue = greenSensorValue / 4;
  blueValue = blueSensorValue / 4;

  Serial.print("Mapped Sensor Values \t Red: ");
  Serial.print(redValue);
  Serial.print("\t Green: ");
  Serial.print(greenValue);
  Serial.print("\t Blue: ");
  Serial.println(blueValue);

  //change RGB LED color
  analogWrite(redLEDPin, redValue);
  analogWrite(greenLEDPin, greenValue);
  analogWrite(blueLEDPin, blueValue);
}

I moved your topic to an appropriate forum category @ardaussie.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

@pert No worries. Thanks

Thanks all for your feedback. I persisted and now I have got it working.

I do have a question. Is it possible to display yellow on the LED? RGB(255,255,0)?

Thanks

The beauty of Arduino is that you can easily try that yourself with something like below which will set the colour to (something like) orange.

void setup()
{
  pinMode(redLEDPin, OUTPUT);
  pinMode(greenLEDPin, OUTPUT);
  pinMode(blueLEDPin, OUTPUT);

  digitalWrite(redLEDPin, HIGH);
  digitalWrite(greenLEDPin, HIGH);
}

void loop()
{
}

This is the most simple code to demonstrate. I can not guarantee that the colour is indeed orange but it shows the idea.

To get the color rendering right you would need to match the INTENSITIES of the lights.
Now (depending on the specific LED) green is often much less intense than red or blue.
It also depends on the spectral content of the light from the LEDs.
SO you would need to choose a suitable current for each LED.
The current depends on the source and the forward voltage of the LED.

For simple experimentation if the green DOES look dim compared to the others you could increase the resistor values for the red and blue.

Thanks all for their replies.

Yes. NeoPixels follow HTML colors.