DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
Bettesworth Construction
Arduino

Arduino Project 4: Build and Troubleshoot the Color Mixing Lamp

Build the Arduino Starter Kit Color Mixing Lamp with three filtered light sensors and an RGB LED. Includes wiring, code, calibration, staged testing, and troubleshooting.

By Bettesworth Construction Team 8 min read

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Arduino Project 4, the Color Mixing Lamp, uses three light sensors to control the red, green, and blue channels of an RGB LED. Each sensor sits behind a colored filter, the Arduino reads the sensors through analog inputs, and PWM outputs vary the LED’s brightness. The project is a practical introduction to voltage dividers, analog-to-digital conversion, PWM, and additive color mixing.

This guide follows the classic Arduino Uno version from the Arduino Starter Kit Projects Book, while explaining important differences between common-anode and common-cathode LEDs and between photoresistors and phototransistors.

As an Amazon Associate I earn from qualifying purchases.

What the Color Mixing Lamp does

The lamp’s signal chain is straightforward:

  1. Light passes through red, green, or blue transparent gel.
  2. A light sensor produces a changing voltage.
  3. The Arduino measures that voltage on an analog input.
  4. The reading is converted into a PWM brightness value.
  5. The RGB LED combines the three channel intensities into a perceived color.

The result is an educational color mixer, not a calibrated colorimeter. The visible color depends on the LED, sensor response, gel transparency, ambient light, resistor values, sensor spacing, and the way human vision perceives brightness. Arduino describes the project as producing colors with “light as an input,” but real builds will not reproduce every color with equal accuracy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Parts required

  • Arduino Uno or compatible 5 V Arduino board
  • Breadboard and jumper wires
  • One four-lead RGB LED
  • Three light sensors
  • Three 10-kilohm resistors for sensor voltage dividers
  • Three 220-ohm resistors for LED channels
  • Red, green, and blue transparent gels
  • USB cable and the Arduino IDE

The original project materials commonly call the sensors photoresistors. The current Starter Kit product page lists phototransistors instead, so check the contents of your particular kit revision. These sensors are not electrically identical: their response curves, useful resistor values, and reading direction can differ.

#1 Best Overall
3DZWMAN 3-Pack IR RGB LED Lamp Kit 001 for Bambu Lab 3D Printer Light kit
  • 【Compatible with 3D Printing Models】This kit works Compatible with the LED Lamp Kit 001 3D printing model, available for download on the MakerWorld website. Simply search "Lighting Set" or "MH001" to find and print the model. Whether you're a professional 3D creator or a DIY enthusiast, you can then use our lamp kit to build your own unique lighting fixtures.
  • 【Memory & Syncshronization】This LED light kit can automatically remember the last color or mode you used. If you have multiple lights working together, the synchronization feature keeps them perfectly in sync. Especially when using "Flash" or "Smooth" modes, each light changes color at exactly the same rhythm—no more mismatched or out-of-sync effects. Note: A single remote control is all you need to operate all the lights simultaneously. It's incredibly simple to use.
  • 【Material】The aluminum alloy shell offers high strength and rigidity, capable of withstanding significant pressure and bending forces without deforming or breaking. With 5V 4W smart voltage control, it helps keep the housing temperature under control during extended use, making it better compatible with PLA, PETG, and other filaments.
  • 【RGB Remote Control】 The light offers 16 colors to choose from and 4 levels of brightness to adjust. Features Flash, Fade, Smooth, and Strobe modes. It allowing you to create various lighting effects to suit different environments and reflect different moods. At a party, use Strobe/Flash mode with bright colors for an energetic vibe. For a romantic dinner, use Fade mode with warm tones like red or orange — the soft, breathing light effect adds a warm and intimate feel.
  • 【Versatile Use for Any Occasion】Combine 3D-printed models with this kit for holidays (Christmas, Valentine's, birthdays), home decor (mounts on bedroom, desk, bookshelf, cabinet), office, parties, outdoor camping, or as a heartfelt handmade gift – perfect for surprising someone special.

Identify the RGB LED before wiring

A four-lead RGB LED contains three separate emitters with one shared leg. It may be common cathode or common anode; the pinout also varies between LED packages. Use the kit documentation or the component datasheet rather than relying only on leg length.

  • Common cathode: connect the shared leg to ground. A larger PWM value normally makes a channel brighter.
  • Common anode: connect the shared leg to 5 V. The channel logic is inverted, so a lower PWM value normally makes it brighter.

Give each color leg its own current-limiting resistor. Do not use one shared resistor for all three channels if you want independent color control. The published 220-ohm value is part of the starter example, but the LED’s electrical limits and the board’s output limits still apply.

Pin assignments

Function Pin
Green LED channel D9
Red LED channel D10
Blue LED channel D11
Red-filtered sensor A0
Green-filtered sensor A1
Blue-filtered sensor A2

These assignments match the classic Uno example. They are software-defined, so another layout is valid if the constants in the sketch and the physical wiring agree. Pins 9–11 are PWM pins on the classic Uno; verify PWM capabilities before moving the project to another Arduino board.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Wire the sensor voltage dividers

The Arduino does not measure a photoresistor’s or phototransistor’s resistance directly. Each sensor must be paired with a fixed resistor to create a voltage divider.

For each channel:

  1. Connect one sensor terminal to 5 V.
  2. Connect the other sensor terminal to the appropriate analog input.
  3. Connect a 10-kilohm resistor from that analog-input junction to ground.

Build three separate versions of this circuit for A0, A1, and A2. The junction voltage changes as the sensor’s resistance changes. If you put the fixed resistor toward 5 V and the sensor toward ground instead, the reading direction reverses: more light may produce a lower rather than higher analog value.

Rank #2
ELEGOO 3mm & 5mm Clear & Diffused LED Kit, RGB, UV, Fast Flashing, 350pcs
  • 350 PIECES ACROSS TWO SIZES AND SPECIAL EFFECTS - Stock 30 each of 3mm and 5mm white, red, blue, yellow and green LEDs, plus 10 UV, 10 RGB common-anode, 10 RGB common-cathode, 10 fast-flashing RGB and 10 slow-flashing RGB LEDs in a divided organizer
  • CLEAR AND DIFFUSED OPTIONS FOR DIFFERENT LOOKS - Use narrow, bright indicators for control panels or softer light for models, cosplay, school experiments, 3D-printed props and breadboard projects, with both 3mm and 5mm sizes ready for compact or more visible designs
  • EXPLORE UV, RGB AND SELF-FLASHING CIRCUITS - Compare common-anode and common-cathode RGB wiring, create color-mixing lessons or add automatic fast and slow effects without coding every blink; these are conventional through-hole LEDs, not addressable WS2812 or RGB strip pixels
  • PROTECT EVERY LED WITH THE CORRECT RESISTOR - Check polarity, forward voltage and desired current before power is applied, calculate a series resistor for the supply voltage and never connect a bare LED directly to a battery, power rail or controller output without current limiting
  • BARE COMPONENTS FOR LEARNING, PROTOTYPING AND REPAIR - Test each diode before permanent soldering, keep the compartments labeled and verify RGB pin order when leads have been trimmed; resistors, wires, breadboards, controller boards, soldering tools and power supplies are not included

Keep the three sensors physically separated and place the matching red, green, and blue gels in front of them. Shielding each sensor from the lamp’s own light reduces cross-talk and makes the result more stable.

Wire the RGB LED

Connect the red, green, and blue LED legs through separate 220-ohm resistors to D10, D9, and D11 respectively. Connect the common leg to ground for a common-cathode LED or to 5 V for a common-anode LED. Connect the Arduino ground to the breadboard ground rail.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Make sure each LED leg is in a separate breadboard row. A four-lead LED inserted incorrectly can short channels or connect two legs to the same row.

Upload the original Arduino sketch

const int greenLEDPin = 9;
const int redLEDPin   = 10;
const int blueLEDPin  = 11;

const int redSensorPin   = A0;
const int greenSensorPin = A1;
const int blueSensorPin  = A2;

int redValue = 0;
int greenValue = 0;
int blueValue = 0;

int redSensorValue = 0;
int greenSensorValue = 0;
int blueSensorValue = 0;

void setup() {
  Serial.begin(9600);

  pinMode(greenLEDPin, OUTPUT);
  pinMode(redLEDPin, OUTPUT);
  pinMode(blueLEDPin, OUTPUT);
}

void loop() {
  redSensorValue = analogRead(redSensorPin);
  delay(5);

  greenSensorValue = analogRead(greenSensorPin);
  delay(5);

  blueSensorValue = analogRead(blueSensorPin);

  Serial.print("Raw sensor valuestred: ");
  Serial.print(redSensorValue);
  Serial.print("tgreen: ");
  Serial.print(greenSensorValue);
  Serial.print("tblue: ");
  Serial.println(blueSensorValue);

  redValue = redSensorValue / 4;
  greenValue = greenSensorValue / 4;
  blueValue = blueSensorValue / 4;

  Serial.print("Mapped valuestred: ");
  Serial.print(redValue);
  Serial.print("tgreen: ");
  Serial.print(greenValue);
  Serial.print("tblue: ");
  Serial.println(blueValue);

  analogWrite(redLEDPin, redValue);
  analogWrite(greenLEDPin, greenValue);
  analogWrite(blueLEDPin, blueValue);
}

Open the Serial Monitor at 9600 baud. On a classic Uno, analogRead() returns a 10-bit value from 0 to 1023. Dividing by four converts that range to approximately 0–255, the 8-bit range used by the traditional analogWrite() PWM interface. The conversion is appropriate for this example, but it is not a universal rule for every Arduino board.

analogWrite() does not create a continuously variable analog voltage. It switches the pin rapidly and changes the duty cycle. A value of 0 is effectively off, 255 is maximum duty cycle, and intermediate values produce intermediate apparent brightness.

Rank #3
3DZWMAN 1-Pack IR RGB LED Lamp Kit 001 for Bambu Lab MH001 Light Projects
  • 【Compatible with 3D Printing Models】This kit works Compatible with the LED Lamp Kit 001 3D printing model, available for download on the MakerWorld website. Simply search "Lighting Set" or "MH001" to find and print the model. Whether you're a professional 3D creator or a DIY enthusiast, you can then use our lamp kit to build your own unique lighting fixtures.
  • 【Memory & Syncshronization】This LED light kit can automatically remember the last color or mode you used. If you have multiple lights working together, the synchronization feature keeps them perfectly in sync. Especially when using "Flash" or "Smooth" modes, each light changes color at exactly the same rhythm—no more mismatched or out-of-sync effects. Note: A single remote control is all you need to operate all the lights simultaneously. It's incredibly simple to use.
  • 【Material】The aluminum alloy shell offers high strength and rigidity, capable of withstanding significant pressure and bending forces without deforming or breaking. With 5V 4W smart voltage control, it helps keep the housing temperature under control during extended use, making it better compatible with PLA, PETG, and other filaments.
  • 【RGB Remote Control】 The light offers 16 colors to choose from and 4 levels of brightness to adjust. Features Flash, Fade, Smooth, and Strobe modes. It allowing you to create various lighting effects to suit different environments and reflect different moods. At a party, use Strobe/Flash mode with bright colors for an energetic vibe. For a romantic dinner, use Fade mode with warm tones like red or orange — the soft, breathing light effect adds a warm and intimate feel.
  • 【Versatile Use for Any Occasion】Combine 3D-printed models with this kit for holidays (Christmas, Valentine's, birthdays), home decor (mounts on bedroom, desk, bookshelf, cabinet), office, parties, outdoor camping, or as a heartfelt handmade gift – perfect for surprising someone special.

Common-anode LED variant

If your LED is common anode, invert the output values:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
analogWrite(redLEDPin,   255 - redValue);
analogWrite(greenLEDPin, 255 - greenValue);
analogWrite(blueLEDPin,  255 - blueValue);

Some simulations, including the Wokwi Project 4 reproduction, use inverted values. That does not automatically mean the code is faulty; it may represent a common-anode LED or the opposite sensor-divider orientation.

Test the project in stages

Testing the complete circuit immediately makes faults difficult to locate. Use this sequence instead.

  1. Test one LED channel: temporarily upload a sketch that writes a fixed value such as analogWrite(redLEDPin, 150);. Repeat for green and blue.
  2. Test all LED channels: write fixed values to all three outputs and confirm that the colors combine.
  3. Test one sensor: print only the A0 reading while covering and illuminating the red-filtered sensor.
  4. Test all sensors: confirm that A0, A1, and A2 produce changing values.
  5. Run the complete sketch: compare the raw readings with the corresponding LED response.

Improve the result with calibration

The division-by-four sketch is easy to understand, but real sensors often occupy only a narrow part of the 0–1023 range. If a sensor changes only from 420 to 650, direct division produces a limited brightness range. Calibrate each channel’s observed low and high values and map them independently:

int redValue = map(redSensorValue, redSensorLow, redSensorHigh,
                   0, maxBrightness);
redValue = constrain(redValue, 0, 255);

Apply the same approach to green and blue. A brightness ceiling such as maxBrightness = 180 can prevent an overly bright output and leave headroom for balancing. Calibration should take place under useful lighting, with the lamp’s light prevented from contaminating the sensors. A calibration made in one room may not behave the same way elsewhere.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
RGB LED Lamp Kit 001, 3D Printed Model Kit, Remote 15-Color, 3 Pack
  • Seamless Compatibility: Specifically designed for Bambu Lab LED Lamp Kit 001, this 3-piece RGB lighting kit integrates perfectly with your 3D-printed models, ensuring a smooth and hassle-free installation process.
  • Advanced RGB Control: Effortlessly switch between 16 vibrant colors and dynamic RGB gradients using the included remote control or manual switch. Enjoy customizable brightness and speed settings to match any mood or occasion.
  • Premium Build for Optimal Performance: LED Lamp Kit 001 Crafted with high-quality LED light sources and durable aluminum housing, this kit ensures excellent lighting effects. Powered by a 5V 1A USB connection, it works seamlessly with various power sources like chargers, computers, or power banks.
  • DIY Creativity Unleashed: LED Lamp Kit 001 Add a personal touch to your lighting setup by incorporating your own 3D-printed designs. Download free models from MakerWorld and let your creativity shine. (Note:‌ 3D-printed parts must be self-printed by users. Relevant models can be downloaded for free on MakerWorld by searching "LED Light" or "MH001".)
  • Versatile Applications: LED Lamp Kit 001 Perfect for home, office, or outdoor use, this LED Lamp Kit 001 is ideal for cabinets, shelves, desks, and festive decorations. It doubles as a mood lamp or stress-relief device, making it a versatile addition to any space.

You can also average several readings to reduce flicker:

const int samples = 8;
long total = 0;

for (int i = 0; i < samples; i++) {
  total += analogRead(redSensorPin);
}

redSensorValue = total / samples;

Use smoothing after the basic wiring works. It adds stability but also makes the lamp respond more slowly.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting

Symptom Likely causes First check
No light Wrong LED polarity or pinout, missing ground, incorrect PWM pin Test one channel with a fixed PWM value
One color is weak Different LED efficiency, resistor, gel, sensor response, or pin mapping Test that channel alone
Serial values are zero Broken divider, wrong analog pin, missing ground, incorrect resistor Inspect the sensor/fixed-resistor junction
Colors are reversed LED legs, sensor labels, or constants do not match Trace each channel from sensor to LED
Output is inverted Common-anode LED or reversed divider Invert one side only and retest
Flickering colors Noise, loose wiring, poor isolation, changing ambient light Stabilize wiring, shield sensors, then average readings
Compile error Syntax or variable-name typo Check that void loop() { includes parentheses

LED does not light

Confirm that the sketch uploaded, the LED pinout is correct, the common leg is connected to the correct rail, and every color leg has a resistor. Also confirm that the LED legs are not sharing a breadboard row accidentally. If the LED is common anode, use the inverted output formula.

One color is weak

RGB dies do not necessarily have identical forward voltages, efficiencies, or apparent brightness. A gel may also transmit less light, and one sensor may be less sensitive. Equal PWM values therefore do not guarantee equal-looking colors. Balance channels through calibration rather than assuming the LED is defective.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Sensor readings are zero

Check the analog pin, the junction between sensor and resistor, and ground continuity. Do not connect a sensor directly between 5 V and ground without a junction for the Arduino to measure. Confirm the Serial Monitor is set to 9600 baud.

Best Value
Sale
5Pcs Remote Control RGB LED Lamp Kit 001 for Bambu Lab, Multicolor RGB 3D Printer LED Lamp Kit, Adjustable 3D Printed DIY Hardware Model Spare Parts, 5V USB Powered
  • 【Model Compatibility】This RGB light kit is suitable for X1C/P1P/P1S/X1/X1E/H2D LED lighting kit 001 , ensuring a simple and smooth installation process . Note : Printed parts must be printed by the user . Related models can be found by searching for LEDs
  • 【Easy to Switch Light Color】This multi color RGB LED lamp kit features an adjustment function . Users can easily switch RGB colors with a button to achieve monochrome or dynamic color changing effect to suit different environmental backgrounds and ambience
  • 【USB Powered】To ensure optimal lighting performance , we have carefully selected premium 4W COB LED light sources and a robust aluminum alloy housing . The 1 meter/3.28 ft USB power cord is powered by a 5V 1A USB (Type A) interface , which can be connected to a phone/tablet charger , computer USB port , or charger (Type A interfaces are rated for over 1A)
  • 【Easy to Operate】Considering that the USB LED light kit is primarily used in areas close to people , such as bedside tables and desks , we've placed the light switch nearby for easy access
  • 【Wide Range of Application】This RGB LED night lamp kit is suitable for home environments such as kitchens , cabinets , display cases , bedrooms , desks , and bookshelves , and also suitable for public spaces like university dormitories , offices , and party venues

The LED changes in the wrong direction

Reverse the sensor divider or invert the PWM output, depending on which part is responsible. Change one thing at a time; reversing both can hide the original fault.

The sensors change but the color does not

Verify that the mapped values change, that the LED channel constants match the physical legs, and that resistor leads are not touching. Keep the lamp’s light away from the sensors. Cross-talk and accidental shorts are common breadboard causes.

Typical code errors

The declaration must be:

void loop() {

Writing void loop{ causes a compilation error because the function declaration is missing parentheses. Also check that names such as redSensorValue are spelled consistently throughout the sketch.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Physical build versus simulation

The Wokwi reproduction is useful for inspecting the sketch and experimenting without assembling every component. It cannot reproduce the full behavior of real gels, ambient light, sensor placement, LED spectral output, or breadboard faults, so a successful simulation does not prove that physical wiring is correct.

Is the Starter Kit worth buying?

The official Arduino Starter Kit Multi-Language is the most direct option for an absolute beginner who needs the Uno, breadboard, Projects Book, RGB LED, sensors, gels, and resistors together. The listed price was €117 including VAT when observed in August 2026; regional tax, currency, stock, and localization can change the amount.

If you already own an Arduino, breadboard, jumper wires, RGB LED, sensors, and resistors, buying the complete kit is usually unnecessary. Buy compatible individual components instead, and confirm the sensor and LED specifications. Arduino also references a Starter Kit R4 with an Uno R4 WiFi and newer projects; do not assume its exact parts, book, pin behavior, or project sequence are identical to the classic kit.

Important limitations

  • The project is not a calibrated color measurement system.
  • Photoresistors and phototransistors may need different calibration and resistor values.
  • Equal PWM numbers can produce unequal-looking brightness.
  • Ambient light and the lamp’s own light can alter readings.
  • ADC resolution, voltage levels, PWM behavior, and pin assignments vary across Arduino boards.
  • The published 220-ohm resistors are an example component choice, not a substitute for checking LED and board limits.

Once the basic lamp works, the same analog-input and PWM techniques can drive a dimmer, indicator panel, automatic night light, or manually controlled RGB fixture.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

More from the Site Office

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.