Well my shipment of electronic components arrived today allowing me to have a good restock of things I had ran out of or needed to replace, that and get a bigger breadboard as the one that came with my arduino takes the piss. It is small as fuck and I managed to burn holes in it from the numerous short circuits I accidently created while testing things :facepalm:. Anyway I got a few Shift Registers, and for those who own an arduino know the board only has 13 digital outputs which is great until you need more outputs. This is where the shift register comes in, it uses only three outputs and provides eight outputs or if you stack another shift register on top provides sixteen outputs. There is no real limit on how many you can stack on top so you can run LED cubes off of an arduino with ease.
Below you will see the first circuit based on a 74HC595N shift register. It controls eight green LEDs which sweep back and forth in sequence. This would normally require eight outputs from the arduino but with the 74HC595N, only requires three. Digital pin two provides data to the shift register, pin three provides the latching signal and pin four provides the clock signal. There is also ground and +5v lines to power the device and associated LEDs. The dimple in one end of the device denotes the end with pins 1 and 16, 1 being on the left as per the diagram below.
The code that runs the circuit is below
int dataPin = 2; //Define which pins will be used for the Shift Register control
int latchPin = 3;
int clockPin = 4;
int seq[14] = {1,2,4,8,16,32,64,128,64,32,16,8,4,2}; //The byte sequence
void setup()
{
pinMode(dataPin, OUTPUT); //Configure each IO Pin
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop()
{
for (int n = 0; n < 14; n++)
{
digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data
shiftOut(dataPin, clockPin, MSBFIRST, seq[n]); //Send the data
digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data
delay(75);
}
}
So your circuit works as expected and you now have eight LEDs sweeping in sequence in front of you. Now we are going to add a second shift register. Connecting the second device is the same as the first. There is a pin called Overflow on the 74HC595N which will be joined to the data pin on the second device. This carries over the data sent to the first device and if the first bit of code you tried is running, you will see it replicated on the second device. Your power, latching and clock lines you just join between each device as shown below.
After connecting everything correctly and ignoring the LEDs on the data, overflow and clock lines (they aren't needed), upload the next bit of code below
int dataPin = 2; //Define which pins will be used for the Shift Register control
int latchPin = 3;
int clockPin = 4;
int seq1[14] = {1,2,4,8,16,32,64,128,64,32,16,8,4,2}; //The array for storing the
// byte #1 value
int seq2[14] = {128,64,32,16,8,4,2,1,2,4,8,16,32,64}; //The array for storing the
// byte #2 value
void setup()
{
pinMode(dataPin, OUTPUT); //Configure each IO Pin
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop()
{
for (int x = 0; x < 14; x++) //Array Index
{
digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data
shiftOut(dataPin, clockPin, MSBFIRST, seq1[x]); //Send the data byte 1
shiftOut(dataPin, clockPin, MSBFIRST, seq2[x]); //Send the data byte 2
digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data
delay(75);
}
}
You should have two sets of sweeping LEDs sweeping in opposite directions if everything is done correctly.
Again there is no real limit on how many can be stacked together but after a while, powering a large amount may become a problem. Just remember to use series resistors with your LEDs as they don't like a lot of current. I used a single 390 ohm resistor on the ground bus feeding the LEDs as i'm a lazy cunt although as only one or two are illuminated at once, it doesn't make too much difference IMO.
Comments
So if you want to build one you will need...
Firstly make your soldering jig. Drill 9 holes around 2 cm apart in a 3*3 grid. Now take your LEDs and insert them leads up into the holes. This will hold them in place so you can solder them easily. Start at the top left, bend the cathode pin (short one) across to the next cathode pin. Do this to each LED so all the cathodes are joined together like below.
Repeat as above two more times until you have three 3*3 grids of LEDs. Now solder the anode pins together so you end up with nine leads at the bottom of your cube. Now insert your finished cube into your breadboard. Connect a lead into the bus on your breadboard that each cube lead inserts into. Take three bits of wire and solder each wire to each cathode row (three in total). Connect from top to bottom, each wire to Analogue pins 3,4,5 respectively. Take the anode leads and connect them to the Arduino as shown below.
Now connect your Arduino board to your PC and upload the following code. Due to its size, the Arduino will take a couple of seconds to begin running the cube after power on.
If you have correctly soldered everything and correctly connected the board to the Arduino, you should be greeted by a cool flashing LED cube.