Step 70: Run the cube on an Arduino

Since we published our last LED Cube instructable, we have gotten a lot of questions from people wondering if they could use an Arduino to control the cube.

This time, we are one step ahead of you on the "Can i use an arduino?" front :D

The IO requirements for an 8x8x8 LED cube is:

  • Layer select: 8
  • Data bus for latches: 8
  • Address bus for latches: 3
  • Output enable (OE) for latches: 1

Total: 21

The Arduino has 13 GPIO pins and 8 analog inputs, which can also be used as GPIO. This gives you a total of 21 IO lines, exactly the amount of IO needed to run the LED cube!

But why write about it when we could just show you?

We hooked the cube up to an Arduino and ported some of the software.

Since the multiplexer array and AVR board are separated by a ribbon cable, connecting the IO lines to an Arduino is a simple matter of connecting some breadboard wires. Luckily, we soldered in a female 0.1" pin header for the transistor lines when we were debugging the first set of transistors. Just remove the ATmega and connect wires from the Arduino to these pin headers.

We connected the cube like this: DATA bus: Digital pins 0-7. This corresponds to PORTD on the ATmega328 on the Arduino board, so we can use direct port access instead of Arduinos digitalWrite (which is slow). Address bus: Digital pins 8-10. This corresponds to PORTB bit 0-2. On this we HAVE to use direct port access. Arduinos digitalWrite wouldn't work with this, because you can't set multiple pins simultaneously. If the address pins are not set at the exact same time, the output of the 74HC138 would trigger the wrong latches. Output Enable: Digital pin 11. Layer transistors: Analog pins 0-5 and digital pins 12 and 13.

We had to go a bit outside the scope of the Arduino platform. The intention of Arduino is to use digitalWrite() for IO port access, to make the code portable and some other reasons. We had to sidestep that and access the ports directly. In addition to that, we had to use one of the timers for the interrupt routine.

The registers for the interrupt and timers are different on different AVR models, so the code may not be portable between different versions of the Arduino board.

The code for our quick Arduino hack is attached.

Remove these adsRemove these ads by Signing Up
1-40 of 66Next »


wcjcs1 year ago
This is the sine wave ripple effect all in one easy function that you can copy into your Arduino sketch and then call in your main loop. Note that this effect will run on an Arduino Uno, however, with the sheer number of complicated mathematical calculations involved, the Arduino chokes on it. I'm guessing here, but that seems logical. Anyway, I've stripped everything out, removing extra function calls, avoiding assigning temp vars, and even doing some math (as much as possible) ahead of time. In spite of this, the animation still lags. All the same, now you have something you can hack at. If you improve the performance, please post the code back. Also note that it takes 300+ iterations to create a full cycle of the animation, so give it a much larger number to keep the animation running longer. The delay argument isn't useful as written; even when it is set to 0, the animation still lags. You can port the other animations in the same way. Good luck.

Sine wave animation for 8x8x8 LED cube running Arduino Uno
John Alarcon, 2013.
void ripples (int iterations, int delay)
// Remember, it takes 300+ for just a couple seconds of animation...
for (int i=0; i // Iterate through x and y.
for (int x=0; x<8; x++) {
for (int y=0; y<8; y++) {
// Light LED at x,y at the correct height.
setvoxel(x, y, (int)((4+sin(sqrt((3.5-x)*(3.5-x)+(3.5-y)*(3.5-y)) / 1.3 + (float)i/50) * 4)));
// This would normally be used to slow the animation but, well, the animation
// can't really get any slower than it already is, so, yea.
// Clear the cube to ready it for the next iteration.
Loskeem wcjcs4 months ago

for (int i=0; i // Iterate through x and y. should read:

for (int i=0; i < iterations; i++)

Otherwise works well. ;-)

chobostyle2 years ago
Has someone got the Source Code or the needed adjustments for use with Arduino MEGA 2560 (r3) ?
goroth chobostyle9 months ago

Did you ever get the MEGA 2560 R3 to work? My UNO works fine but the source code does not work for the MEGA 2560 R3.

Loskeem goroth4 months ago

Hey Instructables gang,

I have created the code that allows the cube to run on the Arduino MEGA 2560. It's a simple fix and easy to follow. See below. Just change the code originally given by CHR to my code and the cube works great. Only includes 5 effects but you can add your own. Cheers!

// Rewrite of CHR's 8X8X8 LED Cube written for Arduino UNO. This sketch works for the MEGA 2560.

// This sketch cleans up issues with pin assignment differences between UNO and 2560.

// Wire the cube using the folowing parameters:


// Original sketch uses PORT C for layer select. I do too but use pins 37 (bit 0) thru 30 (bit 7).

// Original sketch uses PORT D for DATA. I use PORT A pins 22 (bit 0) thru 29 (bit 7).

// Limitations on available pins caused software to be written that is unnecessary on the MEGA.

// Use PORT L for Chip Select and Chip Enable (clock) pins;

// Digital pins 49, 48, and 47 (LSB to MSB) for the Chip Select, Digital pin 46 for the clock pin

#include <avr/interrupt.h>

#include <string.h>

#define AXIS_X 1

#define AXIS_Y 2

#define AXIS_Z 3

volatile unsigned char cube[8][8];

volatile int current_layer = 0;

void setup()


int i;

for(i=0; i<14; i++)

pinMode(i, OUTPUT);

// pinMode(A0, OUTPUT) as specified in the arduino reference didn't work. So I accessed the registers directly.

DDRC = 0xff;

DDRA = 0xff;

DDRL = 0x0f;

PORTC = 0x00;

PORTA = 0x00;

// Reset any PWM configuration that the arduino may have set up automagically!

TCCR2A = 0x00;

TCCR2B = 0x00;

TCCR2A |= (0x01 << WGM21); // CTC mode. clear counter on TCNT2 == OCR2A

OCR2A = 10; // Interrupt every 25600th cpu cycle (256*100)

TCNT2 = 0x00; // start counting at 0

TCCR2B |= (0x01 << CS22) | (0x01 << CS21); // Start the clock with a 256 prescaler

TIMSK2 |= (0x01 << OCIE2A);




int i;

// all layer selects off

PORTC = 0x00;

PORTA = 0x00;

PORTL &= 0x0f;

PORTL |= 0x08; // output enable off.

for (i=0; i<8; i++)


PORTA = cube[current_layer][i];

PORTL = (PORTL & 0xF8) | (0x07 & (i+1));


PORTL &= 0b00110111; // Output enable on.

PORTC = (0x01 << current_layer);


if (current_layer == 8)

current_layer = 0;


johnatalopes5 months ago

ola alguém pode mim ajudar com a pinagem para ligação do Arduíno uno, pois ja montei todo o cubo e nao sei como ligar no arduino.

abuchard1 year ago
j' ai construit le cube , je le pilote avec arduino uno
le problème est que j' ai " ROW1, ROW2, ROW3" qui reste allumé donc j' ai 192 leds
qui ne s' animes pas
pourriez vous me donner quelques conseils
As-tu trouvé la solution ?
abuchard meindi7 months ago

oui j' ai trouvé la solution , c' été un probléme de masse

Blade122888 made it!8 months ago

OMG lots of soldering!!! So glad I got mine finished! Great Instructable!

Ian989 months ago

Hi, I connected my cube to an Arduino Uno R3. Everything seems to have power but no LEDs are turing on. Any idea what the problem may be?


I just finished putting all the parts together and hooked up the cube to an atmega328 and something seems to be off. when I upload the sketch all the led's light up and they stay lit and nothing else happens. did anyone else stumble upon this problem?

Make sure your 74hc138 has power.

captainjack3h11 months ago
We're making a 6x6x6 version of this. Would 3 sx1509 chips work to drive this?
Nobody seemed to pick up on this, but 8+8+3+1 = 20 lines, not 21 - which is a good thing because the arduino actually only has the 20 lines. A0 to A5 = 6 lines, and D0 to D13 = 14 lines...and 14 + 6 = 20. This hit me as I was getting ready to hook up the Arduino to my driver board, and wiring the driver board to the I/O connector. It's all good though and since the hookup instructions all work, it's not even a big deal. I just thought I'd point it out in case anyone else was scratching their heads.
Maybe they included the 5V or the GND as the 21st line...
Hi, it it possible to get from somewhere the eagle schematic file - .sch for the controller board (not the one with the MCU), so it will be easier to design a PCB for it. It will be much easier to solder. Thanks
rrussis821 year ago
how could I integrate an MSGEQ7 chip into this to make the cube respond to music?
I may have missed it, but what is the wire mapping for this ?
OOPS - it's right here:

Thanks Maewert
chewdog3161 year ago
Has anyone built or knows where to buy cables to replace the jumpers?
I have to wonder how well a VIC-20 or Commodore 64 might be able to do something like this. Since the keyboard input can be redefined as output, and there's another 8 lines on the user port, we could do without the 74138 because we'd have 8 lines X 8 lines X 8 lines. If it was done in machine code, we might be able to pull it off, I may try it since I still have a VIC-20.
Andre8881 year ago
tarPancake3 years ago
does anyone have the ripples, fireworks, or the sidewaves functions ported to pde yet? thanks in advance.
I posted a comment at the top of the thread. There is a function you can copy into your sketch. If achieves the effect, but its laggy due to all the math. Good luck.
rex191 year ago
Will this work on a arduino with atmega328? help me pls.
zstryker1 year ago
Will this work on a Raspberry Pi?
Hi, I'm new to Instructables, but the arduinocube.pde download link seems to be broken. Can anyone advise if it is or whether it's just me? It looks like it's referring to a .tmp file rather than the correct file?
Akardo15022 years ago
Can you take the programmed microcontroller on arduino (ATmega328) and place it where the ATmega32 was?? Would it still work??
patyork2 years ago
Just a thought: You're using 8 lines to select the correct layer; could a 3x8 decoder not accomplish the same thing? Still waiting on parts, but this is how I have mine designed at the moment.
arighi12 years ago
hey guys, hope y r doing well I have this problem, I have a arduino softwar mega and I changed port L by the port D and I sent it to arduino uno it function normaly but there is a lign it has to be One led light, but the hall cube light, and am sure the problem is in the program Please help am waiting ^_^
victinho2 years ago
preciso se possivel dos ajustes para o codigo usando o arduino mega 2560 alguem pode me dar um forcinha por gentileza?
froibo2 years ago
So I hooked up the cube to my Arduino with this code and all I got was crazy gibberish.

To try and get a handle on the problem I changed the loop code to alternate the lights as all on to all off every other second using the fill function. Well it worked, only it was inverted. The lights were all on when they should have been off and vise versa.

I am a bit lost as how to interpret this.

The only thing I could think of is that I am using an Uno SMD edition and perhapse the interupt and timers are different from the intentions in the code as the guide mentions. I'm clueless to the deeply technical aspects of Aurdino, so any insight would be greatly appreciated.
Pog492 years ago
Hey Everybody!

Just wondering about power. Is the Arduino capable of running the LED cube without building/buying the external PSU mentioned in an earlier step? I assume not but just wondering if anybody could help me out.

@maewert, thanks for your images (in a comment below), they help alot but I don't see connections running from the PSU and I am assuming it is necessary to simply connect the PSU VCC/GND to the appropriate arrows.

Also, just to be clear - Which circuits actually need to be built if I'm using the Arduino instead of the ATmega32 microcontroller? I would prefer not to buy components that I won't use.

Hope somebody understands my query :/
shredape2 years ago
It's alive! After many hours of tinkering and building I finally got the lattice to light up, with spectacular results. I am using an Arduino UNO as the programmer and power source to my cuber, but I'm not able to really understand the code even though it works out great. My question is, can anyone post a tutorial on how to program this cube? I'm very interested in creating my own animations but I do not know how, because I'm a novice when it comes to coding. Will anyone help me with this last step of the best lighting project?!
lhwong2 years ago
I'll add my thanks for this great project!

Question: If you use an Arduino, do you still need the serial connection to a PC in order to do the fancy animations?
TangoDelta2 years ago
In the last weeks I spent a couple of hours here and there on this project, and tonight I reached the stage where I could hook it op to my Arduino Uno, and it works a charm! I was kinda nervous, I couldn't find the 2n2222's, so I used others, and I had to replace some things here and there, also my wiring's a mess, but it works!

This is a great project, with mesmerizing results.
lscarmic2 years ago
Ok. Here I am again. If someone gets a sec, can you double check my R values? I don't really think that would be causing my problems but I wanted to double check anyways. I'm ok with the LED and pull-up values. It's the Rb values I'm not 100% on.

Again, my problem is that  the entire row 0 plane is always on (that is, the 16 voxels from 0,0,0 to 3,0,3). For a test, I loaded the effect_planboing function just to see what would happen and same thing, the XZ planes along the Y axis for row 1, 2 and 3 work fine, but the row 0 plane just stays full on.

I tested solder joints per triumphtotty's suggestions but didn't find anything alarming.

I'm at a loss. Here's a link to the larger images:

As always, thanks for your help.


by the way, i realize this is a 4x4x4 question on the 8x8x8 instructable. however, since i'm using the same method as the 8x8x8 i thought it was appropriate.
well for anyone watching, i completely replaced the latch for row 0 (the one misbehaving). i actually wired over to a new latch on a breadboard complete with separate Vcc and GND (from the same power supply) and new resistors. unfortunately, still have the same result.

my only thought at this point is to go back to the code (posted in the next step). can anyone think of why there would be a problem running a 4x4x4 cube by simply scaling down the 8x8x8 code?

thanks again.
1-40 of 66Next »