The RGB LED Sidequest šŸ’”

Published: (January 5, 2026 at 06:00 PM EST)
4 min read
Source: Dev.to

Source: Dev.to

Jennifer Davis

Welcome back to my journey From Dust to Droid Dreams

While the primary path to building a droid is a long‑term mission, sometimes you have to take a side‑quest to master the fundamentals of the ā€œnervous system.ā€
Today’s mission: Multi‑LED color blending and the hidden traps of Serial debugging.

I discovered that I had an RGB LED and decided to rewire the existing Red, Blue, and Green LEDs while keeping the Yellow LED as‑is. The goal was to create a smooth transition between Red, Green, and Blue using Pulse‑Width Modulation (PWM), with a dedicated Yellow LED that glows based on the overlap of the Red and Green channels.

The ā€œFiddlyā€ Hardware

First lesson of the side‑quest: The physical world is messy.
The RGB LED setup is super fiddly—wires cross over easily, and it requires very careful application of resistors to keep the signals clean and the components safe.

LED surrounded by jumper wires and resistors

Encountering the ā€œLagā€ Monster

Once I got the LEDs in sync, I wanted to monitor the values changing in real time. This did not work the way I expected. Suddenly, the synchronization disappeared—the Yellow LED started stuttering and wouldn’t come on at the right time.

Problematic Code

void updateLEDs() {
  analogWrite(RED, redValue);
  analogWrite(GREEN, greenValue);
  analogWrite(BLUE, blueValue);

  // Serial output inside the main update loop
  Serial.print("R: "); Serial.print(redValue);
  Serial.print(" | G: "); Serial.print(greenValue);
  Serial.print(" | B: "); Serial.print(blueValue);
  Serial.print(" | Y-LED: "); Serial.print(yellowBright);
  // ... this was slowing everything down!
}

At the default 9600 baud, Serial communication is relatively slow. Every time the code reaches these print statements, it pauses the loop to send data. This creates a ā€œhiccupā€ in the PWM signal, making the LEDs flicker and the timing feel ā€œoff.ā€

The Optimization Fix

To resolve the lag and reclaim that smooth fade, I applied two key fixes:

  1. Baud‑Rate Boost – increased the speed from 9600 to 115200 (updated in both the code and the IDE configuration).
  2. Timed Printing (Non‑blocking) – instead of printing every single loop, I used a timer (millis()) to update the Serial output every 100 ms. This keeps the processor focused on the LED pulses.
void updateLEDs() {
  analogWrite(RED, redValue);
  analogWrite(GREEN, greenValue);
  analogWrite(BLUE, blueValue);

  int yellowBright = (redValue  100) {
    Serial.print("R:"); Serial.print(redValue);
    Serial.print(" G:"); Serial.print(greenValue);
    Serial.print(" B:"); Serial.print(blueValue);
    // Added a small offset (+5) so the yellow line is visible on the plotter
    Serial.print(" Y-LED:"); Serial.println(yellowBright + 5);
    lastPrintTime = millis();
  }
}

New Tool Use Unlocked: The Serial Plotter

I also spent some time with the Arduino IDE’s Serial Plotter (Tools > Serial Plotter). It’s a fantastic tool for visualizing how the color variables oscillate in waves.

Yellow LED blip on the Serial Plotter graph

I had to iterate a few times to get the Yellow line to show up properly. Because the values were identical to the Red or Green lines, they were hidden behind them. Adding a small offset (+5) to the print statement finally made the Yellow line visible!

Yellow LED now visible on the Serial Plotter graph

A minor mystery: I haven’t figured out how to get the line colors in the Plotter to actually match the RGB colors I’m outputting. The IDE seems to assign them automatically based on the order of the variables. If anyone has a hack for this, please let me know in the comments! Even without matching colors, seeing the waves overlap in real‑time is a huge help for debugging the logic.

Key Takeaways for the Droid Build

  • Communication Overhead: Consider how much ā€œtalkingā€ your microcontroller is doing—it might be slowing down its ā€œthinking.ā€
  • Visualization over Text: Data is much easier to digest as a wave than as a wall of scrolling numbers.
  • Timing: (continue your notes here…)

Everything

Don’t just default to delay(). millis() allows for multi‑tasking, whereas delay() essentially puts the Arduino Uno to sleep.

Happy building, and may your LEDs always blend smoothly!

Back to Blog

Related posts

Read more Ā»

Rapg: TUI-based Secret Manager

We've all been there. You join a new project, and the first thing you hear is: > 'Check the pinned message in Slack for the .env file.' Or you have several .env...

Technology is an Enabler, not a Saviour

Why clarity of thinking matters more than the tools you use Technology is often treated as a magic switch—flip it on, and everything improves. New software, pl...