MyRoboPathOpen Robotics Lab
Arduino Uno #11 of 35
Est. 0.5 Hours
Budget: $1 - $3
Beginner

KY-016 RGB LED 3-Channel PWM Color Mixer

Blend millions of additive RGB hues using three independent hardware PWM channels on Arduino Uno.

Master additive color mixing with the KY-016 common-cathode RGB LED module (or discrete 4-leg RGB LED). Drive Red, Green, and Blue dies independently using 8-bit PWM on pins D9, D10, and D11 to synthesize custom colors, breathing fades, and interactive presets.

Arduino Uno R3KY-016 RGB LED3-Channel PWMAdditive Color MixinganalogWrite()
KY-016 RGB LED 3-Channel PWM Color Mixer Blueprint
KY-016 RGB LED 3-Channel PWM Color MixerCAD Blueprint

Key Learning Objectives & Robotics Concepts

By building and programming this project, you will master the following core engineering skills:

1Differentiate Common Cathode (shared GND, active-HIGH) from Common Anode (shared 5V, active-LOW) RGB LEDs.
2Use hardware PWM pins (~D9, ~D10, ~D11) to modulate perceived brightness linearly.
3Combine primary channels (R+G=Yellow, G+B=Cyan, R+B=Magenta, R+G+B=White) via additive optics.
4Build reusable setRgbColor(r, g, b) helper functions with smooth cross-fading.

Power Architecture & Voltage Staging

5V / 3.3V Regulated Power

Each RGB channel draws ~12–15mA at 255 PWM duty cycle (~45mA combined at full white), safely powered directly by Arduino Uno GPIO pins through per-channel current-limiting resistors. KY-016 includes onboard 150Ω SMD resistors; discrete 4-pin RGB LEDs require three separate 220Ω resistors (one per color leg).

KY-016 RGB LED 3-Channel PWM Color Mixer Power Architecture Schematic
Figure: Regulated Arduino Uno supply rails, current budget, and component protection.Power Schematic

Bill of Materials (BOM) & Hardware Components

Bill of Materials for KY-016 RGB LED 3-Channel PWM Color Mixer
ComponentSpecifications & AlternativeQtyApprox Cost
Arduino Uno R3ATmega328P with 6 hardware PWM channels1$8.00
KY-016 RGB LED Module (or 4-Pin RGB LED)Common-cathode 5mm tri-color LED1$1.00
220Ω Resistors (×3 for bare LED)Only needed if using bare 4-pin RGB LED3$0.15
Breadboard & Jumper Wires4× color-coded jumpers1$2.00

Electrical & System Architecture

Connect KY-016 GND (-) to Arduino GND, R to D9 (~), G to D10 (~), and B to D11 (~). If using a discrete 4-pin RGB LED, place a 220Ω resistor in series with each of R, G, and B.

Figure: Complete Arduino Uno R3 pin-to-pin wiring schematic for KY-016 RGB LED 3-Channel PWM Color Mixer.
Figure: Complete Arduino Uno R3 pin-to-pin wiring schematic for KY-016 RGB LED 3-Channel PWM Color Mixer.Wiring Schematic

Autonomous Behavior & Finite State Machine (FSM)

Deterministic Arduino loop handling KY-016 Common-Cathode RGB LED Module acquisition, filtering, and real-time output updates.

Figure: Firmware execution flow and state transitions for KY-016 RGB LED 3-Channel PWM Color Mixer.
Figure: Firmware execution flow and state transitions for KY-016 RGB LED 3-Channel PWM Color Mixer.Control Algorithm

Step-by-Step Physical Assembly & Wiring Tutorial

Follow each of the 5 sequential milestone stages with technical photos, wiring checks, and pre-flight tests.

1

Check Common-Cathode vs. Common-Anode Type

Duration: 5 Mins

KY-016 modules are common-cathode (pin marked "-" connects to GND).

KY-016 RGB LED 3-Channel PWM Color Mixer hardware layout diagram
Stage 1: KY-016 Common-Cathode RGB LED Module hardware inspection & pinout overview.Stage 1 Diagram
Step Action Checklist:
  • Inspect the 4 pins on KY-016: R, G, B, and - (GND).
  • For a bare 4-leg RGB LED, the longest pin is the common cathode (or common anode).
  • Never share a single resistor on the common pin—each color needs its own resistor due to differing forward voltages.
Engineering & Tuning Tip: Red dies have ~2.0V Vf while Blue/Green have ~3.1V Vf—dedicated resistors prevent Red from hogging all current!
2

Wire R, G, B to PWM Pins D9, D10, D11

Duration: 5 Mins

Connect each color pin to a tilde (~) PWM pin on the Arduino Uno.

KY-016 RGB LED 3-Channel PWM Color Mixer breadboard wiring check diagram
Stage 2: Breadboard layout & Arduino Uno pin-to-pin wiring audit.Stage 2 Diagram
Step Action Checklist:
  • Connect KY-016 "-" to Arduino GND.
  • Connect R → D9, G → D10, and B → D11.
  • Add 220Ω resistors in series with R, G, and B if using a bare 4-leg LED.
Engineering & Tuning Tip: Avoid mixing tone() with D11 or Servo.h with D9/D10; use D3/D5/D6 instead if adding servos later.
3

Verify Individual Primary Channels

Duration: 5 Mins

Upload the channel test diagnostic to ensure Red, Green, and Blue map accurately.

KY-016 RGB LED 3-Channel PWM Color Mixer power rail protection diagram
Stage 3: Supply rail check (USB 5.0V Regulated Rail (≈35–45mA max)) and circuit protection verification.Stage 3 Diagram
Step Action Checklist:
  • Flash the diagnostic check below.
  • Confirm the LED illuminates pure Red, then pure Green, then pure Blue.
  • Swap any mismatched pin labels if your KY-016 silkscreen differs.
Engineering & Tuning Tip: Place a translucent ping-pong ball or tissue paper over clear-lens RGB LEDs to blend the three dies smoothly.
4

Upload Smooth PWM Color Cross-Fader

Duration: 10 Mins

Flash the additive mixer sketch to step through named colors and continuous spectrum transitions.

KY-016 RGB LED 3-Channel PWM Color Mixer serial telemetry verification diagram
Stage 4: Firmware upload & 115200 baud Serial Monitor verification.Stage 4 Diagram
Step Action Checklist:
  • Upload the production sketch below.
  • Open Serial Monitor at 115200 baud to observe active RGB tuples.
  • Watch seamless transitions across Red → Yellow → Green → Cyan → Blue → Magenta.
Engineering & Tuning Tip: If you have a Common-Anode LED, simply flip COMMON_ANODE = true at the top of the sketch!
5

Calibrate Pure White Balance

Duration: 5 Mins

Red often overpowers Green/Blue visually; test reduced Red weighting (e.g., 180, 255, 220) for neutral white.

KY-016 RGB LED 3-Channel PWM Color Mixer live operational logic diagram
Stage 5: Live operational logic flow & calibration verification.Stage 5 Diagram
Step Action Checklist:
  • Observe raw (255, 255, 255) color tint through a diffuser.
  • Reduce the dominant channel by 20–30% to achieve crisp neutral white.
  • Record your calibrated RGB values for future status lamps.
Engineering & Tuning Tip: PWM runs at 490Hz on D9/D10/D11—completely flicker-free to the human eye.

Subsystem Benchtop Verification Scripts

Test each hardware subsystem independently before deploying the full autonomous firmware.

1Bench Diagnostic: KY-016 Common-Cathode RGB LED Module Hardware Check

Subsystem Diagnostic

Minimal standalone sketch to verify pin wiring and signal response for KY-016 Common-Cathode RGB LED Module before running the full project firmware.

Arduino IDE Diagnostic ScriptC++ / Arduino
// Diagnostic: Verify R(D9), G(D10), B(D11) Pin Mapping
void setup() { pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT); }
void loop() {
  analogWrite(9, 180); analogWrite(10, 0); analogWrite(11, 0); delay(700);
  analogWrite(9, 0); analogWrite(10, 180); analogWrite(11, 0); delay(700);
  analogWrite(9, 0); analogWrite(10, 0); analogWrite(11, 180); delay(700);
}
Expected Output: Cycles pure Red → pure Green → pure Blue every 700ms.

Complete Production Firmware

Full working C++ source code with pin mappings, non-blocking timers, and FSM avoidance routines.

arduino_uno_ky016_rgb_led_pwm_mixer.ino
arduino_uno_ky016_rgb_led_pwm_mixer.inoArduino C++
/**
 * Project 11: KY-016 3-Channel PWM RGB Color Mixer
 * Board: Arduino Uno R3 | Pins: R=D9, G=D10, B=D11
 */
