Introduction: LED Waterfall With a Shift Register and Arduino

Picture of LED Waterfall With a Shift Register and Arduino

This is the fourteenth module in a series of lessons about the use of the Arduino, which will focus on the use of shift registers.

There are very limited pins on an Arduino, so in order to save up on the uses of pins, Shift registers are used to control 8 digital signals, but only using 3 pins -- a data pin, clock pin, and latch pin. In this project he shift registers will be used to drive 8 different coloured LEDs to make a waterfall, falling effect.

Step 1: Tools and Materials

Picture of Tools and Materials
  • Arduino 101 or Arduino Uno
  • 8 LEDs of different colours
  • 8 pieces of 100Ω resistors
  • Shift Register - SN74HC595
  • Jumper Wires

Step 2: Circuitry

Picture of Circuitry

Connect the Arduino Power to the breadboard power rails

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

Wiring the shift register.

  • Place the shift register on the breadboard with the top notch facing the top, this will indicate where pin one is
  • Connect pin 10 and 16 on the shift register to the 3.3V power rail.
  • Connect pin 8 and pin 13 on the shift register to the ground rail of the breadboard.
  • Connect pin 11, 12 and 14 from the shift register to pins 2, 3, and 4 to the breadboard, respectively.

Connecting the LEDs to the Shift Register and Arduino

  • Connect pin 15 to a 100Ω resistor then in series with an LED to ground. It may be easier to connect it to ground on the other rail of the breadboard, so simply connect this ground to the other ground rail of the breadboard.
  • Connect pins 1 to 7 from the shift register to a 100Ω resistor in series to an LED to ground.

Step 3: Code

Picture of Code

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:

bitWrite(data,desiredPin,desiredState);

// 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

The LED's will turn ON, then OFF, in sequence from the top to the bottom like a waterfall.

Comments

About This Instructable

530views

16favorites

License:

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: