Adventures with an Arduino: RGB LED (part 1)

For both the Arduino projects, the mind machine and the pulse oximeter (heart rate monitor), a light source will be required. The heart monitor could use IR, well it will use it in addition to visible light, but ignore that for a minute. The mind machine will use LED lights for the googles to create something similar to the Ganzfeld effect, the heart rate monitor will use it to measure transmittance or reflectance through a finger.

So whats the big deal, can’t you just hook up an LED? Well yes, I could just use a superbright red LED, or other colour. What I would like to do is to experiment with different colours for both projects. For all I know pink or purple light may work better than another. So I will use a RGB LED to do this. Now I could use RGB LEDs and drive them from the PWM output, or for less combinations from the digital pins. Those methods use a lot of pins and will require some additional coding.

I opted for a digitally controlled LED from SKPANG. This has a WS2801 IC on it that you connect to a single digital line. These can be daisy chained as well so one line on the Arduino can control several LEDs. Each LED has three channels as you would expect on an RGB LED with each colour having one of 256 values.

So taking things one at a time, I first want to connect one of these breakout boards up (see diagram below). It is fairly simple, power as normal and a serial line (digital pin 2) and clock (digital pin 3).

Arduino controlling a single WS2801 LED
Arduino controlling a single WS2801 LED

You will need the Adafruit WS2801 library from Github. The code is fairly simple (see below). It shows red for 1 second, then green and then blue.

#include <adafruit_ws2801.h>
#include <wire.h>
#include "SPI.h"
int dataPin  = 2;    // Yellow wire on Adafruit Pixels
int clockPin = 3;    // Green wire on Adafruit Pixels
Adafruit_WS2801 strip = Adafruit_WS2801(1, dataPin, clockPin);
void setup() {
  // Update LED contents, to start they are all 'off';
void loop() {
  //Show Red
  //Show Green
  //Show Blue
// Create a 24 bit color value from R,G,B
uint32_t Color(byte r, byte g, byte b)
  uint32_t c;
  c = r;
  c <<= 8;
  c |= g;
  c <<= 8;
  c |= b;
  return c;

Code for the projects is available on Github. Look at the project (mind machine or pulse oximeter) and then under the WS2801_ONE_LED folder.

Okay so it is nothing fancy but as I said in previous posts I want to go nice and slow and document everything. So that is one LED. Will post later on adding a second LED.