Introduction: RGB Flashers With Shift Register

Picture of RGB Flashers With Shift Register

A shift register is a cascade of flip flops, sharing the same clock, in which the output of each flip-flop is connected to the 'data' input of the next flip-flop in the chain, resulting in a circuit that shifts by one position the 'bit array' stored in it, 'shifting in' the data present at its input and 'shifting out' the last bit in the array, at each transition of the clock input.

This allows us to shift through multiple colours of the an RGB LED by connecting it to different pins in the Shift register. Since an RGB LED is composed of three individual LEDs with 3 pins for each of these LEDs, though in one package, we are able to flash all the different colours with a shift register and cycle through all of these colours. By extension we can connect up to 3 RGB LEDs to one shift register, although on of the colour LEDs on the 3rd RGB LED will not be able to light up.

To make it more colourful and christmassy, I decided to add some extra LEDs in the demo circuit, just for fun!

Step 1: Tools and Materials

Picture of Tools and Materials
  • Arduino 101 or Arduino Uno
  • Shift register
  • Breadboard
  • 3 pieces of 100Ω resistor
  • Jumper Wires

Step 2: Circuitry

Picture of Circuitry

Connect the Arduino Power to the breadboard power rails

  1. Connect the 3.3V pin from the Arduino to the red breadboard power rail using a red jumper wire.
  2. Connect the ground pin from he Arduino to the black bread board pose rail using a black jumper wire.

Wire the Shift Register to the Arduino.

  1. Place the shift register on the breadboard with the top notch facing the top, this will indicate where pin 1 is, which is the one to the left of the notch, by convention. This is a universal property among all ICs and is a good thing to remember.
  2. Connect pin 10 and 16 on the shift register to the 3.3V power rail.
  3. Connect pin 8 and pin 13 on the shift register to the ground rail of the breadboard.
  4. Connect pin 11, 12 and 14 from the shift register to pins 2, 3, and 4 to the breadboard, respectively.

Lastly, connect the RGB LED to the Shift Register

  1. Connect the longest pin of the RGB LED to the common ground.
  2. Connect pin 15 to a 100Ω resistor then in series with the Red LED of the RGB LED, which is the one closest to the ground pin but is not in the middle.
  3. Connect the remaining middle pin, this is also the Green LED pin, to pin 1 of the Shift Register.
  4. Now, connect the only unconnected pin, which you know to be the Blue LED pin, to pin 2 of the Shift Register.

Step 3: Code

Picture of Code

We cannot turn on and keep each individual pins turned to high with an RGB LED, since this will simply keep all LEDs high and produce white after one cycle, which is not going to look nice and pretty, so instead, we have to all each pin to be HIGH then wait, finally LOW, so as to cycle through all the colours through to infinity.

int datapin = 2;
int clockpin = 3; int latchpin = 4;

// We'll also declare a global variable for the data we're // sending to the shift register:

byte data = 0;

void setup() { // Set the three SPI pins to be outputs:

pinMode(datapin, OUTPUT); pinMode(clockpin, OUTPUT); pinMode(latchpin, OUTPUT); }

void loop() {

oneAfterAnother(); // All on, all off


void shiftWrite(int desiredPin, boolean desiredState)

{ // First we'll alter the global variable "data," changing the // desired bit to 1 or 0:


// Now we'll actually send that data to the shift register. // The shiftOut() function does all the hard work of // manipulating the data and clock pins to move the data // into the shift register:

shiftOut(datapin, clockpin, MSBFIRST, data);

// Once the data is in the shift register, we still need to // make it appear at the outputs. We'll toggle the state of // the latchPin, which will signal the shift register to "latch" // the data to the outputs. (Latch activates on the high-to // -low transition).

digitalWrite(latchpin, HIGH); digitalWrite(latchpin, LOW); }

void oneAfterAnother() { int index; int delayTime = 100; // Time (milliseconds) to pause between LEDs // Make this smaller for faster switching

// Turn all the LEDs on:

// This for() loop will step index from 0 to 7 // (putting "++" after a variable means add one to it) // and will then use digitalWrite() to turn that LED on.

for(index = 0; index <= 7; index++) { shiftWrite(index, HIGH); delay(delayTime); }

// Turn all the LEDs off:

// This for() loop will step index from 7 to 0 // (putting "--" after a variable means subtract one from it) // and will then use digitalWrite() to turn that LED off.

for(index = 7; index >= 0; index--) { shiftWrite(index, LOW); delay(delayTime); } }

Step 4: Demo

Focus on the first LED, since that is the RGB one. As the shift register, shifts per cycle, the colour LED changes. The timing is rather fast, the way I programmed it, but it is still visible to the human eye.


About This Instructable




Bio: Aerospace Engineer working in Software Development with a passion for Hardware.
More by TechMartian:Flying Captain America's Shield - RC PlaneWide Angle ShotsLED Ping Pong With Shift Register
Add instructable to: