LED Waterfall With a Shift Register and Arduino
by TechMartian in Circuits > Arduino
3583 Views, 17 Favorites, 0 Comments
LED Waterfall With a Shift Register and Arduino
![7kGeoMsXRoiR3idKs0i3BA_thumb_226.jpg](/proxy/?url=https://content.instructables.com/FKQ/XENW/J52Q8RQ2/FKQXENWJ52Q8RQ2.jpg&filename=7kGeoMsXRoiR3idKs0i3BA_thumb_226.jpg)
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.
Tools and Materials
![cmVqdJBxSDagspdaYiRaog_thumb_221.jpg](/proxy/?url=https://content.instructables.com/FEN/XBXV/J52Q8ROP/FENXBXVJ52Q8ROP.jpg&filename=cmVqdJBxSDagspdaYiRaog_thumb_221.jpg)
- Arduino 101 or Arduino Uno
- 8 LEDs of different colours
- 8 pieces of 100Ω resistors
- Shift Register - SN74HC595
- Jumper Wires
Circuitry
![Screen Shot 2017-07-14 at 10.52.39 PM.png](/proxy/?url=https://content.instructables.com/FV2/0N6E/J52Q7HUS/FV20N6EJ52Q7HUS.png&filename=Screen Shot 2017-07-14 at 10.52.39 PM.png)
![Screen Shot 2017-07-15 at 4.25.58 PM.png](/proxy/?url=https://content.instructables.com/FEP/P8VO/J52Q8YGY/FEPP8VOJ52Q8YGY.png&filename=Screen Shot 2017-07-15 at 4.25.58 PM.png)
![B%+kUMDxT1q7mswyvhDYCA_thumb_227.jpg](/proxy/?url=https://content.instructables.com/FOA/9BVS/J52Q8RQP/FOA9BVSJ52Q8RQP.jpg&filename=B%+kUMDxT1q7mswyvhDYCA_thumb_227.jpg)
![ZwT4kIVvSeScqXXrSKVDcw_thumb_224.jpg](/proxy/?url=https://content.instructables.com/FTG/I2XZ/J52Q8ROR/FTGI2XZJ52Q8ROR.jpg&filename=ZwT4kIVvSeScqXXrSKVDcw_thumb_224.jpg)
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.
Code
![Screen Shot 2017-07-15 at 3.59.27 PM.png](/proxy/?url=https://content.instructables.com/FOH/PG6X/J52Q8UNW/FOHPG6XJ52Q8UNW.png&filename=Screen Shot 2017-07-15 at 3.59.27 PM.png)
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); } }
Demo
![Waterfall LEDs with Shift Register and Arduino 101](/proxy/?url=https://content.instructables.com/F9K/2QZD/J52Q7HCQ/F9K2QZDJ52Q7HCQ.jpg&filename=Waterfall LEDs with Shift Register and Arduino 101)
The LED's will turn ON, then OFF, in sequence from the top to the bottom like a waterfall.