HSB RGB Arduino Color Library

Views: 32703 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 HSB RGB Color Library
 * For instructions, details and schematic, See:

#include <Color.h>

// these are the pins connected to the RGB LEDs
int leds[] = {9,10,11}; 
Color cur_color = Color(1,1,1);
float hue = 0;

// run once, when the sketch starts
void setup()                    
  for(int i = 0 ; i < 3; i++ ){
    pinMode(leds[i], OUTPUT);
    digitalWrite(leds[i], LOW);
    digitalWrite(leds[i], HIGH);

// run over and over again
void loop()                   

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

void display_color(Color c){

Download the Color Library from Github

Grab the latest code here! Download and unizp into your Arduino libraries folder.
A library to interface Arduino code with the 3 Axis L3G4200D gyroscope....
An arduino library for the MMA8453 Triple Axis Accelerometer...
Control the hue, value and saturation on this pocket-sized joystick drawing machine....
A wearable real-time clock with vibrant color display....
Coupling the HMC5883L Compass with our color library turns the Wearable Wayfinder into a handy naviga...
Think of it like a shift register for Pulse Width Modulation (PWM)....
The Wearable Wayfinder is a totally programmable, beautiful little computer for your wrist packed wit...
Control a 120v outlet with a 5V arduino....