HSB RGB Arduino Color Library

Views: 13392 Difficulty: 2 Status: Complete

Here is another arduino library to handle Hue, Saturation, and Brightness as well as Red, Green, and Blue color models.

Screens speak of color in terms of 3 channels: Red, Green and Blue. Humans tend to think of colors in 3 channels too, but the channels that seem more natural usually are Hue, Saturation and Brightness. Here is an arduino color library so you too can specify colors by their hue! We use this code in our RGB Rainbow Sun and HSB RGB Sketcher. If you need help learning how to install libraries in arduino check out this thorough Adafruit tutorial. We use this library to draw colors on LCD screens, for example see the HSB RGB Sketcher Tutorial and onto RGB LEDs in the Sun Kit.

Arduino Color Icon

Color Icon!

Color Wheel on LEO Gamer

Here we are using the Arduino color code to display a color wheel on the LEO Gamer.

Color Code Example

This code show a basic example of using the color library to make a rainbow appear on RGB LEDs. By varying the hue the rainbow function moves across the whole visible color spectrum.
/* LucidTronix Arduino HSB RGB Color library 
 * Control rgb color by specifying
 * Hue saturation and brightness.
 * This code shows a rainbow

#include <color.h>
// these are the pins connected to
// the RGB LEDs.  They must be PWM capable
int leds[] = {5,6,9}; 
Color cur_color = Color(1,1,1);
float hue = 0;
void setup()  // run once, when the sketch starts                  
  for(int i = 0 ; i < 3; i++ ){
    pinMode(leds[i], OUTPUT); 

void loop() // run over and over again                   

void rainbow(){
  hue += 0.06;
  if ( hue >=1 ) hue = 0;
  float sat = 1.0;
  float val = 0.4;

void display_color(Color c){

Download the Color Library from Github

Grab the latest code here! Download and unizp into your Arduino libraries folder.
An arduino library for the MMA8453 Triple Axis Accelerometer...
Think of it like a shift register for Pulse Width Modulation (PWM)....
Light sensors guids this robot towards the light....
Rainbow flower necklace using the TLC5940....
Control a 120v outlet with a 5V arduino....
How to upload code to an Arduino Leonardo clone....
Standalone programmable Heart-Shaped LED display....
This PCB controls a camera and an SD card so you can make automatic time lapse videos. ...