const uint8_t PIN_R = 9;
const uint8_t PIN_G = 10;
const uint8_t PIN_B = 11;
const bool COMMON_ANODE = false; // Set true for common-anode RGB LEDs

void setColor(uint8_t r, uint8_t g, uint8_t b) {
  analogWrite(PIN_R, COMMON_ANODE ? 255 - r : r);
  analogWrite(PIN_G, COMMON_ANODE ? 255 - g : g);
  analogWrite(PIN_B, COMMON_ANODE ? 255 - b : b);
}

void crossFade(uint8_t r1, uint8_t g1, uint8_t b1, uint8_t r2, uint8_t g2, uint8_t b2, uint16_t steps, uint8_t waitMs) {
  for (uint16_t i = 0; i <= steps; i++) {
    uint8_t r = r1 + ((int)(r2 - r1) * i) / steps;
    uint8_t g = g1 + ((int)(g2 - g1) * i) / steps;
    uint8_t b = b1 + ((int)(b2 - b1) * i) / steps;
    setColor(r, g, b);
    delay(waitMs);
  }
}

void setup() {
  pinMode(PIN_R, OUTPUT);
  pinMode(PIN_G, OUTPUT);
  pinMode(PIN_B, OUTPUT);
  Serial.begin(115200);
  Serial.println(F("KY-016 PWM RGB Color Mixer Ready"));
}

void loop() {
  Serial.println(F("Fade: Red -> Amber -> Green"));
  crossFade(255, 0, 0, 0, 255, 0, 100, 15);
  Serial.println(F("Fade: Green -> Cyan -> Blue"));
  crossFade(0, 255, 0, 0, 0, 255, 100, 15);
  Serial.println(F("Fade: Blue -> Magenta -> Red"));
  crossFade(0, 0, 255, 255, 0, 0, 100, 15);
}

Firmware Architecture Explanation:

  • Provides a single COMMON_ANODE boolean flag to support both KY-016 common-cathode and common-anode parts.
  • Linearly interpolates all three 8-bit PWM channels smoothly over 100 steps per spectrum edge.
  • Uses pure hardware PWM on D9/D10/D11 for zero visual flicker.

Operational Verification & Pin State Matrix

1Double-check all 4 Arduino Uno pin connections against the wiring schematic before plugging in USB.
2Upload the Bench Diagnostic sketch first and confirm Serial Monitor at 115200 baud matches: Cycles pure Red → pure Green → pure Blue every 700ms.
3Upload the complete production sketch and verify every condition in the operational truth table below.

Input Signal vs. System Output Truth Table:

Operational truth table for KY-016 RGB LED 3-Channel PWM Color Mixer
Input / StatePin / SignalDetected ConditionExpected Output
R=255, G=255, B=0D9+D10 HIGHRed + Green MixEmit Bright Yellow
R=0, G=255, B=255D10+D11 HIGHGreen + Blue MixEmit Electric Cyan
R=255, G=0, B=255D9+D11 HIGHRed + Blue MixEmit Vivid Magenta

Engineering Troubleshooting Matrix

Engineering troubleshooting matrix for KY-016 RGB LED 3-Channel PWM Color Mixer
ProblemLikely CauseDiagnostic CheckEngineering Solution
Colors look inverted (0 is full bright, 255 is off)Common-Anode RGB LED wired to 5V instead of Common-CathodeVerify whether common pin goes to 5V or GNDSet COMMON_ANODE = true in the sketch.
Only Red lights when mixing Red + BlueSingle shared resistor on common cathode pinCheck resistor placement on breadboardGive R, G, and B each their own separate 220Ω resistor.
One color channel stays darkLoose jumper or non-PWM pin assignmentRun primary channel diagnosticConfirm wires land on D9, D10, and D11.

Engineering Challenges & Upgrades

Take your build to the next level with these progressive engineering upgrades:

Level 13-Button Interactive Color Selector

Wire 3 push buttons on D2/D3/D4 to step Red, Green, and Blue brightness independently.

Level 2Serial Hex Color Picker

Parse hex codes like #00FF88 from Serial Monitor and display them live.

Level 3Ambient Mood Auto-Dimmer

Scale overall RGB brightness automatically using an LDR light sensor (Project 13).