ExoSynkLab

exosynk/rgb-color-fader

exosynk/rgb-color-fader

RGB color fader (Arduino PWM)

Arduino drives a common-cathode RGB LED through three 330Ω resistors. Code cycles R, G, B via analogWrite — classic PWM color mixing.

0 views0 upvotes0 forks6 partsUpdated Apr 19, 2026, 6:30 PMCreated Apr 19, 2026

README

RGB color fader

Three PWM pins → three 330Ω resistors → three anodes of an RGB LED → common cathode → ground. That's it.

What you see

Press ▶ Simulate. The LED walks the hue wheel — red, yellow, green, cyan, blue, magenta, back to red. One full loop is about 7.7 seconds.

The trick: PWM

Arduino's analogWrite(pin, 0-255) doesn't actually output an analog voltage — it outputs a square wave that's on for n/255 of the time. The LED flickers faster than your eye can see, and you perceive the average brightness.

  • analogWrite(pin, 255) → 100% on, full brightness
  • analogWrite(pin, 128) → 50% duty, half brightness
  • analogWrite(pin, 0) → off

Mix three channels and you get 256³ ≈ 16.7 million colors, same as any monitor.

Try this

  • Change each 255 to 64. LED gets much dimmer but the cycle still runs.
  • Change delay(5) to delay(50). Cycle slows 10×.
  • Hardcode analogWrite(11, 200); analogWrite(10, 40); analogWrite(9, 150); inside setup() and remove the loop body. You've just picked a single color and held it — purple-ish.

The resistor values

With Arduino at 5 V and the R-channel Vf ≈ 1.8 V: I = (5 - 1.8) / 330 ≈ 9.7 mA. Comfortably under the 20 mA max. Each color has a different Vf so the three channels brighten at slightly different rates — that's normal for RGB LEDs and the eye adjusts.

0 comments

No comments yet. Be the first.
Sign in to leave a comment.