Arduino Color Mixing Lamp (Starter Kit Project #4)

This entire thing is fairly simple. We will use phototransistors to input the RGB components of any light source to our arduino. The arduino will then convert these to digital values, and combine the RGB components to operate a four pin, RGB LED. All we have to do is input to our uno, process the data (fancy word for dividing by 4), and output.


Here’s what we’ll need:

  • Arduino UNO
  • Breadboard
  • 3 220 Ω resistors, 3 10 kΩ resistors.
  • Jumper wires/cables
  • 4 pin RGB LED
  • RGB color filters
  • 3 phototransistors


Here’s what the circuit should look like (from the arduino starter kit projects book).

And here is my build:

You can see that I didn’t use the wooden components already in the starter kit to appropriately connect the filters to the phototransistors. This is because those components were too small (probably a defect in the kit), fitting the screens caused them to fly across the room at random intervals.


You can find the full code here. I’m not discussing the setup part here.

void loop() {
    redSensVal = analogRead(redSensPin);
    greenSensVal = analogRead(greenSensPin);
    blueSensVal = analogRead(blueSensPin);

Here we’re reading in the rgb components of the light source under scrutiny. A delay of five milliseconds has been taken as the arduino takes a while to process analogue inputs and convert them into digital values.

void loop() {
    // ...
    redVal = redSensVal/4;
    greenVal = greenSensVal/4;
    blueVal = blueSensVal/4;

    analogWrite(redLEDPin, redVal);
    analogWrite(blueLEDPin, blueVal);
    analogWrite(greenLEDPin, greenVal);

Now we divide by four because our analogue input corresponds to digital values between 0 and 1023. However, our output LED requires digital values between 0 and 255. Given that our output LED requires analogue inputs, we use the UNO’s built in DAC to display our combined RGB components.


Many people (including me) initially thought that this entire thing wasn’t working. This isn’t the case. The fact is that the phototransistors that come with the starter kit are incredibly insensitive. They registers values of o,0,0 for room lights (and most lights), which is why there is no discernible output unless one uses a strong flashlight (built-in in smartphones) or a decent light source.

Here’s a small demo. You can visibly see that iphone flashlights have strong blue and green components.



%d bloggers like this: