Projects / 3×3×3 LED cube

3×3×3 LED cube

Beginner3 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. UNO13.2 mA

    Test one LED

    Check polarity with a resistor and the 5 V pin before soldering.

  2. UNO13.3 mA

    Make a jig

    Drill a 3×3 grid in card, 2.5 cm apart, and hold the LEDs in it.

  3. UNO

    Solder a layer

    Bend the cathode legs flat and join the nine cathodes into one square.

  4. UNO13.3 mA

    Make three layers

    Test each layer's LEDs again before stacking.

  5. UNO

    Join the columns

    Stack the layers and join each column's anodes with the vertical legs.

  6. UNOBC547

    Wire the base

    Fit nine resistors on the columns and one transistor per layer.

  7. UNO

    Upload the sketch

    Watch the three animations.

In short

How do you build a 3×3×3 LED cube?

Twenty-seven LEDs soldered into a cube light up in 3D animations, multiplexed by layer. You need Arduino Uno R3, LED 5 mm blue × 27, Resistor 220 Ω × 9, BC547 NPN transistor × 3, Resistor 1 kΩ × 3 and Perfboard (dot PCB) 7 × 9 cm. It takes 7 steps and about 180 minutes.

Level
Beginner
Time
About 180 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Column 1 to 9 (anodes of the three LEDs stacked in each column)Arduino D2 to D10 through a 220 Ω resistor eachNine column drives
Layer 1 common cathodeBC547 collector, emitter to GNDBottom layer switch
Layer 2 common cathodeBC547 collector, emitter to GNDMiddle layer switch
Layer 3 common cathodeBC547 collector, emitter to GNDTop layer switch
BC547 basesA0, A1, A2 through a 1 kΩ resistor eachLayer select
Arduino GNDAll BC547 emittersCommon ground
USBArduinoPower

Code

Columns are wired in a 3×3 grid, so column 1 is a corner and column 5 is the centre. Each LED is on for one third of the time, so with a 220 Ω resistor the pulses look bright enough while the current stays small: a layer has up to nine LEDs lit at about 8 mA each, which the BC547 handles. Never switch two layers on together. If the cube looks dim, shorten nothing: lower the delay only a little, as flicker appears below about 1 ms per layer. Arduino IDE, board "Arduino Uno".

Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

// 3x3x3 LED cube: nine column pins, three layer transistors. Board: Arduino Uno.
const byte COL[9] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
const byte LAY[3] = {A0, A1, A2};
byte cube[3][9];                       // cube[layer][column] is 1 when the LED is on

void clearCube() { for (byte l = 0; l < 3; l++) for (byte c = 0; c < 9; c++) cube[l][c] = 0; }

// Show the current frame for the given time by scanning one layer at a time.
void show(unsigned long ms) {
  unsigned long t = millis();
  while (millis() - t < ms) {
    for (byte l = 0; l < 3; l++) {
      for (byte c = 0; c < 9; c++) digitalWrite(COL[c], cube[l][c]);
      digitalWrite(LAY[l], HIGH);      // transistor on, this layer's cathodes go to ground
      delayMicroseconds(1500);
      digitalWrite(LAY[l], LOW);       // off before changing the columns, to avoid ghosting
    }
  }
}

void setup() {
  for (byte c = 0; c < 9; c++) pinMode(COL[c], OUTPUT);
  for (byte l = 0; l < 3; l++) pinMode(LAY[l], OUTPUT);
  randomSeed(analogRead(A5));
}

void rain() {                          // random drops fall from the top layer to the bottom
  for (byte n = 0; n < 12; n++) {
    byte c = random(9);
    for (int l = 2; l >= 0; l--) { clearCube(); cube[l][c] = 1; show(90); }
  }
}

void layerSweep() {
  for (byte r = 0; r < 3; r++) for (byte l = 0; l < 3; l++) {
    clearCube(); for (byte c = 0; c < 9; c++) cube[l][c] = 1; show(180);
  }
}

void spin() {                          // a bar turns around the middle column
  const byte ring[8] = {0, 1, 2, 5, 8, 7, 6, 3};
  for (byte r = 0; r < 3; r++) for (byte i = 0; i < 8; i++) {
    clearCube();
    for (byte l = 0; l < 3; l++) { cube[l][ring[i]] = 1; cube[l][4] = 1; cube[l][ring[(i + 4) % 8]] = 1; }
    show(90);
  }
}

void loop() { rain(); layerSweep(); spin(); }

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
One layer onAll nine LEDs of that layer light evenly
RainSingle drops fall top to bottom
SweepA full layer moves up in turn
No LED stays on when the program stopsRemove power and check

If it does not work

A whole layer stays dark

Check its transistor, base resistor and cathode joint.

A column never lights

Look for a cold joint on its anode legs.

Two layers show the same picture

Check no cathode square touches another layer.

Brightness varies

Check the LEDs are the same colour and batch.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the 3×3×3 LED cube?

Arduino Uno R3, LED 5 mm blue × 27, Resistor 220 Ω × 9, BC547 NPN transistor × 3, Resistor 1 kΩ × 3 and Perfboard (dot PCB) 7 × 9 cm.

How long does the 3×3×3 LED cube take to build?

About 180 minutes for a beginner maker, in 7 steps.

How do I know the 3×3×3 LED cube works?

One layer on: All nine LEDs of that layer light evenly. Rain: Single drops fall top to bottom. Sweep: A full layer moves up in turn.

A whole layer stays dark: what should I check?

Check its transistor, base resistor and cathode joint.

A column never lights: what should I check?

Look for a cold joint on its anode legs.

Two layers show the same picture: what should I check?

Check no cathode square touches another layer.

Brightness varies: what should I check?

Check the LEDs are the same colour and batch.