Demonstrates use of an RGB LED (common cathode) by cycling through rainbow colors. Requires RGB LED on pins that support PWM (usually denoted by ~).

Common Cathode RGB LED. (Arduino UNO)

RGB LED connected to pins 6, 5, and 3 for red, green, and blue respectively. The common pin is connected to ground.


Fritzing diagram: led-rgb.fzz


Run this example from the command line with:

node eg/led-rainbow.js
var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {
  var rgb = new five.Led.RGB([6, 5, 3]);
  var index = 0;
  var rainbow = ["FF0000", "FF7F00", "FFFF00", "00FF00", "0000FF", "4B0082", "8F00FF"];

  this.loop(1000, function() {
    if (index === rainbow.length) {
      index = 0;


Component Classes in this example:

Hi! The Johnny-Five community is building new projects every day. We made this newsletter to tell you about what's new, what's good, and what's next for Open Source robotics. Join us in exploring what we can make together.

Fork me on GitHub